From f3ddf263341cf1a37a70c457fe1107a730cfad47 Mon Sep 17 00:00:00 2001 From: Maze Winther Date: Sun, 17 Aug 2025 18:50:13 +0200 Subject: feat: export waitlist --- apps/web/src/components/export-button.tsx | 243 +++++++++++++++++++++++------- 1 file changed, 185 insertions(+), 58 deletions(-) (limited to 'apps/web/src/components') diff --git a/apps/web/src/components/export-button.tsx b/apps/web/src/components/export-button.tsx index 0e1c8774..c325db5c 100644 --- a/apps/web/src/components/export-button.tsx +++ b/apps/web/src/components/export-button.tsx @@ -1,58 +1,185 @@ -"use client"; - -import { useState } from "react"; -import { TransitionUpIcon } from "./icons"; -import { Dialog, DialogContent, DialogHeader, DialogTitle } from "./ui/dialog"; - -export function ExportButton() { - const [isExportDialogOpen, setIsExportDialogOpen] = useState(false); - - const handleExport = () => { - setIsExportDialogOpen(true); - }; - - return ( - <> - - - - ); -} - -function ExportDialog({ - isOpen, - onOpenChange, -}: { - isOpen: boolean; - onOpenChange: (open: boolean) => void; -}) { - return ( - - - - Export Project - -
-

- Export functionality is not ready yet. We're currently working on a - custom pipeline to make this possible. -

-
-
-
- ); -} +"use client"; + +import { useState } from "react"; +import { TransitionUpIcon } from "./icons"; +import { + Dialog, + DialogContent, + DialogDescription, + DialogHeader, + DialogTitle, +} from "./ui/dialog"; +import { Button } from "./ui/button"; +import { Input } from "./ui/input"; +import { useForm } from "react-hook-form"; +import { + Form, + FormControl, + FormDescription, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "./ui/form"; +import { + exportWaitlistSchema, + type ExportWaitlistInput, + type ExportWaitlistResponse, +} from "@/lib/schemas/waitlist"; +import { cn } from "@/lib/utils"; + +export function ExportButton() { + const [isExportDialogOpen, setIsExportDialogOpen] = useState(false); + + const handleExport = () => { + setIsExportDialogOpen(true); + }; + + return ( + <> + + + + ); +} + +function ExportDialog({ + isOpen, + onOpenChange, +}: { + isOpen: boolean; + onOpenChange: (open: boolean) => void; +}) { + const form = useForm({ defaultValues: { email: "" } }); + const { isSubmitting } = form.formState; + const [serverMessage, setServerMessage] = useState<{ + text: string; + type: "success" | "error"; + } | null>(null); + + const onSubmit = form.handleSubmit(async (values) => { + const parsed = exportWaitlistSchema.safeParse(values); + if (!parsed.success) { + for (const issue of parsed.error.issues) { + const fieldName = + (issue.path[0] as keyof ExportWaitlistInput) || "email"; + form.setError(fieldName, { type: "zod", message: issue.message }); + } + return; + } + setServerMessage(null); + const { email } = parsed.data; + const response = await fetch("/api/waitlist/export", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ email }), + }); + if (!response.ok) { + setServerMessage({ + text: "Something went wrong. Please try again.", + type: "error", + }); + return; + } + const data: ExportWaitlistResponse = await response.json(); + if (data.success && data.alreadySubscribed) { + setServerMessage({ + text: "You're already on the list.", + type: "success", + }); + return; + } + if (data.success) { + setServerMessage({ + text: "You're on the list. We'll email you when it's ready.", + type: "success", + }); + form.reset(); + return; + } + setServerMessage({ + text: "Couldn't add your email. Please try again.", + type: "error", + }); + }); + return ( + + + + Export Project + +
+ + Export isn't ready yet. we're building a custom pipeline to make it + great. + +
+ +
+ ( + + Email + + + + + We'll let you know once export is ready. + + + + )} + /> + +
+ {serverMessage ? ( +

+ {serverMessage.text} +

+ ) : null} +
+ +
+
+
+ ); +} -- cgit v1.3.1