{t["A Path to Heavenly Marriage"]}
{ t[ 'We have come together with the goal of creating a secure and confidential path for "permanent marriage" among Muslims' ] }
120
{t["user profiles"]}
14
{t["matches"]}
14
{t["marriages"]}
"use client"; import Image from "next/image"; import { useRouter } from "next/navigation"; import { useEffect, useRef, 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"; 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(); const { data: profile, refetch } = useMarriageProfileQuery({ enabled: false, retry: false, }); 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; } setIsSubmitting(true); try { if (!authBridge.isAuthenticated()) { const token = await authBridge.ensureToken(); if (!token) { console.warn("No token from bridge – proceeding with fallback path"); } } let profileResponse = profile; try { const { data: freshProfile } = await refetch(); profileResponse = freshProfile ?? profile; } catch (refetchError) { console.warn( "Could not refetch profile data – using fallback", refetchError, ); } const submitPath = getSubmitPath(profileResponse); const nextPath = localizePath( submitPath === "/intro" ? "/terms" : submitPath, locale, ); router.push(nextPath); } catch (error) { console.error("Submission/redirect failed", error); router.push(localizePath("/terms", locale)); } finally { setIsSubmitting(false); } }; if (isCheckingRedirect) { return null; } return (
{ t[ 'We have come together with the goal of creating a secure and confidential path for "permanent marriage" among Muslims' ] }
120
{t["user profiles"]}
14
{t["matches"]}
14
{t["marriages"]}