|
|
|
@ -488,9 +488,15 @@ export default function NewMatchClient() { |
|
|
|
const { isAdvisorOpen, openAdvisors, closeAdvisors } = |
|
|
|
useMarriageAdvisorsOverlay(); |
|
|
|
const { isProfileOpen, openProfile, closeProfile } = useMatchProfileOverlay(); |
|
|
|
const { |
|
|
|
data: profile, |
|
|
|
isError, |
|
|
|
isLoading, |
|
|
|
isFetched, |
|
|
|
isFetching, |
|
|
|
refetch: refetchProfile, |
|
|
|
} = useMarriageProfileQuery(); |
|
|
|
const [isOpeningProfile, setIsOpeningProfile] = useState(false); |
|
|
|
const { data: profile, isError, isLoading, isFetched } = |
|
|
|
useMarriageProfileQuery(); |
|
|
|
const [isPaymentSheetOpen, setIsPaymentSheetOpen] = useState(false); |
|
|
|
const [isDeclineConfirmOpen, setIsDeclineConfirmOpen] = useState(false); |
|
|
|
const [paymentError, setPaymentError] = useState<string | null>(null); |
|
|
|
@ -608,20 +614,43 @@ export default function NewMatchClient() { |
|
|
|
// Signal Flutter to lift its loading cover immediately with 0ms latency.
|
|
|
|
useHabibWebReady(true); |
|
|
|
|
|
|
|
const handleOpenProfile = () => { |
|
|
|
if (profile) { |
|
|
|
const handleOpenProfile = async () => { |
|
|
|
// If profile has not yet completed its initial server fetch or is in flight:
|
|
|
|
if (!isFetched || isFetching) { |
|
|
|
setIsOpeningProfile(true); |
|
|
|
try { |
|
|
|
const result = await refetchProfile(); |
|
|
|
const freshProfile = result.data ?? profile; |
|
|
|
setIsOpeningProfile(false); |
|
|
|
|
|
|
|
const isMaleUser = freshProfile?.gender === "male"; |
|
|
|
const hasActiveSubscription = |
|
|
|
!!freshProfile?.active_subscription && |
|
|
|
freshProfile.active_subscription.is_active !== false && |
|
|
|
freshProfile.active_subscription.is_valid !== false; |
|
|
|
|
|
|
|
if (isMaleUser && !hasActiveSubscription) { |
|
|
|
setIsPaymentSheetOpen(true); |
|
|
|
} else { |
|
|
|
openProfile(); |
|
|
|
} |
|
|
|
} catch (err) { |
|
|
|
setIsOpeningProfile(false); |
|
|
|
if (isMale && !hasActiveSub) { |
|
|
|
setIsPaymentSheetOpen(true); |
|
|
|
} else { |
|
|
|
setIsOpeningProfile(true); |
|
|
|
openProfile(); |
|
|
|
} |
|
|
|
} |
|
|
|
return; |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
if (isOpeningProfile && profile) { |
|
|
|
setIsOpeningProfile(false); |
|
|
|
if (isMale && !hasActiveSub) { |
|
|
|
setIsPaymentSheetOpen(true); |
|
|
|
} else { |
|
|
|
openProfile(); |
|
|
|
} |
|
|
|
}, [isOpeningProfile, profile, openProfile]); |
|
|
|
}; |
|
|
|
|
|
|
|
const isRedirecting = useMemo(() => { |
|
|
|
if (!profile) return false; |
|
|
|
@ -835,14 +864,8 @@ export default function NewMatchClient() { |
|
|
|
{/* Button */} |
|
|
|
<button |
|
|
|
type="button" |
|
|
|
disabled={isOpeningProfile && isLoading} |
|
|
|
onClick={() => { |
|
|
|
if (isMale && !hasActiveSub) { |
|
|
|
setIsPaymentSheetOpen(true); |
|
|
|
} else { |
|
|
|
handleOpenProfile(); |
|
|
|
} |
|
|
|
}} |
|
|
|
disabled={isOpeningProfile} |
|
|
|
onClick={handleOpenProfile} |
|
|
|
className=" |
|
|
|
mt-2.5 |
|
|
|
flex |
|
|
|
@ -863,7 +886,7 @@ export default function NewMatchClient() { |
|
|
|
border-none |
|
|
|
" |
|
|
|
> |
|
|
|
{isOpeningProfile && isLoading ? ( |
|
|
|
{isOpeningProfile ? ( |
|
|
|
<LoadingThreeDot /> |
|
|
|
) : ( |
|
|
|
<> |
|
|
|
|