Browse Source

fix: prioritize existing cache data during profile state updates and persistence

master
mortezaei 2 weeks ago
parent
commit
fbddda3a21
  1. 26
      src/hooks/marriage/use-profile-main.ts

26
src/hooks/marriage/use-profile-main.ts

@ -123,18 +123,34 @@ export function useMarriageProfileQuery<TData = MarriageProfileResponse>(
(old: MarriageProfileResponse | undefined) => {
if (!old) return data;
return {
...old,
...data,
match_summary: data.match_summary ?? old.match_summary,
active_case: data.active_case ?? old.active_case,
...old,
match_summary: old.match_summary ?? data.match_summary,
active_case: old.active_case ?? data.active_case,
active_subscription:
data.active_subscription ?? old.active_subscription,
old.active_subscription ?? data.active_subscription,
recommended_plan:
old.recommended_plan ?? data.recommended_plan,
};
},
);
if (data.id && (data.match_summary || data.status)) {
saveScopedMarriageProfile(data);
const currentPersisted = getScopedMarriageProfile();
const merged = {
...data,
...(currentPersisted || {}),
match_summary:
currentPersisted?.match_summary ?? data.match_summary,
active_case:
currentPersisted?.active_case ?? data.active_case,
recommended_plan:
currentPersisted?.recommended_plan ?? data.recommended_plan,
active_subscription:
currentPersisted?.active_subscription ??
data.active_subscription,
};
saveScopedMarriageProfile(merged);
}
}
}

Loading…
Cancel
Save