mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-09-16 01:33:09 +00:00
fix(dashboard): приветствие без пустого имени для email-пользователей
This commit is contained in:
@@ -3,21 +3,28 @@
|
||||
*
|
||||
* Why: single-letter first_name (e.g., "О") looked confusing alone ("Добро пожаловать, О!").
|
||||
* Combining with last_name makes truncated/short first names readable.
|
||||
*
|
||||
* Email/OAuth registration does not collect a name, so for such users every
|
||||
* Telegram-derived field is null — fall back to the email local part
|
||||
* ("vasya@gmail.com" → "vasya") to avoid an empty name in greetings.
|
||||
*/
|
||||
export interface NameSource {
|
||||
first_name?: string | null;
|
||||
last_name?: string | null;
|
||||
username?: string | null;
|
||||
telegram_id?: number | null;
|
||||
email?: string | null;
|
||||
}
|
||||
|
||||
export function displayName(user?: NameSource | null): string {
|
||||
if (!user) return '';
|
||||
const fullName = [user.first_name, user.last_name]
|
||||
.filter((part): part is string => Boolean(part && part.trim()))
|
||||
.filter((part): part is string => Boolean(part?.trim()))
|
||||
.join(' ');
|
||||
if (fullName) return fullName;
|
||||
if (user.username) return user.username;
|
||||
if (user.telegram_id) return `#${user.telegram_id}`;
|
||||
const emailLocalPart = user.email?.trim().split('@')[0];
|
||||
if (emailLocalPart) return emailLocalPart;
|
||||
return '';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user