import { useEffect, useState } from "react"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Loader2 } from "lucide-react"; import { toast } from "sonner"; import { trpc } from "@/lib/trpc"; interface RegisterProjectDialogProps { open: boolean; onOpenChange: (open: boolean) => void; } export function RegisterProjectDialog({ open, onOpenChange, }: RegisterProjectDialogProps) { const [name, setName] = useState(""); const [url, setUrl] = useState(""); const [defaultBranch, setDefaultBranch] = useState("main"); const [error, setError] = useState(null); const utils = trpc.useUtils(); const registerMutation = trpc.registerProject.useMutation({ onSuccess: () => { onOpenChange(false); toast.success("Project registered"); void utils.listProjects.invalidate(); }, onError: (err) => { if (err.data?.code === "INTERNAL_SERVER_ERROR") { setError("Failed to clone repository. Check the URL and try again."); } else { setError(err.message); } }, }); useEffect(() => { if (open) { setName(""); setUrl(""); setDefaultBranch("main"); setError(null); } }, [open]); function handleSubmit(e: React.FormEvent) { e.preventDefault(); setError(null); registerMutation.mutate({ name: name.trim(), url: url.trim(), defaultBranch: defaultBranch.trim() || undefined, }); } const canSubmit = name.trim().length > 0 && url.trim().length > 0 && !registerMutation.isPending; return ( Register Project Register a git repository as a project.
setName(e.target.value)} autoFocus />
setUrl(e.target.value)} />
setDefaultBranch(e.target.value)} />
{error &&

{error}

}
); }