"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}
); }