refactor: enhance phone number validation in account forms
- Updated phone number validation logic in useCompleteAccountForm and CompleteAccountStep components to include schema validation using phoneSchema. - Improved error messaging for invalid phone numbers and ensured required field checks are clearly defined.
This commit is contained in:
parent
58ed32c431
commit
73ef1d9825
@ -2,6 +2,7 @@ import { useState, useCallback } from "react";
|
||||
import { type JapanAddressFormData } from "@/features/address/components/JapanAddressForm";
|
||||
import { prepareWhmcsAddressFields } from "@customer-portal/domain/address";
|
||||
import { validatePasswordRules } from "@/features/auth/hooks/usePasswordValidation";
|
||||
import { phoneSchema } from "@customer-portal/domain/common";
|
||||
import type { AccountFormErrors } from "./types";
|
||||
|
||||
interface FormState {
|
||||
@ -90,7 +91,14 @@ export function useCompleteAccountForm({
|
||||
const passwordError = validatePasswordRules(password);
|
||||
if (passwordError) newErrors.password = passwordError;
|
||||
if (password !== confirmPassword) newErrors.confirmPassword = "Passwords do not match";
|
||||
if (!phone.trim()) newErrors.phone = "Phone number is required";
|
||||
if (phone.trim()) {
|
||||
const phoneResult = phoneSchema.safeParse(phone.trim());
|
||||
if (!phoneResult.success) {
|
||||
newErrors.phone = "Please enter a valid phone number";
|
||||
}
|
||||
} else {
|
||||
newErrors.phone = "Phone number is required";
|
||||
}
|
||||
if (!dateOfBirth) newErrors.dateOfBirth = "Date of birth is required";
|
||||
if (!gender) newErrors.gender = "Please select a gender";
|
||||
if (!acceptTerms) newErrors.acceptTerms = "You must accept the terms of service";
|
||||
|
||||
@ -15,6 +15,7 @@ import {
|
||||
validatePasswordRules,
|
||||
usePasswordValidation,
|
||||
} from "@/features/auth/hooks/usePasswordValidation";
|
||||
import { phoneSchema } from "@customer-portal/domain/common";
|
||||
import { useEligibilityCheckStore } from "../../../stores/eligibility-check.store";
|
||||
import { AccountInfoDisplay, PersonalInfoFields, PasswordSection } from "./complete-account";
|
||||
|
||||
@ -59,7 +60,14 @@ export function CompleteAccountStep() {
|
||||
if (passwordError) errors.password = passwordError;
|
||||
if (accountData.password !== accountData.confirmPassword)
|
||||
errors.confirmPassword = "Passwords do not match";
|
||||
if (!accountData.phone.trim()) errors.phone = "Phone number is required";
|
||||
if (accountData.phone.trim()) {
|
||||
const phoneResult = phoneSchema.safeParse(accountData.phone.trim());
|
||||
if (!phoneResult.success) {
|
||||
errors.phone = "Please enter a valid phone number";
|
||||
}
|
||||
} else {
|
||||
errors.phone = "Phone number is required";
|
||||
}
|
||||
if (!accountData.dateOfBirth) errors.dateOfBirth = "Date of birth is required";
|
||||
if (!accountData.gender) errors.gender = "Please select a gender";
|
||||
if (!accountData.acceptTerms) errors.acceptTerms = "You must accept the terms of service";
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user