[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:
Anmol Singh Bhatia 2026-03-31 15:54:12 +05:30 committed by GitHub
parent 9fa707b260
commit d8ed19f204
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 55 additions and 48 deletions

View file

@ -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 (