Update AddressFormContent and ProfilePage to lock primary phone and email fields as account details

This commit is contained in:
estifanos
2026-08-08 07:36:04 +00:00
parent 85c9930363
commit 451e9a7f35
2 changed files with 29 additions and 26 deletions

View File

@@ -124,8 +124,9 @@ export function AddressFormContent({
/>
<TextInput
label="Primary Phone"
placeholder="+251 9XX XXX XXX"
description="From your account, edit it in the Personal tab"
required
readOnly
{...register('primaryPhoneNumber')}
error={errors.primaryPhoneNumber?.message}
/>
@@ -138,7 +139,8 @@ export function AddressFormContent({
<TextInput
label="Email"
type="email"
placeholder="email@example.com"
description="From your account, edit it in the Personal tab"
readOnly
{...register('email')}
error={errors.email?.message}
/>

View File

@@ -195,36 +195,37 @@ export function ProfilePage() {
maritalStatus: currentProfile.maritalStatus || '',
});
if (currentProfile.address) {
setLoadedAddress({
idType: currentProfile.address.idType || '',
idNumber: currentProfile.address.idNumber || '',
nationality: currentProfile.address.nationality || '',
primaryPhoneNumber: currentProfile.address.primaryPhoneNumber || '',
secondaryPhoneNumber: currentProfile.address.secondaryPhoneNumber || '',
email: currentProfile.address.email || '',
website: currentProfile.address.website || '',
regionId: currentProfile.address.regionId || '',
cityId: currentProfile.address.cityId || '',
subcityId: currentProfile.address.subCityId || '',
woredaId: currentProfile.address.woredaId || '',
streetAddress: currentProfile.address.streetAddress || '',
postalAddress: currentProfile.address.postalAddress || '',
emergencyContactName: currentProfile.address.emergencyContactName || '',
emergencyContactPhone: currentProfile.address.emergencyContactPhone || '',
// Previously read `emergencycontactRelation` (lower-case c), so the
// saved relationship never appeared when reopening the profile.
emergencyContactRelation:
currentProfile.address.emergencyContactRelation || '',
});
}
// Primary phone and email are the account's contact details (same
// source as the Personal tab), not the address record — always
// populated even before an address exists, and locked in the form.
setLoadedAddress({
idType: currentProfile.address?.idType || '',
idNumber: currentProfile.address?.idNumber || '',
nationality: currentProfile.address?.nationality || '',
primaryPhoneNumber: user?.phoneNumber || '',
secondaryPhoneNumber: currentProfile.address?.secondaryPhoneNumber || '',
email: user?.email || '',
website: currentProfile.address?.website || '',
regionId: currentProfile.address?.regionId || '',
cityId: currentProfile.address?.cityId || '',
subcityId: currentProfile.address?.subCityId || '',
woredaId: currentProfile.address?.woredaId || '',
streetAddress: currentProfile.address?.streetAddress || '',
postalAddress: currentProfile.address?.postalAddress || '',
emergencyContactName: currentProfile.address?.emergencyContactName || '',
emergencyContactPhone: currentProfile.address?.emergencyContactPhone || '',
// Previously read `emergencycontactRelation` (lower-case c), so the
// saved relationship never appeared when reopening the profile.
emergencyContactRelation:
currentProfile.address?.emergencyContactRelation || '',
});
setDataLoading(false);
} else if (!profileResolving) {
// Resolver finished and there is still nothing — render the empty form
// rather than an indefinite spinner.
setDataLoading(false);
}
}, [resolvedProfile, storedProfile, profileResolving]);
}, [resolvedProfile, storedProfile, profileResolving, user]);
// Load the latest user from the server on mount
useEffect(() => {