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:
estifanos
2026-08-08 07:32:33 +00:00
parent 0f7c1dba4b
commit 85c9930363
9 changed files with 160 additions and 62 deletions

View File

@@ -1,5 +1,6 @@
import { useState, useMemo, useEffect, useCallback } from 'react';
import { Stack, Select, Group, Text, Loader, Center, Badge } from '@mantine/core';
import { ErrorState } from '@ema-platform/ui';
import { useGetLocationTypesQuery, useGetLocationsQuery } from '../api/location-api';
import type { Location, LocationType } from '../types/location';
import { useTranslation } from 'react-i18next';
@@ -13,8 +14,8 @@ interface LocationPickerProps {
export function LocationPicker({ value, onChange, onChainChange, required }: LocationPickerProps) {
const { t } = useTranslation();
const { data: typesRes, isLoading: typesLoading } = useGetLocationTypesQuery();
const { data: locsRes, isLoading: locsLoading } = useGetLocationsQuery({ take: 10000 });
const { data: typesRes, isLoading: typesLoading, isError: typesError, refetch: refetchTypes } = useGetLocationTypesQuery();
const { data: locsRes, isLoading: locsLoading, isError: locsError, refetch: refetchLocs } = useGetLocationsQuery({ take: 10000 });
const locationTypes = typesRes?.items ?? [];
const allLocations = locsRes?.items ?? [];
@@ -160,6 +161,18 @@ export function LocationPicker({ value, onChange, onChainChange, required }: Loc
);
}
if (typesError || locsError) {
return (
<ErrorState
title={t('location.loadFailed')}
onRetry={() => {
refetchTypes();
refetchLocs();
}}
/>
);
}
const roots = childrenByParentId.get('__root__') ?? [];
if (roots.length === 0) {