refactor(admin): replace inline avatar logic with shared UserAvatar component

This commit is contained in:
2026-04-22 15:14:07 -04:00
parent 92265f450e
commit 18270540cc
4 changed files with 52 additions and 46 deletions
+39
View File
@@ -0,0 +1,39 @@
'use client';
const getImageUrl = (imageKey) => {
if (!imageKey) return null;
return `/zen/api/storage/${imageKey}`;
};
const getUserInitials = (name) => {
if (!name) return 'U';
return name.split(' ').map(n => n[0]).join('').toUpperCase().slice(0, 2);
};
const sizeMap = {
sm: { wrapper: 'w-[26px] h-[26px]', text: 'text-[10px]' },
md: { wrapper: 'w-8 h-8', text: 'text-[11px]' },
};
const UserAvatar = ({ user, size = 'md' }) => {
const imageUrl = getImageUrl(user?.image);
const initials = getUserInitials(user?.name);
const { wrapper, text } = sizeMap[size] ?? sizeMap.md;
if (imageUrl) {
return (
<img
src={imageUrl}
alt={user?.name || 'User'}
className={`${wrapper} rounded-full object-cover shrink-0`}
/>
);
}
return (
<div className={`${wrapper} rounded-full bg-black dark:bg-white flex items-center justify-center shrink-0`}>
<span className={`${text} font-medium text-white dark:text-black`}>{initials}</span>
</div>
);
};
export default UserAvatar;
+1
View File
@@ -26,3 +26,4 @@ export { default as FilterTabs } from './FilterTabs';
export { default as Breadcrumb } from './Breadcrumb';
export { default as Switch } from './Switch';
export { default as TagInput } from './TagInput';
export { default as UserAvatar } from './UserAvatar';