diff --git a/apps/edr-freight-web/portal/src/pages/MyPortalPage/components/InvoicesSection.tsx b/apps/edr-freight-web/portal/src/pages/MyPortalPage/components/InvoicesSection.tsx index 4e2c30343..3ebb9606f 100644 --- a/apps/edr-freight-web/portal/src/pages/MyPortalPage/components/InvoicesSection.tsx +++ b/apps/edr-freight-web/portal/src/pages/MyPortalPage/components/InvoicesSection.tsx @@ -54,7 +54,7 @@ export const InvoicesSection = memo(function InvoicesSection({ Outstanding balance - {formatCurrency(totalOutstanding || 377500, "ETB")} + {formatCurrency(totalOutstanding || 0, "ETB")} /[^A-Za-z0-9]/.test(v) }, ] as const; +const ETHIOPIA_COUNTRY_CODE = "+251"; + +const isValidEthiopianMobile = (value: string) => { + const digits = value.replace(/\D/g, ""); + const normalized = digits.startsWith("0") ? digits.slice(1) : digits; + return /^9\d{8}$/.test(normalized); +}; + const userSchema = z .object({ email: z.string().email("Invalid email address"), - countryCode: z.string().min(1, "Country code is required"), - phone: z.string().min(9, "Phone number is too short").max(9, "Phone number is too long"), + countryCode: z.literal(ETHIOPIA_COUNTRY_CODE), + phone: z + .string() + .min(1, "Phone number is required") + .refine(isValidEthiopianMobile, "Enter a valid mobile number (e.g. 0912345678)"), userType: z.string(), firstName: z.object({ en: z.string().min(2, "Name is required"), am: z.string().nullable() }), lastName: z.object({ en: z.string().min(2, "Name is required"), am: z.string().nullable() }), @@ -64,7 +75,7 @@ export default function SignupPage() { resolver: zodResolver(userSchema), defaultValues: { email: "", - countryCode: "+251", + countryCode: ETHIOPIA_COUNTRY_CODE, phone: "", userType: userType.individual, firstName: { en: "", am: "" }, @@ -78,7 +89,8 @@ export default function SignupPage() { setError(null); setLoading(true); try { - const normalizedPhone = data.phone.startsWith("0") ? data.phone.slice(1) : data.phone; + const digits = data.phone.replace(/\D/g, ""); + const normalizedPhone = digits.startsWith("0") ? digits.slice(1) : digits; const payload: SignupPayload = { email: data.email, username: data.email, @@ -168,23 +180,35 @@ export default function SignupPage() { - + Phone * - + + + + {ETHIOPIA_COUNTRY_CODE} + - { + event.target.value = event.target.value.replace(/\D/g, "").slice(0, 10); + }, + })} /> - {errorText(errors.countryCode?.message ?? errors.phone?.message)} + {errorText(errors.phone?.message)}