From d9bebf9a091d2b7499445a17f6b2ac2a1cd7a67c Mon Sep 17 00:00:00 2001 From: regalijan Date: Thu, 19 Oct 2023 16:49:29 -0400 Subject: [PATCH] Reset turnstile on submission request failure --- app/routes/report.tsx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/app/routes/report.tsx b/app/routes/report.tsx index c5ffb9a..873eaec 100644 --- a/app/routes/report.tsx +++ b/app/routes/report.tsx @@ -66,6 +66,8 @@ export default function () { ); }, []); + const { logged_in, site_key } = useLoaderData(); + async function submit() { const usernames = ( document.getElementById("usernames") as HTMLInputElement @@ -112,13 +114,21 @@ export default function () { method: "POST", }); - if (!submitReq.ok) + if (!submitReq.ok) { + if (!logged_in) { + try { + // @ts-expect-error + turnstile.reset(); + } catch {} + } + return toast({ description: ((await submitReq.json()) as { error: string }).error, isClosable: true, status: "error", title: "Error", }); + } const { id, upload_url }: { id: string; upload_url: string } = await submitReq.json(); @@ -181,8 +191,6 @@ export default function () { sessionStorage.setItem("REPORT_SUCCESS", "1"); } - const { logged_in, site_key } = useLoaderData(); - useEffect(() => { if (logged_in) return;