mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-09-08 00:45:42 +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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user