mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-22 04:46:40 +00:00
use display name function
This commit is contained in:
36
src/lib/getUserDisplayName.ts
Normal file
36
src/lib/getUserDisplayName.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { GetUserResponse } from "@server/routers/user";
|
||||
|
||||
type UserDisplayNameInput =
|
||||
| {
|
||||
user: GetUserResponse;
|
||||
}
|
||||
| {
|
||||
email?: string | null;
|
||||
name?: string | null;
|
||||
username?: string | null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the display name for a user.
|
||||
* Priority: email > name > username
|
||||
*
|
||||
* @param input - Either a user object or individual email, name, username properties
|
||||
* @returns The display name string
|
||||
*/
|
||||
export function getUserDisplayName(input: UserDisplayNameInput): string {
|
||||
let email: string | null | undefined;
|
||||
let name: string | null | undefined;
|
||||
let username: string | null | undefined;
|
||||
|
||||
if ("user" in input) {
|
||||
email = input.user.email;
|
||||
name = input.user.name;
|
||||
username = input.user.username;
|
||||
} else {
|
||||
email = input.email;
|
||||
name = input.name;
|
||||
username = input.username;
|
||||
}
|
||||
|
||||
return email || name || username || "";
|
||||
}
|
||||
Reference in New Issue
Block a user