|
|
@ -39,30 +39,50 @@ export function getInitialMarriageProfile( |
|
|
} as MarriageProfileResponse; |
|
|
} as MarriageProfileResponse; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Priority 2: Use locally persisted profile from previous successful server response
|
|
|
|
|
|
|
|
|
const flutterData = authBridge.getMarriageData(); |
|
|
const persisted = getScopedMarriageProfile(); |
|
|
const persisted = getScopedMarriageProfile(); |
|
|
|
|
|
|
|
|
|
|
|
// If Flutter provided match_summary (e.g. fresh match on new/current device) and persisted doesn't have it, prefer Flutter data
|
|
|
|
|
|
if (flutterData?.match_summary && !persisted?.match_summary) { |
|
|
|
|
|
return { |
|
|
|
|
|
id: flutterData.id ?? persisted?.id ?? 0, |
|
|
|
|
|
status: flutterData.status ?? persisted?.status, |
|
|
|
|
|
gender: flutterData.gender ?? persisted?.gender, |
|
|
|
|
|
age: flutterData.age ?? persisted?.age ?? null, |
|
|
|
|
|
is_registering_for_self: flutterData.is_registering_for_self ?? persisted?.is_registering_for_self ?? null, |
|
|
|
|
|
can_edit_profile: flutterData.can_edit_profile ?? persisted?.can_edit_profile ?? true, |
|
|
|
|
|
can_message_expert: flutterData.can_message_expert ?? persisted?.can_message_expert ?? true, |
|
|
|
|
|
active_subscription: flutterData.active_subscription ?? persisted?.active_subscription ?? null, |
|
|
|
|
|
is_ready_for_match: flutterData.is_ready_for_match ?? persisted?.is_ready_for_match ?? true, |
|
|
|
|
|
active_case: flutterData.active_case ?? persisted?.active_case ?? null, |
|
|
|
|
|
needs_subscription: flutterData.needs_subscription ?? persisted?.needs_subscription ?? false, |
|
|
|
|
|
recommended_plan: flutterData.recommended_plan ?? persisted?.recommended_plan ?? null, |
|
|
|
|
|
match_summary: flutterData.match_summary ?? null, |
|
|
|
|
|
} as MarriageProfileResponse; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Priority 2: Use locally persisted profile from previous successful server response
|
|
|
if (persisted) { |
|
|
if (persisted) { |
|
|
return persisted; |
|
|
return persisted; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Priority 3: Fallback to Flutter native bridge data
|
|
|
// Priority 3: Fallback to Flutter native bridge data
|
|
|
const data = authBridge.getMarriageData(); |
|
|
|
|
|
if (!data) return undefined; |
|
|
|
|
|
|
|
|
if (!flutterData) return undefined; |
|
|
|
|
|
|
|
|
return { |
|
|
return { |
|
|
id: data.id ?? 0, |
|
|
|
|
|
status: data.status, |
|
|
|
|
|
gender: data.gender, |
|
|
|
|
|
age: data.age ?? null, |
|
|
|
|
|
is_registering_for_self: data.is_registering_for_self ?? null, |
|
|
|
|
|
can_edit_profile: data.can_edit_profile ?? true, |
|
|
|
|
|
can_message_expert: data.can_message_expert ?? true, |
|
|
|
|
|
active_subscription: data.active_subscription ?? null, |
|
|
|
|
|
is_ready_for_match: data.is_ready_for_match ?? true, |
|
|
|
|
|
active_case: data.active_case ?? null, |
|
|
|
|
|
needs_subscription: data.needs_subscription ?? false, |
|
|
|
|
|
recommended_plan: data.recommended_plan ?? null, |
|
|
|
|
|
match_summary: data.match_summary ?? null, |
|
|
|
|
|
|
|
|
id: flutterData.id ?? 0, |
|
|
|
|
|
status: flutterData.status, |
|
|
|
|
|
gender: flutterData.gender, |
|
|
|
|
|
age: flutterData.age ?? null, |
|
|
|
|
|
is_registering_for_self: flutterData.is_registering_for_self ?? null, |
|
|
|
|
|
can_edit_profile: flutterData.can_edit_profile ?? true, |
|
|
|
|
|
can_message_expert: flutterData.can_message_expert ?? true, |
|
|
|
|
|
active_subscription: flutterData.active_subscription ?? null, |
|
|
|
|
|
is_ready_for_match: flutterData.is_ready_for_match ?? true, |
|
|
|
|
|
active_case: flutterData.active_case ?? null, |
|
|
|
|
|
needs_subscription: flutterData.needs_subscription ?? false, |
|
|
|
|
|
recommended_plan: flutterData.recommended_plan ?? null, |
|
|
|
|
|
match_summary: flutterData.match_summary ?? null, |
|
|
} as MarriageProfileResponse; |
|
|
} as MarriageProfileResponse; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -102,6 +122,33 @@ export async function getMarriageProfile() { |
|
|
export function useMarriageProfileQuery<TData = MarriageProfileResponse>( |
|
|
export function useMarriageProfileQuery<TData = MarriageProfileResponse>( |
|
|
options?: QueryOptions<MarriageProfileResponse, TData>, |
|
|
options?: QueryOptions<MarriageProfileResponse, TData>, |
|
|
) { |
|
|
) { |
|
|
|
|
|
const queryClient = useQueryClient(); |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
|
const handleInitialData = (e: any) => { |
|
|
|
|
|
const data = e.detail; |
|
|
|
|
|
if (data) { |
|
|
|
|
|
queryClient.setQueryData( |
|
|
|
|
|
marriageQueryKeys.profile(), |
|
|
|
|
|
(old: MarriageProfileResponse | undefined) => { |
|
|
|
|
|
if (!old) return getInitialMarriageProfile(data); |
|
|
|
|
|
return { |
|
|
|
|
|
...old, |
|
|
|
|
|
...data, |
|
|
|
|
|
match_summary: data.match_summary ?? old.match_summary, |
|
|
|
|
|
active_case: data.active_case ?? old.active_case, |
|
|
|
|
|
}; |
|
|
|
|
|
}, |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
window.addEventListener("habib:marriage-initial-data", handleInitialData); |
|
|
|
|
|
return () => { |
|
|
|
|
|
window.removeEventListener("habib:marriage-initial-data", handleInitialData); |
|
|
|
|
|
}; |
|
|
|
|
|
}, [queryClient]); |
|
|
|
|
|
|
|
|
const query = useQuery({ |
|
|
const query = useQuery({ |
|
|
staleTime: 30 * 1000, |
|
|
staleTime: 30 * 1000, |
|
|
refetchOnWindowFocus: false, |
|
|
refetchOnWindowFocus: false, |
|
|
|