|
|
@ -12,6 +12,8 @@ import type { MarriageProfileResponse } from "@/hooks/marriage/types"; |
|
|
import { localizePath } from "@/i18n/config"; |
|
|
import { localizePath } from "@/i18n/config"; |
|
|
import { useI18n } from "@/i18n/provider"; |
|
|
import { useI18n } from "@/i18n/provider"; |
|
|
|
|
|
|
|
|
|
|
|
const REDIRECT_SESSION_KEY = "redirect"; |
|
|
|
|
|
|
|
|
function getSubmitPath(profile: MarriageProfileResponse | undefined) { |
|
|
function getSubmitPath(profile: MarriageProfileResponse | undefined) { |
|
|
const isInCase = profile?.status === "in_case"; |
|
|
const isInCase = profile?.status === "in_case"; |
|
|
const isFemaleAcceptedFlow = |
|
|
const isFemaleAcceptedFlow = |
|
|
@ -39,18 +41,43 @@ export default function Intro() { |
|
|
const router = useRouter(); |
|
|
const router = useRouter(); |
|
|
const { dictionary: t, locale } = useI18n(); |
|
|
const { dictionary: t, locale } = useI18n(); |
|
|
const { data: profile, refetch } = useMarriageProfileQuery({ |
|
|
const { data: profile, refetch } = useMarriageProfileQuery({ |
|
|
|
|
|
enabled: false, |
|
|
retry: false, |
|
|
retry: false, |
|
|
}); |
|
|
}); |
|
|
const [isReportSheetOpen, setIsReportSheetOpen] = useState(false); |
|
|
const [isReportSheetOpen, setIsReportSheetOpen] = useState(false); |
|
|
const [isSubmitting, setIsSubmitting] = useState(false); |
|
|
const [isSubmitting, setIsSubmitting] = useState(false); |
|
|
|
|
|
const [isCheckingRedirect, setIsCheckingRedirect] = useState(true); |
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
useEffect(() => { |
|
|
if (!profile) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
let isCancelled = false; |
|
|
|
|
|
|
|
|
router.replace(localizePath(getSubmitPath(profile), locale)); |
|
|
|
|
|
}, [locale, profile, router]); |
|
|
|
|
|
|
|
|
const redirectIfNeeded = async () => { |
|
|
|
|
|
const shouldRedirect = |
|
|
|
|
|
authBridge.isAuthenticated() && |
|
|
|
|
|
window.sessionStorage.getItem(REDIRECT_SESSION_KEY) === "true"; |
|
|
|
|
|
|
|
|
|
|
|
if (!shouldRedirect) { |
|
|
|
|
|
if (!isCancelled) { |
|
|
|
|
|
setIsCheckingRedirect(false); |
|
|
|
|
|
} |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const profileResponse = profile ?? (await refetch()).data; |
|
|
|
|
|
const nextPath = localizePath(getSubmitPath(profileResponse), locale); |
|
|
|
|
|
window.sessionStorage.removeItem(REDIRECT_SESSION_KEY); |
|
|
|
|
|
|
|
|
|
|
|
if (!isCancelled) { |
|
|
|
|
|
router.replace(nextPath); |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
void redirectIfNeeded(); |
|
|
|
|
|
|
|
|
|
|
|
return () => { |
|
|
|
|
|
isCancelled = true; |
|
|
|
|
|
}; |
|
|
|
|
|
}, [locale, profile, refetch, router]); |
|
|
|
|
|
|
|
|
const handleSubmit = async () => { |
|
|
const handleSubmit = async () => { |
|
|
if (isSubmitting) { |
|
|
if (isSubmitting) { |
|
|
@ -66,15 +93,15 @@ export default function Intro() { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const profileResponse = profile ?? (await refetch()).data; |
|
|
|
|
|
const nextPath = localizePath(getSubmitPath(profileResponse), locale); |
|
|
|
|
|
router.push(nextPath); |
|
|
|
|
|
} finally { |
|
|
} finally { |
|
|
setIsSubmitting(false); |
|
|
setIsSubmitting(false); |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
if (isCheckingRedirect) { |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return ( |
|
|
return ( |
|
|
<div className="pt-7"> |
|
|
<div className="pt-7"> |
|
|
{isReportSheetOpen && ( |
|
|
{isReportSheetOpen && ( |
|
|
|