'use client'; import { ComponentPropsWithoutRef, CSSProperties, ElementRef, forwardRef } from 'react'; import { getUserInitials } from '@/lib/utils'; import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'; type UserAvatarProps = Omit, 'children'> & { name?: string | null; email?: string | null; profileImage?: string | null; userId?: number | null; imageSrc?: string; fallbackClassName?: string; fallbackStyle?: CSSProperties; }; const UserAvatar = forwardRef, UserAvatarProps>(function UserAvatar({ name, email, profileImage, userId, imageSrc, className, fallbackClassName, fallbackStyle, ...props }, ref) { const src = imageSrc || (profileImage && !profileImage.startsWith('data:') && userId ? `/api/v1/users/${userId}/avatar?v=${encodeURIComponent(profileImage.split(/[\\/]/).pop() || profileImage)}` : profileImage); return ( {src && ( )} {getUserInitials(name || email) || 'U'} ); }); export default UserAvatar;