Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Reset turnstile on submission request failure
  • Loading branch information
regalijan committed Oct 19, 2023
1 parent 2db6aca commit d9bebf9
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions app/routes/report.tsx
Expand Up @@ -66,6 +66,8 @@ export default function () {
);
}, []);

const { logged_in, site_key } = useLoaderData<typeof loader>();

async function submit() {
const usernames = (
document.getElementById("usernames") as HTMLInputElement
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -181,8 +191,6 @@ export default function () {
sessionStorage.setItem("REPORT_SUCCESS", "1");
}

const { logged_in, site_key } = useLoaderData<typeof loader>();

useEffect(() => {
if (logged_in) return;

Expand Down

0 comments on commit d9bebf9

Please sign in to comment.