blocker phase 3 addresses

This commit is contained in:
hamid
2026-08-02 21:15:57 +03:30
parent 2cd1075286
commit dd3e39dec5
8 changed files with 47 additions and 6 deletions
@@ -172,6 +172,8 @@ export default function AddressesPage() {
latitude: editing.latitude,
longitude: editing.longitude,
isPrimary: editing.isPrimary,
recipientName: editing.recipientName,
recipientPhone: editing.recipientPhone,
}
: undefined
}
@@ -51,6 +51,8 @@ describe('<AddressForm/> component', () => {
latitude: 35.7,
longitude: 51.4,
isPrimary: false,
recipientName: 'Sara',
recipientPhone: '09120001234',
}}
onSubmit={onSubmit}
/>
@@ -67,6 +69,8 @@ describe('<AddressForm/> component', () => {
latitude: 35.7,
longitude: 51.4,
isPrimary: false,
recipientName: 'Sara',
recipientPhone: '09120001234',
});
});
});
@@ -7,6 +7,7 @@ import Stack from '@mui/material/Stack';
import Switch from '@mui/material/Switch';
import { AppButton } from '@/components/common';
import { RhfControlGroup, RhfTextField } from '@/components/common/form';
import PhoneNumberField, { isIranianMobile } from '@/components/PhoneNumberField';
import { cityCentroid } from '@/services/geography/constants';
import type { CreateAddressInput, LatLng } from '@/services/addresses/types';
import CascadingRegionSelect, { type CascadingRegionValue } from './CascadingRegionSelect';
@@ -22,6 +23,8 @@ export interface AddressFormInitial {
latitude?: number | null;
longitude?: number | null;
isPrimary?: boolean;
recipientName?: string | null;
recipientPhone?: string | null;
}
export interface AddressFormProps {
@@ -39,6 +42,8 @@ interface AddressFormValues {
pin: LatLng | null;
addressLine: string;
isPrimary: boolean;
recipientName: string;
recipientPhone: string;
}
// Only prefill the region when we have the province — a city id without its province can't drive
@@ -78,6 +83,8 @@ const AddressForm: FunctionComponent<AddressFormProps> = ({ initial, submitting
pin: initialPin(initial),
addressLine: initial?.addressLine ?? '',
isPrimary: initial?.isPrimary ?? false,
recipientName: initial?.recipientName ?? '',
recipientPhone: initial?.recipientPhone ?? '',
},
});
const { control, handleSubmit, formState } = form;
@@ -98,6 +105,8 @@ const AddressForm: FunctionComponent<AddressFormProps> = ({ initial, submitting
latitude: (values.pin as LatLng).latitude,
longitude: (values.pin as LatLng).longitude,
isPrimary: values.isPrimary,
recipientName: values.recipientName.trim(),
recipientPhone: values.recipientPhone,
});
};
@@ -153,6 +162,29 @@ const AddressForm: FunctionComponent<AddressFormProps> = ({ initial, submitting
fullWidth
/>
<RhfTextField<AddressFormValues>
name="recipientName"
label={t('recipient_name_label')}
rules={{ validate: (value) => String(value ?? '').trim().length > 0 || t('recipient_name_required') }}
fullWidth
/>
<RhfControlGroup<AddressFormValues>
name="recipientPhone"
rules={{ validate: (value) => isIranianMobile(String(value ?? '')) }}
>
{({ field, hasError }) => (
<PhoneNumberField
label={t('recipient_phone_label')}
value={(field.value as string) ?? ''}
onChange={field.onChange}
error={hasError}
helperText={hasError ? t('recipient_phone_invalid') : undefined}
fullWidth
/>
)}
</RhfControlGroup>
<RhfControlGroup<AddressFormValues> name="isPrimary">
{({ field }) => (
<FormControlLabel