feat(dashboard): use username instead of email for the generation of the

fallback avatar image
This commit is contained in:
2025-07-28 19:20:05 +02:00
parent 30c2c7afb0
commit f8261b5364
3 changed files with 8 additions and 11 deletions

View File

@@ -268,7 +268,7 @@ export const ProfileForm = () => {
</FormControl>
<Avatar className="default-avatar h-12 w-12 rounded-full border hover:p-px hover:border-primary transition-transform">
<AvatarFallback className="rounded-lg">{getFallbackAvatarInitials(data?.user?.email)}</AvatarFallback>
<AvatarFallback className="rounded-lg">{getFallbackAvatarInitials(data?.user?.name)}</AvatarFallback>
</Avatar>
</FormLabel>
</FormItem>

View File

@@ -47,7 +47,7 @@ export const UserNav = () => {
src={data?.user?.image || ""}
alt={data?.user?.image || ""}
/>
<AvatarFallback className="rounded-lg">{getFallbackAvatarInitials(data?.user?.email)}</AvatarFallback>
<AvatarFallback className="rounded-lg">{getFallbackAvatarInitials(data?.user?.name)}</AvatarFallback>
</Avatar>
<div className="grid flex-1 text-left text-sm leading-tight">
<span className="truncate font-semibold">Account</span>

View File

@@ -28,14 +28,11 @@ export function formatTimestamp(timestamp: string | number) {
}
}
export function getFallbackAvatarInitials(email: string | undefined): string {
if (typeof email === "undefined") return "CN";
const [emailUsername = ""] = email.split('@');
const parts = emailUsername.split(/[\._-]+/).filter(Boolean);
if (parts.length >= 2) {
// @ts-ignore we are sure parts[0] and parts[1] exist
return (parts[0]?.charAt(0) + parts[1].charAt(0)).toUpperCase();
export function getFallbackAvatarInitials(fullName: string | undefined): string {
if (typeof fullName === "undefined" || fullName === "") return "CN";
const [ name = "", surname = "" ] = fullName.split(" ");
if (surname === "") {
return (name.substring(0,2)).toUpperCase();
}
return emailUsername.slice(0, 2).toUpperCase();
return (name.charAt(0) + surname.charAt(0)).toUpperCase();
}