29 lines
863 B
TypeScript
29 lines
863 B
TypeScript
import type { AuthUser } from "@/types/auth";
|
|
|
|
/** Prefer Meshkee English name fields; fall back to cell. */
|
|
export function getDisplayName(user: AuthUser | null | undefined): string {
|
|
if (!user) return "Admin";
|
|
|
|
const english = [user.firstNameEn, user.lastNameEn]
|
|
.filter(Boolean)
|
|
.join(" ")
|
|
.trim();
|
|
if (english) return english;
|
|
|
|
const local = [user.firstName, user.lastName].filter(Boolean).join(" ").trim();
|
|
if (local && !/[\u0600-\u06FF]/.test(local)) return local;
|
|
|
|
return user.cellNumber || "User";
|
|
}
|
|
|
|
export function getFirstName(user: AuthUser | null | undefined): string {
|
|
if (!user) return "there";
|
|
const raw =
|
|
user.firstNameEn?.trim() ||
|
|
(user.firstName?.trim() && !/[\u0600-\u06FF]/.test(user.firstName)
|
|
? user.firstName.trim()
|
|
: "");
|
|
if (!raw) return "there";
|
|
return raw.split(/\s+/)[0] || raw;
|
|
}
|