import { createSignal, Show, onMount } from "solid-js"; import { useSearchParams } from "@solidjs/router"; import { PageHead } from "~/components/PageHead"; import SubdomainHeader from "~/components/SubdomainHeader"; import Button from "~/components/ui/Button"; import { useSite } from "~/context/SiteContext"; import { useDarkMode } from "~/context/darkMode"; const POLL_INTERVAL_MS = 1500; const MAX_POLLS = 8; export default function NookSuccess() { const site = useSite(); const { isDark } = useDarkMode(); const [searchParams] = useSearchParams(); const sessionId = () => (searchParams.session_id as string | undefined) ?? ""; const brandColor = () => isDark() ? (site().brandColorDark ?? site().brandColor) : site().brandColor; const [key, setKey] = createSignal(null); const [failed, setFailed] = createSignal(false); const [copied, setCopied] = createSignal(false); const copyKey = async () => { const value = key(); if (!value) return; await navigator.clipboard.writeText(value); setCopied(true); setTimeout(() => setCopied(false), 2000); }; onMount(async () => { if (!sessionId()) { setFailed(true); return; } for (let i = 0; i < MAX_POLLS; i++) { try { const res = await fetch( `/api/the-nook/by-session?session_id=${encodeURIComponent(sessionId())}` ); if (res.ok) { const data = (await res.json()) as { key: string }; setKey(data.key); return; } } catch { // transient — keep polling } await new Promise((r) => setTimeout(r, POLL_INTERVAL_MS)); } setFailed(true); }); return ( <>

Confirming your order…

Checking payment and preparing your license key.

} >

Thank you

Check your email for your license key.

} >

Thanks for buying The Nook

Here is your license key. Open The Nook, go to Settings, and enter it to activate.

{key()}

We also emailed this key to you. You can activate up to 3 devices.

); }