"use client"; import { useState, type FormEvent } from "react"; import { Check, ChevronRight, GitBranch, Loader2, Terminal } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; type CreationResult = { name: string; path: string; gitInitialized: boolean; }; export function ProjectCreator({ projectsRoot }: { projectsRoot: string }) { const [name, setName] = useState(""); const [isCreating, setIsCreating] = useState(false); const [error, setError] = useState(""); const [createdProject, setCreatedProject] = useState(null); async function handleSubmit(event: FormEvent) { event.preventDefault(); setIsCreating(true); setError(""); setCreatedProject(null); try { const response = await fetch("/api/projects", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ name }), }); const data = await response.json(); if (!response.ok) { setError(data.error || "The project could not be created."); return; } setCreatedProject(data); setName(""); } catch { setError("Could not reach the local server. Try again."); } finally { setIsCreating(false); } } return (

New project

A directory, plus a Git repository.

01 / 01
setName(event.target.value)} placeholder="e.g. morning-star" autoComplete="off" autoFocus disabled={isCreating} aria-describedby="project-name-help" />

Letters, numbers, spaces, hyphens, and underscores.

Destination

{projectsRoot}/{name.trim() || "project-name"}

{error ? (

{error}

) : null} {createdProject ? (
Project created and Git initialized.

{createdProject.path}

) : null}
); }