43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import { type FC } from 'react'
|
|
import { usePresignedUrl } from '@/pages/uploader/hooks/usePresignedUrl'
|
|
import { clx } from '@/helpers/utils'
|
|
|
|
type Props = {
|
|
src?: string | null
|
|
firstName?: string | null
|
|
lastName?: string | null
|
|
className?: string
|
|
textClassName?: string
|
|
}
|
|
|
|
const UserAvatar: FC<Props> = ({
|
|
src,
|
|
firstName,
|
|
lastName,
|
|
className = 'size-10',
|
|
textClassName = 'text-xs',
|
|
}) => {
|
|
const resolvedSrc = usePresignedUrl(src ?? undefined)
|
|
const initials =
|
|
`${String(firstName ?? '').charAt(0)}${String(lastName ?? '').charAt(0)}`.trim() ||
|
|
'?'
|
|
|
|
return (
|
|
<div
|
|
className={clx(
|
|
'shrink-0 rounded-full bg-description overflow-hidden flex items-center justify-center text-white font-medium',
|
|
className,
|
|
textClassName,
|
|
)}
|
|
>
|
|
{resolvedSrc ? (
|
|
<img src={resolvedSrc} className="size-full object-cover" alt="" />
|
|
) : (
|
|
initials
|
|
)}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default UserAvatar
|