|
|
|
@ -2,12 +2,11 @@ |
|
|
|
|
|
|
|
import Image from "next/image"; |
|
|
|
import { useRouter } from "next/navigation"; |
|
|
|
import { useEffect, useRef, useState } from "react"; |
|
|
|
import { useState } from "react"; |
|
|
|
import Button from "@/components/Componentes/button"; |
|
|
|
import PageHeader from "@/components/Componentes/page-header"; |
|
|
|
import ReportActionsSheet from "@/components/Componentes/report-actions-sheet"; |
|
|
|
import VideoPlayer from "@/components/Componentes/video-player"; |
|
|
|
import type { MarriageProfileResponse } from "@/hooks/marriage/types"; |
|
|
|
import { useMarriageConfigQuery } from "@/hooks/marriage/use-marriage-config"; |
|
|
|
import { useMarriageProfileQuery } from "@/hooks/marriage/use-profile-main"; |
|
|
|
import { authBridge } from "@/lib/auth-bridge"; |
|
|
|
@ -15,8 +14,6 @@ import { getSubmitPath } from "@/lib/get-submit-path"; |
|
|
|
import { localizePath } from "@/translations/config"; |
|
|
|
import { useI18n } from "@/translations/provider"; |
|
|
|
|
|
|
|
const REDIRECT_SESSION_KEY = "redirect"; |
|
|
|
|
|
|
|
export default function Intro() { |
|
|
|
const router = useRouter(); |
|
|
|
const { dictionary: t, locale } = useI18n(); |
|
|
|
@ -26,80 +23,10 @@ export default function Intro() { |
|
|
|
}); |
|
|
|
const [isReportSheetOpen, setIsReportSheetOpen] = useState(false); |
|
|
|
const [isSubmitting, setIsSubmitting] = useState(false); |
|
|
|
const [isCheckingRedirect, setIsCheckingRedirect] = useState(true); |
|
|
|
const [isPlayerOpen, setIsPlayerOpen] = useState(false); |
|
|
|
const isRedirectingRef = useRef(false); |
|
|
|
|
|
|
|
const { data: config } = useMarriageConfigQuery(); |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
let isCancelled = false; |
|
|
|
|
|
|
|
const redirectIfNeeded = async () => { |
|
|
|
if (isRedirectingRef.current) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
const isAuthenticated = authBridge.isAuthenticated(); |
|
|
|
|
|
|
|
if (!isAuthenticated) { |
|
|
|
if (!isCancelled) { |
|
|
|
setIsCheckingRedirect(false); |
|
|
|
} |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
isRedirectingRef.current = true; |
|
|
|
|
|
|
|
if (!isCancelled) { |
|
|
|
setIsCheckingRedirect(true); |
|
|
|
} |
|
|
|
|
|
|
|
const profileResponse = profile ?? (await refetch()).data; |
|
|
|
const nextPath = localizePath(getSubmitPath(profileResponse), locale); |
|
|
|
if (typeof window !== "undefined") { |
|
|
|
try { |
|
|
|
window.sessionStorage.removeItem(REDIRECT_SESSION_KEY); |
|
|
|
} catch (e) { |
|
|
|
console.warn("sessionStorage is not accessible:", e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!isCancelled) { |
|
|
|
const currentPath = |
|
|
|
typeof window !== "undefined" ? window.location.pathname : ""; |
|
|
|
if (currentPath === nextPath) { |
|
|
|
setIsCheckingRedirect(false); |
|
|
|
} else { |
|
|
|
router.replace(nextPath); |
|
|
|
} |
|
|
|
return; |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
console.error("Error in redirectIfNeeded:", error); |
|
|
|
if (!isCancelled) { |
|
|
|
setIsCheckingRedirect(false); |
|
|
|
} |
|
|
|
} finally { |
|
|
|
isRedirectingRef.current = false; |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
void redirectIfNeeded(); |
|
|
|
|
|
|
|
const unsubscribe = window.addFlutterResponseListener?.((event) => { |
|
|
|
if (event.action === "login" && event.success) { |
|
|
|
void redirectIfNeeded(); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
return () => { |
|
|
|
isCancelled = true; |
|
|
|
unsubscribe?.(); |
|
|
|
}; |
|
|
|
}, [locale, profile, refetch, router]); |
|
|
|
|
|
|
|
const handleSubmit = async () => { |
|
|
|
if (isSubmitting) { |
|
|
|
return; |
|
|
|
@ -111,7 +38,8 @@ export default function Intro() { |
|
|
|
if (!authBridge.isAuthenticated()) { |
|
|
|
const token = await authBridge.ensureToken(); |
|
|
|
if (!token) { |
|
|
|
console.warn("No token from bridge – proceeding with fallback path"); |
|
|
|
console.warn("No token from bridge – login was not completed"); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -140,10 +68,6 @@ export default function Intro() { |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
if (isCheckingRedirect) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
return ( |
|
|
|
<div className="pt-[max(16px,calc(var(--safe-top)+8px))]"> |
|
|
|
{isReportSheetOpen && ( |
|
|
|
|