"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { toast } from "sonner"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Textarea } from "@/components/ui/textarea"; import { createProject } from "@/app/(frontend)/projects/actions"; interface CreateProjectDialogProps { readonly open: boolean; readonly onOpenChange: (open: boolean) => void; } export function CreateProjectDialog({ open, onOpenChange }: CreateProjectDialogProps) { const router = useRouter(); const [name, setName] = useState(""); const [key, setKey] = useState(""); const [description, setDescription] = useState(""); const [pending, setPending] = useState(false); const [error, setError] = useState(null); function reset() { setName(""); setKey(""); setDescription(""); setPending(false); setError(null); } async function handleSubmit() { const trimmedName = name.trim(); const trimmedKey = key.trim().toUpperCase(); if (!trimmedName) { setError("Project name is required."); return; } if (!trimmedKey) { setError("Project key is required."); return; } setPending(true); setError(null); try { const result = await createProject({ name: trimmedName, key: trimmedKey, description: description.trim(), }); if (!result.success) { setError(result.error ?? "Could not create the project."); setPending(false); return; } onOpenChange(false); reset(); toast.success("Project created"); router.refresh(); } catch (caught) { setError(caught instanceof Error ? caught.message : "Could not create the project."); setPending(false); } } return ( { onOpenChange(nextOpen); if (!nextOpen) reset(); }} > Create project Set up a project space for tickets, sprints, and releases.
{ event.preventDefault(); void handleSubmit(); }} >
setName(event.target.value)} disabled={pending} />
setKey(event.target.value.toUpperCase().slice(0, 10))} disabled={pending} className="font-mono uppercase" />

Up to 10 characters. Keys are stored in uppercase.