fix(user): clone user data before updates to prevent mutations

Updated the `updateCurrentUser` method in `UserStore` to clone the current user data before making updates, ensuring that the original data remains unchanged during the update process. Additionally, added logic to update the local state with the new user data after a successful update.

fix(cover-image): return absolute URLs for cover images

Modified the `handleCoverImageChange` function to return absolute URLs for cover images, ensuring compatibility with the expected format. This change includes handling both uploaded images and new images, providing a consistent return structure.
This commit is contained in:
Atul Tameshwari
2026-06-22 13:03:29 +05:30
parent 4a0746b45e
commit 955ee49ada
2 changed files with 14 additions and 4 deletions

View File

@@ -153,7 +153,7 @@ export class UserStore implements IUserStore {
* @returns {Promise<IUser>}
*/
updateCurrentUser = async (data: Partial<IUser>): Promise<IUser> => {
const currentUserData = this.data;
const currentUserData = cloneDeep(this.data);
try {
if (currentUserData) {
Object.keys(data).forEach((key: string) => {
@@ -162,6 +162,14 @@ export class UserStore implements IUserStore {
});
}
const user = await this.userService.updateUser(data);
if (user && this.data) {
runInAction(() => {
Object.keys(user).forEach((key: string) => {
const userKey: keyof IUser = key as keyof IUser;
if (this.data) set(this.data, userKey, user[userKey]);
});
});
}
return user;
} catch (error) {
if (currentUserData) {

View File

@@ -272,11 +272,13 @@ export const handleCoverImageChange = async (
}
if (analysis.needsUpload) {
await uploadCoverImage(newImage, uploadConfig);
return;
const assetUrl = await uploadCoverImage(newImage, uploadConfig);
// cover_image requires an absolute URL; cover_image_url is relative (matches GET /api/users/me/ format)
return { cover_image: getFileURL(assetUrl) || assetUrl, cover_image_url: assetUrl };
}
return { cover_image: newImage };
// cover_image requires an absolute URL; getFileURL converts relative paths from the Upload tab
return { cover_image: getFileURL(newImage) || newImage, cover_image_url: newImage };
};
/**