fix(admin): show flag for every country code, not just hardcoded 25-36

User reported the EE (Estonia) flag rendered as plain text 'EE' on the
admin servers page. Root cause: getCountryFlag() in AdminServers.tsx
and AdminServerEdit.tsx hardcoded a 25-entry codeMap that didn't
include EE; falling through to 'return code' produced raw text.

Two other admin pages (AdminRemnawaveSquadDetail, AdminUserDetail)
had bigger 35-entry maps that did include EE — so EE worked there
but MX/AR/EG/ZA and friends still wouldn't. AdminRemnawave repeated
the same 35-entry map. AdminTrafficUsage already had the correct
algorithmic ISO→regional-indicator code but as a local duplicate of
utils/subscriptionHelpers.

Unify all six on the single algorithmic helper:

- getFlagEmoji() in utils/subscriptionHelpers.ts now:
  * accepts string | null | undefined (callers don't need to guard)
  * trims whitespace
  * validates [A-Za-z]{2} before composing regional indicators
- Each admin page now either imports getFlagEmoji directly or wraps
  it with the page's preferred fallback character (e.g. '🌍' for
  empty codes where the UI expects a placeholder).
This commit is contained in:
Fringg
2026-05-16 01:11:00 +03:00
parent abbbc6a216
commit f301d44f24
7 changed files with 27 additions and 202 deletions

View File

@@ -32,9 +32,12 @@ export const getInsufficientBalanceError = (
return null;
};
export const getFlagEmoji = (countryCode: string): string => {
if (!countryCode || countryCode.length !== 2) return '';
const codePoints = countryCode
export const getFlagEmoji = (countryCode: string | null | undefined): string => {
// Trim + длина строго 2 буквы — иначе Unicode regional indicators не дадут флаг.
// Принимаем null/undefined чтобы вызывающие коду не приходилось страховаться.
const code = (countryCode ?? '').trim();
if (code.length !== 2 || !/^[A-Za-z]{2}$/.test(code)) return '';
const codePoints = code
.toUpperCase()
.split('')
.map((char) => 127397 + char.charCodeAt(0));