diff --git a/apps/portal/src/app/features/profile/pages/ProfilePage.tsx b/apps/portal/src/app/features/profile/pages/ProfilePage.tsx index fa4373973..14f709b8b 100644 --- a/apps/portal/src/app/features/profile/pages/ProfilePage.tsx +++ b/apps/portal/src/app/features/profile/pages/ProfilePage.tsx @@ -269,13 +269,11 @@ export function ProfilePage() { }); const onSavePersonal = async (values: PersonalValues) => { + if (!user) return; + setIsSavingProfile(true); try { - // The PATCH already returns the updated user — trusting it instead of - // an immediate follow-up GET avoids a read-after-write race where the - // GET can return pre-edit data and silently undo `setUser` below, - // which is why the change used to only show up after a re-login. - const updated = await updateTrigger({ + await updateTrigger({ url: '/auth/update-profile', method: 'PATCH', body: { @@ -286,7 +284,25 @@ export function ProfilePage() { }, }).unwrap(); - dispatch(setUser(updated)); + // Update the session from the values that were just accepted. The + // endpoint is allowed to return no body (or a response wrapper), so + // treating its response as an AuthUser can blank or retain stale UI + // state until the next login. + const updatedUser: AuthUser = { + ...user, + email: values.email, + username: values.username, + phoneNumber: values.phoneNumber, + name: { am: values.nameAm, en: values.nameEn }, + }; + dispatch(setUser(updatedUser)); + resetPersonal({ + nameEn: updatedUser.name.en, + nameAm: updatedUser.name.am, + username: updatedUser.username, + email: updatedUser.email, + phoneNumber: updatedUser.phoneNumber, + }); notify.success(t('profile.profileUpdated')); } catch (e) { handleError(e);