[WEB-6794] fix: align profile cover update with correct unsplash and upload handling (#8830)
* fix: profile cover update * chore: code refactoring * chore: code refactoring
This commit is contained in:
parent
9fa707b260
commit
d8ed19f204
2 changed files with 55 additions and 48 deletions
|
|
@ -150,13 +150,32 @@ export const GeneralProfileSettingsForm = observer(function GeneralProfileSettin
|
|||
role: formData.role,
|
||||
};
|
||||
|
||||
const updateCurrentUserDetail = updateCurrentUser(userPayload).finally(() => setIsLoading(false));
|
||||
const updateCurrentUserProfile = updateUserProfile(profilePayload).finally(() => setIsLoading(false));
|
||||
const updateCurrentUserDetail = updateCurrentUser(userPayload);
|
||||
const promises: Promise<IUser | TUserProfile | undefined>[] = [updateCurrentUserDetail];
|
||||
if (profilePayload.role !== profile.role) {
|
||||
const updateCurrentUserProfile = updateUserProfile(profilePayload);
|
||||
promises.push(updateCurrentUserProfile);
|
||||
}
|
||||
|
||||
const promises = [updateCurrentUserDetail, updateCurrentUserProfile];
|
||||
const updateUserAndProfile = Promise.all(promises);
|
||||
const updatePromise = Promise.allSettled(promises)
|
||||
.then((results) => {
|
||||
const rejectedResult = results.find((result) => result.status === "rejected") as
|
||||
| PromiseRejectedResult
|
||||
| undefined;
|
||||
if (rejectedResult) {
|
||||
throw rejectedResult.reason ?? new Error("Failed to update profile");
|
||||
}
|
||||
const values = results.map(
|
||||
(result) => (result as PromiseFulfilledResult<IUser | TUserProfile | undefined>).value
|
||||
);
|
||||
if (values.some((v) => v === undefined)) {
|
||||
throw new Error("Failed to update profile");
|
||||
}
|
||||
return values;
|
||||
})
|
||||
.finally(() => setIsLoading(false));
|
||||
|
||||
setPromiseToast(updateUserAndProfile, {
|
||||
setPromiseToast(updatePromise, {
|
||||
loading: "Updating...",
|
||||
success: {
|
||||
title: "Success!",
|
||||
|
|
@ -167,11 +186,6 @@ export const GeneralProfileSettingsForm = observer(function GeneralProfileSettin
|
|||
message: () => `There was some error in updating your profile. Please try again.`,
|
||||
},
|
||||
});
|
||||
updateUserAndProfile
|
||||
.then(() => {
|
||||
return;
|
||||
})
|
||||
.catch(() => {});
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue