Compare commits

...
+15 -2
View File
@@ -75,8 +75,10 @@ export class ProfileStore implements IUserProfileStore {
// actions
fetchUserProfile: action,
updateUserProfile: action,
finishUserOnboarding: action,
updateTourCompleted: action,
updateUserTheme: action,
mutateUserProfile: action,
});
// services
this.userService = new UserService();
@@ -85,8 +87,19 @@ export class ProfileStore implements IUserProfileStore {
// helper action
mutateUserProfile = (data: Partial<TUserProfile>) => {
if (!data) return;
// Use lodash set with proper MobX reactivity for each property
Object.entries(data).forEach(([key, value]) => {
if (key in this.data) set(this.data, key, value);
if (key in this.data) {
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
// For nested objects, update each nested property
Object.entries(value).forEach(([nestedKey, nestedValue]) => {
set(this.data, `${key}.${nestedKey}`, nestedValue);
});
} else {
// For primitive values, set directly
set(this.data, key, value);
}
}
});
};
@@ -168,7 +181,7 @@ export class ProfileStore implements IUserProfileStore {
// update user onboarding status
await this.userService.updateUserOnBoard();
// update the user profile store
// update the user profile store locally
runInAction(() => {
this.mutateUserProfile({ ...dataToUpdate, is_onboarded: true });
});