Created
July 23, 2026 15:47
-
-
Save hjoseph96/e8fcd7fa1fc7bc96dfd69464a0cc7bef to your computer and use it in GitHub Desktop.
WaitlistForm.astro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| interface Props { | |
| id?: string; | |
| } | |
| const { id } = Astro.props; | |
| const PLATFORMS = [ | |
| "LinkedIn", | |
| "Twitter (X)", | |
| "BlueSky", | |
| "Instagram", | |
| "TikTok", | |
| "YouTube", | |
| "Website", | |
| "Discord", | |
| ]; | |
| --- | |
| <form class="waitlist-form" id={id} data-waitlist-trigger> | |
| <input | |
| type="email" | |
| id="wf-trigger-email" | |
| placeholder="Enter your email" | |
| required | |
| aria-label="Email address" | |
| /> | |
| <button type="submit" class="btn btn--dark"> | |
| Join the Waitlist | |
| <span class="btn__icon"> | |
| <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> | |
| <path fill-rule="evenodd" clip-rule="evenodd" d="M18.5303 12.5303C18.8232 12.2374 18.8232 11.7626 18.5303 11.4697L14.5303 7.46967C14.2374 7.17678 13.7626 7.17678 13.4697 7.46967C13.1768 7.76256 13.1768 8.23744 13.4697 8.53033L16.1893 11.25L6 11.25C5.58579 11.25 5.25 11.5858 5.25 12C5.25 12.4142 5.58579 12.75 6 12.75L16.1893 12.75L13.4697 15.4697C13.1768 15.7626 13.1768 16.2374 13.4697 16.5303C13.7626 16.8232 14.2374 16.8232 14.5303 16.5303L18.5303 12.5303Z" fill="#FCF9FF"/> | |
| </svg> | |
| </span> | |
| </button> | |
| </form> | |
| <dialog class="waitlist-dialog" data-waitlist-dialog> | |
| <form class="wizard" data-waitlist-wizard novalidate> | |
| <button type="button" class="wizard__close" data-waitlist-close aria-label="Close">×</button> | |
| <p class="wizard__progress">Step <span data-waitlist-step-number>1</span> of 5</p> | |
| <div class="wizard__step" data-step="1"> | |
| <h3>What's your email?</h3> | |
| <input | |
| type="email" | |
| data-waitlist-email | |
| placeholder="Enter your email" | |
| required | |
| aria-label="Email address" | |
| /> | |
| <p class="wizard__error" data-error-for="1" hidden>Please enter a valid email address.</p> | |
| </div> | |
| <div class="wizard__step" data-step="2" hidden> | |
| <h3>What's your first name?</h3> | |
| <input type="text" data-waitlist-first-name placeholder="First name" required aria-label="First name" /> | |
| </div> | |
| <div class="wizard__step" data-step="3" hidden> | |
| <h3>What's your last name?</h3> | |
| <input type="text" data-waitlist-last-name placeholder="Last name" required aria-label="Last name" /> | |
| </div> | |
| <div class="wizard__step" data-step="4" hidden> | |
| <h3>What type of creator are you?</h3> | |
| <div class="wizard__options"> | |
| <label class="wizard__checkbox"> | |
| <input type="checkbox" name="creatorType" value="Artist" /> | |
| <span>Artist</span> | |
| </label> | |
| <label class="wizard__checkbox"> | |
| <input type="checkbox" name="creatorType" value="Animator" /> | |
| <span>Animator</span> | |
| </label> | |
| </div> | |
| <p class="wizard__error" data-error-for="4" hidden>Please select at least one option.</p> | |
| </div> | |
| <div class="wizard__step" data-step="5" hidden> | |
| <h3>What social media platforms do you use?</h3> | |
| <div class="wizard__options"> | |
| {PLATFORMS.map((platform) => ( | |
| <div class="wizard__platform"> | |
| <label class="wizard__checkbox"> | |
| <input type="checkbox" name="platform" value={platform} data-platform-checkbox /> | |
| <span>{platform}</span> | |
| </label> | |
| <input | |
| type="url" | |
| class="wizard__platform-url" | |
| placeholder={`Your ${platform} URL`} | |
| aria-label={`${platform} URL`} | |
| data-platform-url | |
| hidden | |
| /> | |
| </div> | |
| ))} | |
| </div> | |
| <p class="wizard__error" data-error-for="5" hidden>Please select at least one platform and provide a URL.</p> | |
| </div> | |
| <div class="wizard__step" data-step="success" hidden> | |
| <h3>You're on the list!</h3> | |
| <p>Thanks for joining the Sakugami waitlist. We'll be in touch soon.</p> | |
| </div> | |
| <div class="wizard__step" data-step="error" hidden> | |
| <h3>Something went wrong</h3> | |
| <p data-waitlist-submit-error>Please try again.</p> | |
| </div> | |
| <div class="wizard__nav"> | |
| <button type="button" class="btn btn--dark wizard__back" data-waitlist-back hidden>Back</button> | |
| <button type="button" class="btn btn--dark wizard__next" data-waitlist-next>Next</button> | |
| <button type="submit" class="btn btn--dark wizard__submit" data-waitlist-submit hidden>Join the Waitlist</button> | |
| </div> | |
| </form> | |
| </dialog> | |
| <style> | |
| .waitlist-form { | |
| display: flex; | |
| align-items: center; | |
| gap: 4px; | |
| width: 100%; | |
| max-width: 524px; | |
| margin: 0 auto; | |
| padding: 4px; | |
| border-radius: 60px; | |
| border: 0.5px solid rgba(255, 255, 255, 0.8); | |
| background: rgba(255, 255, 255, 0.1); | |
| backdrop-filter: blur(10px); | |
| } | |
| .waitlist-form button { | |
| padding: 1.45rem 1.5rem; | |
| background: var(--color-cream); | |
| color: var(--color-dark-alt); | |
| border-radius: 3em; | |
| font-weight: 800; | |
| letter-spacing: -0.3px; | |
| } | |
| .waitlist-form button svg { | |
| position: relative; | |
| top: 6px; | |
| left: 3px; | |
| } | |
| .waitlist-form button svg path { fill: black; } | |
| .waitlist-form input { | |
| flex: 1; | |
| min-width: 0; | |
| border: none; | |
| background: transparent; | |
| outline: none; | |
| padding: 0.75rem 1rem; | |
| font-family: var(--font-body); | |
| font-size: 1.125rem; | |
| color: var(--color-cream); | |
| border-radius: 40px; | |
| } | |
| .wizard__back { | |
| padding: 0.6em 1em; | |
| border-radius: 0.3em; | |
| } | |
| .wizard__next { | |
| padding: 0.6em 0.8em; | |
| border-radius: 0.3em; | |
| } | |
| .waitlist-form input::placeholder { | |
| color: var(--color-input-placeholder); | |
| } | |
| .waitlist-dialog { | |
| width: min(480px, calc(100vw - 2rem)); | |
| border: none; | |
| border-radius: 24px; | |
| padding: 2.5rem 2rem 2rem; | |
| background: var(--color-dark-alt); | |
| color: var(--color-cream); | |
| font-family: var(--font-body); | |
| } | |
| .waitlist-dialog::backdrop { | |
| background: rgba(29, 30, 34, 0.7); | |
| backdrop-filter: blur(4px); | |
| } | |
| .wizard { | |
| display: flex; | |
| flex-direction: column; | |
| gap: 1.5rem; | |
| } | |
| .wizard__close { | |
| position: absolute; | |
| top: 1rem; | |
| right: 1.25rem; | |
| border: none; | |
| background: transparent; | |
| color: var(--color-cream); | |
| font-size: 1.75rem; | |
| line-height: 1; | |
| cursor: pointer; | |
| } | |
| .wizard__progress { | |
| margin: 0; | |
| color: rgba(252, 249, 255, 0.6); | |
| font-size: 0.875rem; | |
| } | |
| .wizard__step h3 { | |
| margin: 0 0 1rem; | |
| font-size: 1.5rem; | |
| font-weight: 700; | |
| } | |
| .wizard__step input[type="email"], | |
| .wizard__step input[type="text"] { | |
| width: 100%; | |
| box-sizing: border-box; | |
| border-radius: 12px; | |
| border: 0.5px solid rgba(255, 255, 255, 0.3); | |
| background: rgba(255, 255, 255, 0.05); | |
| padding: 0.875rem 1rem; | |
| font-family: var(--font-body); | |
| font-size: 1rem; | |
| color: var(--color-cream); | |
| outline: none; | |
| } | |
| .wizard__step input::placeholder { | |
| color: var(--color-input-placeholder); | |
| } | |
| .wizard__error { | |
| margin: 0.5rem 0 0; | |
| color: #ff8080; | |
| font-size: 0.875rem; | |
| } | |
| .wizard__options { | |
| display: flex; | |
| flex-direction: column; | |
| gap: 0.75rem; | |
| } | |
| .wizard__checkbox { | |
| display: flex; | |
| align-items: center; | |
| gap: 0.75rem; | |
| cursor: pointer; | |
| font-size: 1rem; | |
| } | |
| .wizard__checkbox input { | |
| width: 18px; | |
| height: 18px; | |
| accent-color: var(--color-purple); | |
| } | |
| .wizard__platform { | |
| display: flex; | |
| flex-direction: column; | |
| gap: 0.5rem; | |
| } | |
| .wizard__platform-url { | |
| width: 100%; | |
| box-sizing: border-box; | |
| border-radius: 12px; | |
| border: 0.5px solid rgba(255, 255, 255, 0.3); | |
| background: rgba(255, 255, 255, 0.05); | |
| padding: 0.75rem 1rem; | |
| font-family: var(--font-body); | |
| font-size: 0.9375rem; | |
| color: var(--color-cream); | |
| outline: none; | |
| } | |
| .wizard__nav { | |
| display: flex; | |
| justify-content: flex-end; | |
| gap: 0.75rem; | |
| } | |
| .wizard__back { | |
| background: transparent; | |
| color: var(--color-cream); | |
| border: 0.5px solid rgba(255, 255, 255, 0.4); | |
| } | |
| .wizard__submit:disabled { | |
| opacity: 0.6; | |
| cursor: not-allowed; | |
| } | |
| @media (max-width: 640px) { | |
| .waitlist-form { | |
| flex-direction: column; | |
| background: transparent; | |
| backdrop-filter: none; | |
| border: none; | |
| padding: 0; | |
| gap: 0.75rem; | |
| } | |
| .waitlist-form input { | |
| width: 100%; | |
| border-radius: 60px; | |
| border: 0.5px solid rgba(255, 255, 255, 0.8); | |
| background: rgba(255, 255, 255, 0.1); | |
| backdrop-filter: blur(10px); | |
| box-sizing: border-box; | |
| } | |
| } | |
| </style> | |
| <script> | |
| const STEP_ORDER = ["1", "2", "3", "4", "5"]; | |
| function setUp(triggerForm: HTMLFormElement) { | |
| const dialog = document.querySelector<HTMLDialogElement>("[data-waitlist-dialog]"); | |
| const wizard = document.querySelector<HTMLFormElement>("[data-waitlist-wizard]"); | |
| if (!dialog || !wizard) return; | |
| const steps = Array.from(wizard.querySelectorAll<HTMLElement>(".wizard__step")); | |
| const progressEl = wizard.querySelector<HTMLElement>(".wizard__progress")!; | |
| const stepNumberEl = wizard.querySelector("[data-waitlist-step-number]"); | |
| const backBtn = wizard.querySelector<HTMLButtonElement>("[data-waitlist-back]")!; | |
| const nextBtn = wizard.querySelector<HTMLButtonElement>("[data-waitlist-next]")!; | |
| const submitBtn = wizard.querySelector<HTMLButtonElement>("[data-waitlist-submit]")!; | |
| const closeBtn = wizard.querySelector<HTMLButtonElement>("[data-waitlist-close]")!; | |
| const emailInput = wizard.querySelector<HTMLInputElement>("[data-waitlist-email]")!; | |
| const firstNameInput = wizard.querySelector<HTMLInputElement>("[data-waitlist-first-name]")!; | |
| const lastNameInput = wizard.querySelector<HTMLInputElement>("[data-waitlist-last-name]")!; | |
| const submitErrorEl = wizard.querySelector("[data-waitlist-submit-error]"); | |
| const triggerEmailInput = triggerForm.querySelector<HTMLInputElement>("[type=email]")!; | |
| let currentIndex = 0; | |
| function clearError(step: string) { | |
| const err = wizard!.querySelector<HTMLElement>(`[data-error-for="${step}"]`); | |
| if (err) err.hidden = true; | |
| } | |
| function showError(step: string) { | |
| const err = wizard!.querySelector<HTMLElement>(`[data-error-for="${step}"]`); | |
| if (err) err.hidden = false; | |
| } | |
| function showStep(step: string) { | |
| steps.forEach((el) => { | |
| el.hidden = el.dataset.step !== step; | |
| }); | |
| const stepIdx = STEP_ORDER.indexOf(step); | |
| progressEl.hidden = stepIdx < 0; | |
| if (stepNumberEl && stepIdx >= 0) stepNumberEl.textContent = String(stepIdx + 1); | |
| if (stepIdx >= 0) { | |
| backBtn.hidden = stepIdx <= 0; | |
| const isLast = stepIdx === STEP_ORDER.length - 1; | |
| nextBtn.hidden = isLast; | |
| submitBtn.hidden = !isLast; | |
| } else { | |
| backBtn.hidden = true; | |
| nextBtn.hidden = true; | |
| submitBtn.hidden = true; | |
| } | |
| clearError(step); | |
| } | |
| function validateStep(step: string) { | |
| if (step === "1") { | |
| const value = emailInput.value.trim(); | |
| if (!value.includes("@") || !emailInput.checkValidity()) { | |
| showError("1"); | |
| return false; | |
| } | |
| return true; | |
| } | |
| if (step === "2") return firstNameInput.reportValidity(); | |
| if (step === "3") return lastNameInput.reportValidity(); | |
| if (step === "4") { | |
| const checked = wizard!.querySelectorAll('input[name="creatorType"]:checked'); | |
| if (checked.length === 0) { | |
| showError("4"); | |
| return false; | |
| } | |
| return true; | |
| } | |
| if (step === "5") { | |
| const checkedPlatforms = wizard!.querySelectorAll<HTMLInputElement>('input[name="platform"]:checked'); | |
| if (checkedPlatforms.length === 0) { | |
| showError("5"); | |
| return false; | |
| } | |
| for (const cb of checkedPlatforms) { | |
| const urlInput = cb.closest(".wizard__platform")?.querySelector<HTMLInputElement>("[data-platform-url]"); | |
| if (!urlInput?.value.trim()) { | |
| showError("5"); | |
| return false; | |
| } | |
| } | |
| return true; | |
| } | |
| return true; | |
| } | |
| wizard.querySelectorAll<HTMLInputElement>("[data-platform-checkbox]").forEach((cb) => { | |
| cb.addEventListener("change", () => { | |
| const urlInput = cb.closest(".wizard__platform")?.querySelector<HTMLInputElement>("[data-platform-url]"); | |
| if (!urlInput) return; | |
| urlInput.hidden = !cb.checked; | |
| urlInput.required = cb.checked; | |
| if (!cb.checked) urlInput.value = ""; | |
| }); | |
| }); | |
| nextBtn.addEventListener("click", () => { | |
| const step = STEP_ORDER[currentIndex]; | |
| if (!validateStep(step)) return; | |
| currentIndex = Math.min(currentIndex + 1, STEP_ORDER.length - 1); | |
| showStep(STEP_ORDER[currentIndex]); | |
| }); | |
| backBtn.addEventListener("click", () => { | |
| currentIndex = Math.max(currentIndex - 1, 0); | |
| showStep(STEP_ORDER[currentIndex]); | |
| }); | |
| closeBtn.addEventListener("click", () => dialog.close()); | |
| dialog.addEventListener("click", (e) => { | |
| if (e.target === dialog) dialog.close(); | |
| }); | |
| triggerForm.addEventListener("submit", (e) => { | |
| e.preventDefault(); | |
| if (!triggerEmailInput.checkValidity() || !triggerEmailInput.value.includes("@")) { | |
| triggerEmailInput.reportValidity(); | |
| return; | |
| } | |
| emailInput.value = triggerEmailInput.value.trim(); | |
| currentIndex = 0; | |
| showStep(STEP_ORDER[0]); | |
| dialog.showModal(); | |
| }); | |
| wizard.addEventListener("submit", async (e) => { | |
| e.preventDefault(); | |
| if (!validateStep("5")) return; | |
| const creatorTypes = Array.from(wizard!.querySelectorAll<HTMLInputElement>('input[name="creatorType"]:checked')).map( | |
| (el) => el.value | |
| ); | |
| const socials = Array.from(wizard!.querySelectorAll<HTMLInputElement>('input[name="platform"]:checked')).map((cb) => { | |
| const urlInput = cb.closest(".wizard__platform")?.querySelector<HTMLInputElement>("[data-platform-url]"); | |
| return { platform: cb.value, url: urlInput?.value.trim() ?? "" }; | |
| }); | |
| const payload = { | |
| email: emailInput.value.trim(), | |
| firstName: firstNameInput.value.trim(), | |
| lastName: lastNameInput.value.trim(), | |
| creatorTypes, | |
| socials, | |
| }; | |
| submitBtn.disabled = true; | |
| const originalLabel = submitBtn.textContent; | |
| submitBtn.textContent = "Joining..."; | |
| try { | |
| const res = await fetch("/api/waitlist", { | |
| method: "POST", | |
| headers: { "Content-Type": "application/json" }, | |
| body: JSON.stringify(payload), | |
| }); | |
| if (!res.ok) throw new Error("Request failed"); | |
| showStep("success"); | |
| } catch { | |
| if (submitErrorEl) submitErrorEl.textContent = "Please try again."; | |
| showStep("error"); | |
| } finally { | |
| submitBtn.disabled = false; | |
| submitBtn.textContent = originalLabel; | |
| } | |
| }); | |
| } | |
| document.querySelectorAll<HTMLFormElement>("[data-waitlist-trigger]").forEach(setUp); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment