"use client"; import { useRef, useState } from "react"; import { useRouter } from "next/navigation"; import { toast } from "sonner"; import { FieldLabel, TextInput, PrimaryButton, type SetupProps } from "./setup-shared"; export function FreshIdeaSetup({ workspace, onClose }: SetupProps) { const router = useRouter(); const [name, setName] = useState(""); const [loading, setLoading] = useState(false); const nameRef = useRef(null); const canCreate = name.trim().length > 0; 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, "-"), product: { name: name.trim() }, creationMode: "fresh", sourceData: {}, }), }); 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}/overview`); } catch { toast.error("Something went wrong"); } finally { setLoading(false); } }; return (
New project
Project name { if (e.key === "Enter" && canCreate) handleCreate(); }} inputRef={nameRef} autoFocus /> Start →
); }