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

View File

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