feat: add avatar and nickname display in user info scope

This commit is contained in:
moonrailgun 2024-08-03 03:41:41 +08:00
parent 20e95ef973
commit 03bc9b5125
2 changed files with 11 additions and 7 deletions

View File

@ -1,4 +1,4 @@
import { Avatar, AvatarFallback } from '@/components/ui/avatar'; import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
import { Button } from '@/components/ui/button'; import { Button } from '@/components/ui/button';
import { import {
DropdownMenu, DropdownMenu,
@ -53,17 +53,18 @@ export const UserConfig: React.FC<UserConfigProps> = React.memo((props) => {
}); });
}); });
const nickname = userInfo?.nickname ?? userInfo?.username ?? '';
const avatar = ( const avatar = (
<Avatar size={props.isCollapsed ? 'sm' : 'default'}> <Avatar size={props.isCollapsed ? 'sm' : 'default'}>
<AvatarFallback> <AvatarImage src={userInfo?.avatar ?? undefined} />
{(userInfo?.username ?? '').substring(0, 2).toUpperCase()} <AvatarFallback>{nickname.substring(0, 2).toUpperCase()}</AvatarFallback>
</AvatarFallback>
</Avatar> </Avatar>
); );
const name = ( const name = (
<div className="flex-1 overflow-hidden text-ellipsis"> <div className="flex-1 overflow-hidden text-ellipsis" title={nickname}>
{userInfo?.username ?? ''} {nickname}
</div> </div>
); );

View File

@ -22,9 +22,12 @@ export const workspaceSchema = z.object({
}); });
export const userInfoSchema = z.object({ export const userInfoSchema = z.object({
username: z.string(),
id: z.string(), id: z.string(),
role: z.string(), role: z.string(),
username: z.string(),
nickname: z.string().nullable(),
avatar: z.string().nullable(),
email: z.string().nullable(),
createdAt: z.date(), createdAt: z.date(),
updatedAt: z.date(), updatedAt: z.date(),
deletedAt: z.date().nullable(), deletedAt: z.date().nullable(),