mirror of
https://github.com/twentyhq/twenty
synced 2026-04-21 21:47:38 +00:00
Context : - Phones import is a bit complex if not all subfields are provided. - Phones subfield validation are absent or different from BE validation. Solution : - Normalize callingCode and countryCode validation (BE/FE) - Ease phone import if only phoneNumber is provided
15 lines
467 B
TypeScript
15 lines
467 B
TypeScript
import { getCountries, getCountryCallingCode } from 'libphonenumber-js';
|
|
|
|
const ALL_COUNTRIES_CODE = getCountries();
|
|
|
|
export const getCountryCodesForCallingCode = (callingCode: string) => {
|
|
const cleanCallingCode = callingCode.startsWith('+')
|
|
? callingCode.slice(1)
|
|
: callingCode;
|
|
|
|
return ALL_COUNTRIES_CODE.filter((country) => {
|
|
const countryCallingCode = getCountryCallingCode(country);
|
|
|
|
return countryCallingCode === cleanCallingCode;
|
|
});
|
|
};
|