diff --git a/src/app/(app)/control/new-from-scratch/page.tsx b/src/app/(app)/control/new-from-scratch/page.tsx new file mode 100644 index 000000000..0eb15a1cb --- /dev/null +++ b/src/app/(app)/control/new-from-scratch/page.tsx @@ -0,0 +1,283 @@ +"use client"; + +// "Start a new project from scratch" without local runtime. +// Creates a brand new GitHub repo + FleetCrown project record in one shot. +// After, the user can `git clone` it on any machine — no Fleet Runner needed. +// +// Companion to BootstrapModal which does the full local stack scaffold but +// only works when the local daemon is running. + +import { useState } from "react"; +import { useRouter } from "next/navigation"; +import Link from "next/link"; +import { ArrowLeft, Loader2, GitBranch, Check, Copy } from "lucide-react"; +import { PageLayout } from "@/components/ui/page-layout"; + +type CreateResponse = { + ok: boolean; + project?: { id: string; name: string }; + repo?: { + name: string; + full_name: string; + gitUrl: string; + sshUrl: string; + cloneUrl: string; + private: boolean; + }; + cloneCmd?: string; + cloneHttpsCmd?: string; + error?: string; + detail?: string; + hasGithub?: boolean; +}; + +export default function NewFromScratchPage() { + const router = useRouter(); + const [name, setName] = useState(""); + const [description, setDescription] = useState(""); + const [visibility, setVisibility] = useState<"private" | "public">("private"); + const [submitting, setSubmitting] = useState(false); + const [result, setResult] = useState(null); + const [error, setError] = useState(""); + const [copied, setCopied] = useState<"ssh" | "https" | null>(null); + + async function handleSubmit(e: React.FormEvent) { + e.preventDefault(); + if (!name.trim()) return; + setSubmitting(true); + setError(""); + try { + const res = await fetch("/api/projects/create-with-github", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + name: name.trim(), + description: description.trim() || undefined, + visibility, + init_readme: true, + }), + }); + const body = (await res.json()) as CreateResponse; + if (!res.ok || !body.ok) { + const msg = body.error + ? body.detail + ? `${body.error} — ${body.detail}` + : body.error + : `Failed (HTTP ${res.status})`; + setError(msg); + if (body.hasGithub === false) { + // No GitHub linked — surface a path to connect. + setError(`${msg} Go to /control/import to connect GitHub first.`); + } + setSubmitting(false); + return; + } + setResult(body); + } catch (e) { + setError(e instanceof Error ? e.message : "Network error"); + setSubmitting(false); + } + } + + async function copy(text: string, kind: "ssh" | "https") { + try { + await navigator.clipboard.writeText(text); + setCopied(kind); + setTimeout(() => setCopied(null), 1500); + } catch { + // ignore + } + } + + // ── Result view ───────────────────────────────────────────────────────── + + if (result?.ok && result.repo && result.project) { + return ( + +
+
+ + + Back to Control + +
+ +
+
+

{result.project.name}

+

+ GitHub repo created ({result.repo.private ? "private" : "public"}) and registered in FleetCrown. +

+
+ +
+
+ + Repo +
+ + {result.repo.gitUrl} + +
+ +
+
Clone to your machine
+
+
+                  {result.cloneCmd}
+                
+ +
+
+ HTTPS clone (no SSH key required) +
+
+                    {result.cloneHttpsCmd}
+                  
+ +
+
+
+ +
+ + +
+
+
+
+ ); + } + + // ── Form view ─────────────────────────────────────────────────────────── + + return ( + +
+
+ + + Back to Control + +
+ +
+
+

Start fresh — GitHub repo + FleetCrown project

+

+ Creates a brand-new GitHub repo (with README) and registers it as a FleetCrown project. + No local runtime needed — clone it to your machine when you're ready. +

+
+ + {error && ( +
{error}
+ )} + +
+
+ + setName(e.target.value)} + placeholder="catsitting-startup" + autoFocus + required + maxLength={80} + className="ui-input w-full" + /> +

+ Used as both the GitHub repo name (lowercase, hyphens) and the FleetCrown project display name. +

+
+ +
+ +