From 27c2e8fee5c604d64cd06a37afc62db0252f8370 Mon Sep 17 00:00:00 2001 From: stuppie Date: Mon, 7 Sep 2026 08:53:34 -0600 Subject: add LinkAmtAccount.tsx --- jb-ui/src/pages/LinkAmtAccount.tsx | 73 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 jb-ui/src/pages/LinkAmtAccount.tsx (limited to 'jb-ui/src/pages') diff --git a/jb-ui/src/pages/LinkAmtAccount.tsx b/jb-ui/src/pages/LinkAmtAccount.tsx new file mode 100644 index 0000000..0c9dab3 --- /dev/null +++ b/jb-ui/src/pages/LinkAmtAccount.tsx @@ -0,0 +1,73 @@ +import { type FormEvent, useState } from "react"; + +import { Button } from "@/components/ui/button"; + +type RequestState = "idle" | "working" | "sent" | "failed" | "missing-worker"; + +const LinkAmtAccount = function () { + const [email, setEmail] = useState(""); + const [state, setState] = useState("idle"); + const [mockLink, setMockLink] = useState(null); + const amtWorkerId = new URLSearchParams(window.location.search).get("workerId"); + + const submit = async (event: FormEvent) => { + event.preventDefault(); + if (!amtWorkerId) { + setState("missing-worker"); + return; + } + + setState("working"); + setMockLink(null); + try { + const response = await fetch("/auth/link-amt/request", { + method: "POST", + credentials: "include", + headers: {"Content-Type": "application/json"}, + body: JSON.stringify({ + "email": email, + "amt_worker_id": amtWorkerId, + }), + }); + if (!response.ok) throw new Error("Account-link request failed"); + const body = await response.json() as {magic_link?: string}; + setMockLink(body.magic_link ?? null); + setState("sent"); + } catch { + setState("failed"); + } + }; + + return ( +
+
+

Link your MTurk account

+

Enter the email address you want to use for James Billings.

+
+ setEmail(event.target.value)} + placeholder="you@example.com" + /> + +
+ {state === "sent" &&

Check your email to finish linking your account.

} + {state === "failed" &&

Unable to send the link. Please try again.

} + {state === "missing-worker" &&

This page is missing your MTurk worker ID.

} + {mockLink && ( +

+ Development link: continue +

+ )} +
+
+ ); +}; + +export default LinkAmtAccount; -- cgit v1.2.3