feat(phone-input): integrate phone number input component and validation
- 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.
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
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";
|
||||
Reference in New Issue
Block a user