"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { toast } from "sonner"; import { JM } from "./modal-theme"; import { SetupHeader, FieldLabel, TextInput, TextArea, AudienceSelector, PrimaryButton, SecondaryButton, StepDots, type SetupProps, type Audience, } from "./setup-shared"; /** * "Build your own idea" — two-step setup. * Step 1: project name + audience. * Step 2: describe the idea (free text). Becomes the seed message * for the first AI conversation in the project. */ export function BuildSetup({ workspace, onClose, onBack }: SetupProps) { const router = useRouter(); const [step, setStep] = useState<0 | 1>(0); const [name, setName] = useState(""); const [audience, setAudience] = useState("customers"); const [idea, setIdea] = useState(""); const [loading, setLoading] = useState(false); const canContinue = name.trim().length > 0; const canCreate = idea.trim().length > 4; const handleCreate = async () => { if (!canCreate) return; setLoading(true); try { const res = await fetch("/api/projects/create", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ projectName: name.trim(), projectType: "web-app", slug: name.toLowerCase().replace(/[^a-z0-9]+/g, "-"), vision: idea.trim(), product: { name: name.trim() }, audience, creationMode: "build", sourceData: { idea: idea.trim(), audience }, }), }); if (!res.ok) { const err = await res.json(); toast.error(err.error || "Failed to create project"); return; } const data = await res.json(); onClose(); router.push(`/${workspace}/project/${data.projectId}/product`); } catch { toast.error("Something went wrong"); } finally { setLoading(false); } }; return (
setStep(0)} onClose={onClose} /> {step === 0 && ( <> Project name { if (e.key === "Enter" && canContinue) setStep(1); }} autoFocus /> setStep(1)} disabled={!canContinue}> Next → } /> )} {step === 1 && ( <> What do you want to build?