From 451e9a7f35f38e39b85ff5a4875dbda4032fb28e Mon Sep 17 00:00:00 2001 From: estifanos Date: Sat, 8 Aug 2026 07:36:04 +0000 Subject: [PATCH] Update AddressFormContent and ProfilePage to lock primary phone and email fields as account details --- .../profile/components/AddressFormContent.tsx | 6 ++- .../features/profile/pages/ProfilePage.tsx | 49 ++++++++++--------- 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/apps/portal/src/app/features/profile/components/AddressFormContent.tsx b/apps/portal/src/app/features/profile/components/AddressFormContent.tsx index 617a34751..98e91081e 100644 --- a/apps/portal/src/app/features/profile/components/AddressFormContent.tsx +++ b/apps/portal/src/app/features/profile/components/AddressFormContent.tsx @@ -124,8 +124,9 @@ export function AddressFormContent({ /> @@ -138,7 +139,8 @@ export function AddressFormContent({ diff --git a/apps/portal/src/app/features/profile/pages/ProfilePage.tsx b/apps/portal/src/app/features/profile/pages/ProfilePage.tsx index 50e5c3550..1715affd1 100644 --- a/apps/portal/src/app/features/profile/pages/ProfilePage.tsx +++ b/apps/portal/src/app/features/profile/pages/ProfilePage.tsx @@ -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(() => {