feat: enhance UserAvatar component to accept FacehashProps and add WhatsApp link in UsersTable context menu

This commit is contained in:
Marco Pedone 2026-03-10 15:05:36 +01:00
parent 0759f4216f
commit 4e447cade4
3 changed files with 40 additions and 13 deletions

View file

@ -7,7 +7,7 @@ import { FACES } from "./faces";
type Intensity3D = "none" | "subtle" | "medium" | "dramatic"; type Intensity3D = "none" | "subtle" | "medium" | "dramatic";
type Variant = "gradient" | "solid"; type Variant = "gradient" | "solid";
interface FacehashProps export interface FacehashProps
extends Omit<React.HTMLAttributes<HTMLDivElement>, "children"> { extends Omit<React.HTMLAttributes<HTMLDivElement>, "children"> {
/** /**
* String to generate a deterministic face from. * String to generate a deterministic face from.

View file

@ -22,9 +22,11 @@ import { UserAvatar } from "~/components/user_avatar";
import { cn } from "~/lib/utils"; import { cn } from "~/lib/utils";
import type { Users } from "~/schemas/public/Users"; import type { Users } from "~/schemas/public/Users";
import { api } from "~/utils/api"; import { api } from "~/utils/api";
import { WhatsAppIcon2 } from "../svgs";
import { import {
ContextMenuContent, ContextMenuContent,
ContextMenuItem, ContextMenuItem,
ContextMenuLabel,
ContextMenuSeparator, ContextMenuSeparator,
} from "../ui/context-menu"; } from "../ui/context-menu";
@ -209,6 +211,15 @@ export const UsersTable = (props: { data: UserWChatInfo[] }) => {
columns_titles={columns_titles} columns_titles={columns_titles}
contextMenuContent={(data) => ( contextMenuContent={(data) => (
<ContextMenuContent> <ContextMenuContent>
<ContextMenuLabel className="flex h-8 items-center gap-2">
<UserAvatar
className="size-5"
style={{ height: "1.25rem", width: "1.25rem" }}
userId={data.id}
username={data.username}
/>
<span className="font-semibold text-sm">{data.username}</span>
</ContextMenuLabel>
<ContextMenuItem> <ContextMenuItem>
<Link <Link
aria-label="Visualizza Ricerca" aria-label="Visualizza Ricerca"
@ -275,6 +286,16 @@ export const UsersTable = (props: { data: UserWChatInfo[] }) => {
<MessagesSquare /> Chat <MessagesSquare /> Chat
</Link> </Link>
</ContextMenuItem> </ContextMenuItem>
<ContextMenuItem>
<Link
className="flex w-full items-center gap-2"
href={`https://wa.me/${data.telefono}`}
target="_blank"
>
<WhatsAppIcon2 className="size-4 fill-muted-foreground stroke-0" />
WhatsApp
</Link>
</ContextMenuItem>
<ContextMenuSeparator /> <ContextMenuSeparator />
<ContextMenuItem> <ContextMenuItem>
<button <button
@ -290,7 +311,6 @@ export const UsersTable = (props: { data: UserWChatInfo[] }) => {
)} )}
data={tabledata} data={tabledata}
defaultColumnVisibility={{ defaultColumnVisibility={{
actions: true,
created_at: true, created_at: true,
email: true, email: true,
telefono: true, telefono: true,

View file

@ -1,6 +1,6 @@
import { cn, getHexColorFromString, getInitials } from "~/lib/utils"; import { cn, getHexColorFromString, getInitials } from "~/lib/utils";
import type { UsersId } from "~/schemas/public/Users"; import type { UsersId } from "~/schemas/public/Users";
import { Facehash } from "./facehash/facehash"; import { Facehash, type FacehashProps } from "./facehash/facehash";
const colorOptions = new Map<string, string>(); const colorOptions = new Map<string, string>();
@ -39,19 +39,26 @@ export const UserAvatarOld = ({
); );
}; };
*/ */
export const UserAvatar = ({ export const UserAvatar = (
userId, props: {
username, userId: UsersId;
className, username?: string;
}: { } & Omit<
userId: UsersId; FacehashProps,
username?: string; | "name"
className?: string; | "colors"
}) => { | "initialsCount"
| "intensity3d"
| "variant"
| "showInitial"
>,
) => {
const { userId, username, ...rest } = props;
const value = `${username && getInitials(username)}${userId}`; const value = `${username && getInitials(username)}${userId}`;
return ( return (
<Facehash <Facehash
className={cn("size-20 rounded-full", className)} {...rest}
className={cn("size-20 rounded-full", rest.className)}
colors={[ colors={[
"#2D3436", "#2D3436",
"#535C68", "#535C68",