Enhance CountryFlag to accept country names and codes
All checks were successful
Build And Push Image / docker (push) Successful in 3m20s

- Add actualCountryCode computed property to handle both 2-letter codes and country names
- Extend parseCountryInput with common country name variations (USA, UK, etc.)
- Import parseCountryInput utility in CountryFlag component
- Update template to use actualCountryCode instead of direct countryCode prop
This commit is contained in:
2025-08-07 21:30:47 +02:00
parent b043648db6
commit f096a22824
2 changed files with 43 additions and 7 deletions

View File

@@ -321,8 +321,30 @@ export const parseCountryInput = (input: string): string | null => {
return trimmed.toUpperCase();
}
// Handle common variations and abbreviations
const commonVariations: Record<string, string> = {
'usa': 'US',
'uk': 'GB',
'england': 'GB',
'britain': 'GB',
'great britain': 'GB',
'america': 'US',
'united states of america': 'US',
'south korea': 'KR',
'north korea': 'KP',
'czech republic': 'CZ',
'czechia': 'CZ',
'russia': 'RU',
'russian federation': 'RU',
};
const lowerInput = trimmed.toLowerCase();
if (commonVariations[lowerInput]) {
return commonVariations[lowerInput];
}
// Search by name
const found = countriesByName.get(trimmed.toLowerCase());
const found = countriesByName.get(lowerInput);
return found ? found.code : null;
};