mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-08-29 09:31:01 +00:00
Add address management features and improve validation
- Implement saveMyAddress mutation for updating user addresses. - Enhance address validation schema with additional fields. - Add error handling for location loading in LocationPicker. - Update translations for loading errors in English and Amharic. - Introduce phone number validation for Ethiopian formats. - Refactor AddressFormContent to accommodate new address structure.
This commit is contained in:
13
libs/ui/src/lib/input/phone.ts
Normal file
13
libs/ui/src/lib/input/phone.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
/** Accepts `09xxxxxxxx` or `+2519xxxxxxxx`; always yields `+2519xxxxxxxx`. */
|
||||
export const ethiopianPhone = z
|
||||
.string()
|
||||
.trim()
|
||||
.transform((v) => (/^09\d{8}$/.test(v) ? `+251${v.slice(1)}` : v))
|
||||
.refine((v) => /^\+2519\d{8}$/.test(v), {
|
||||
message: 'Enter a valid phone number (+2519xxxxxxxx)',
|
||||
});
|
||||
|
||||
/** Same rules, but blank is allowed. */
|
||||
export const optionalEthiopianPhone = z.union([z.literal(''), ethiopianPhone]).optional();
|
||||
Reference in New Issue
Block a user