mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-09-09 02:28:20 +00:00
Update ProfilePage to handle user updates more reliably and prevent race conditions
This commit is contained in:
@@ -269,13 +269,11 @@ export function ProfilePage() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const onSavePersonal = async (values: PersonalValues) => {
|
const onSavePersonal = async (values: PersonalValues) => {
|
||||||
|
if (!user) return;
|
||||||
|
|
||||||
setIsSavingProfile(true);
|
setIsSavingProfile(true);
|
||||||
try {
|
try {
|
||||||
// The PATCH already returns the updated user — trusting it instead of
|
await updateTrigger({
|
||||||
// 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({
|
|
||||||
url: '/auth/update-profile',
|
url: '/auth/update-profile',
|
||||||
method: 'PATCH',
|
method: 'PATCH',
|
||||||
body: {
|
body: {
|
||||||
@@ -286,7 +284,25 @@ export function ProfilePage() {
|
|||||||
},
|
},
|
||||||
}).unwrap();
|
}).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'));
|
notify.success(t('profile.profileUpdated'));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
handleError(e);
|
handleError(e);
|
||||||
|
|||||||
Reference in New Issue
Block a user