diff --git a/src/components/layout/Radio.tsx b/src/components/layout/Radio.tsx index 6f755c8..c6bb29a 100644 --- a/src/components/layout/Radio.tsx +++ b/src/components/layout/Radio.tsx @@ -9,16 +9,16 @@ export function StyledRadioGroup(props: { value: string, choices: Choices, onVal props.onValueChange(e)} class="grid w-full gap-4 grid-cols-2"> {choice => - +
- +
{choice.label}
-
{choice.caption}
+
{choice.caption}
diff --git a/src/components/layout/TextField.tsx b/src/components/layout/TextField.tsx index 51ac702..9b6a23b 100644 --- a/src/components/layout/TextField.tsx +++ b/src/components/layout/TextField.tsx @@ -39,9 +39,9 @@ export function TextField(props: TextFieldProps) { } + fallback={} > - + {props.error} diff --git a/src/components/waitlist/WaitlistAlreadyIn.tsx b/src/components/waitlist/WaitlistAlreadyIn.tsx index 149b30c..04adc2c 100644 --- a/src/components/waitlist/WaitlistAlreadyIn.tsx +++ b/src/components/waitlist/WaitlistAlreadyIn.tsx @@ -12,6 +12,7 @@ const relayUrls = [ import { SimplePool } from 'nostr-tools' import { LoadingSpinner } from "~/components/layout"; import Notes from "~/components/waitlist/Notes"; +import logo from '~/assets/icons/mutiny-logo.svg'; const pool = new SimplePool() @@ -34,14 +35,17 @@ export function WaitlistAlreadyIn() { const [posts] = createResource("", postsFetcher); return ( -
+
+ + logo +

You're on a list!

We'll message you when Mutiny Wallet is ready.

-
+

Recent Updates

-
}> +
}> diff --git a/src/components/waitlist/WaitlistForm.tsx b/src/components/waitlist/WaitlistForm.tsx index d2dc508..255701f 100644 --- a/src/components/waitlist/WaitlistForm.tsx +++ b/src/components/waitlist/WaitlistForm.tsx @@ -1,116 +1,110 @@ -import { createSignal } from "solid-js"; -import { Button, LoadingSpinner } from "~/components/layout"; - -const INPUT = "w-full mb-4 p-2 rounded-lg text-black" +import { Match, Switch, createSignal } from "solid-js"; +import { Button } from "~/components/layout"; +import { StyledRadioGroup } from "../layout/Radio"; +import { TextField } from "../layout/TextField"; +import { SubmitHandler, createForm, email, getValue, required, setValue } from "@modular-forms/solid"; +import { showToast } from "../Toaster"; +import eify from "~/utils/eify"; +import logo from '~/assets/icons/mutiny-logo.svg'; const WAITLIST_ENDPOINT = "https://waitlist.mutiny-waitlist.workers.dev/waitlist"; +const COMMUNICATION_METHODS = [{ value: "nostr", label: "Nostr", caption: "Your freshest npub" }, { value: "email", label: "Email", caption: "Burners welcome" }] + +type WaitlistForm = { + user_type: "nostr" | "email", + id: string + comment?: string +} + +const initialValues: WaitlistForm = { user_type: "nostr", id: "", comment: "" }; + export default function WaitlistForm() { - const [nostr, setNostr] = createSignal(true); - const [error, setError] = createSignal(undefined); + const [waitlistForm, { Form, Field }] = createForm({ initialValues }); + const [loading, setLoading] = createSignal(false); - // Form submission function that takes the form data and sends it to the backend - const handleSubmit = async (e: Event) => { - e.preventDefault(); - setError(undefined); - setLoading(true); - const form = e.currentTarget; - const data = new FormData(form as HTMLFormElement); - const value = Object.fromEntries(data.entries()); - console.log(value); - - let payload: null | { user_type: string, id: string, comment: string } = null; - - if (nostr()) { - payload = { - user_type: "nostr", - id: value.pubkey as string, - comment: value.comments as string - } - } else { - payload = { - user_type: "email", - id: value.email as string, - comment: value.comments as string - } - } - - console.log(payload); + const newHandleSubmit: SubmitHandler = async (f: WaitlistForm) => { + console.log(f); + // TODO: not sure why waitlistForm.submitting doesn't work for me + // https://modularforms.dev/solid/guides/handle-submission + setLoading(true) try { - if (!payload || !payload.id) { - throw new Error("nope"); - } - const res = await fetch(WAITLIST_ENDPOINT, { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify(payload) + body: JSON.stringify(f) }) if (res.status !== 200) { throw new Error("nope"); } else { // On success set the id in local storage and reload the page - localStorage.setItem('waitlist_id', payload.id); + localStorage.setItem('waitlist_id', f.id); window.location.reload(); } } catch (e) { - if (nostr()) { - setError("Something went wrong. Are you sure that's a valid npub?"); + if (f.user_type === "nostr") { + const error = new Error("Something went wrong. Are you sure that's a valid npub?") + showToast(eify(error)) + } else { - setError("Something went wrong. Are you sure that's a valid email?"); + const error = new Error("Something went wrong. Not sure what.") + showToast(eify(error)) } - setTimeout(() => setLoading(false), 1000); return + } finally { + setLoading(false) } } return ( -
+
+ + logo +

Join Waitlist

- {/* HTML form with three inputs: nostr pubkey (text), email (text), and a textarea for comments */}

Sign up for our waitlist and we'll send a message when Mutiny Wallet is ready for you.

-
-
- - -
- {error() && -
-

Error: {error()}

-
- } -
- {nostr() && - <> - - - - } - { - !nostr() && - <> - - - - } - -