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:
@@ -1,3 +1,4 @@
|
||||
import { isValidE164Phone } from "@/lib/phone/e164";
|
||||
import { z } from "zod";
|
||||
import { createApiResponseSchema } from "./Factory";
|
||||
|
||||
@@ -25,7 +26,13 @@ export const UserSchema = z.object({
|
||||
export const CreateAdminSchema = z.object({
|
||||
full_name: z.string().min(1, "Full name is required"),
|
||||
email: z.string().email("Invalid email address"),
|
||||
phone: z.string().regex(/^\+?[1-9]\d{1,14}$/, "Invalid phone number"),
|
||||
phone: z
|
||||
.string()
|
||||
.optional()
|
||||
.transform((val) => (val?.trim() ? val.trim() : ""))
|
||||
.refine((val) => !val || isValidE164Phone(val), {
|
||||
message: "Invalid phone number",
|
||||
}),
|
||||
password: z
|
||||
.string()
|
||||
.min(8, "Password must be at least 8 characters long")
|
||||
|
||||
Reference in New Issue
Block a user