d9a945904a
- Added `libphonenumber-js` dependency for improved phone number handling. - Refactored `CreateAdmin` form to utilize a new `PhoneNumberInput` component with validation rules. - Updated `useCreateAdminPresenter` to normalize phone number input before submission. - Enhanced error messages for phone validation in `Texts` constant. - Modified `User` schema to validate phone numbers using E.164 format.
23 lines
749 B
TypeScript
23 lines
749 B
TypeScript
import { getCountryLabel } from "@/lib/phone/e164";
|
|
import { getCountries, getCountryCallingCode } from "libphonenumber-js";
|
|
import type { CountryCode } from "libphonenumber-js";
|
|
import type { ILabelValue } from "@/types/shared";
|
|
|
|
export type PhoneCountryOption = ILabelValue<CountryCode> & {
|
|
callingCode: string;
|
|
};
|
|
|
|
export const PHONE_COUNTRIES: PhoneCountryOption[] = getCountries()
|
|
.map((code) => {
|
|
const callingCode = getCountryCallingCode(code);
|
|
const name = getCountryLabel(code);
|
|
return {
|
|
value: code,
|
|
label: `${name} (+${callingCode})`,
|
|
callingCode,
|
|
};
|
|
})
|
|
.sort((a, b) => a.label.localeCompare(b.label, undefined, { sensitivity: "base" }));
|
|
|
|
export const DEFAULT_PHONE_COUNTRY: CountryCode = "US";
|