"use client"; import { useState } from "react"; interface CreateModalProps { type: "initiative" | "todo" | "idea"; onClose: () => void; onComplete: () => void; } export function CreateModal({ type, onClose, onComplete }: CreateModalProps) { const [name, setName] = useState(""); const [title, setTitle] = useState(""); const [description, setDescription] = useState(""); const [goal, setGoal] = useState(""); const [priority, setPriority] = useState<"low" | "medium" | "high">("medium"); const [state, setState] = useState<"active" | "backlog">("backlog"); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); setError(null); try { let url: string; let payload: Record; if (type === "initiative") { url = "/api/initiatives"; payload = { name, title, goal, state, }; } else if (type === "todo") { url = "/api/todos"; payload = { name, title, description, priority, }; } else { url = "/api/ideas"; payload = { name, title, description, }; } const response = await fetch(url, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(payload), }); const result = await response.json(); if (result.success) { onComplete(); } else { setError(result.error || "Failed to create"); } } catch (err) { setError("Failed to create"); } finally { setLoading(false); } }; const typeLabels = { initiative: "Initiative", todo: "Todo", idea: "Idea", }; const typeColors = { initiative: "emerald", todo: "amber", idea: "violet", }; return (
{/* Header */}

Create New {typeLabels[type]}

{/* Form */}
{error && (
{error}
)} {/* Name field */}
setName(e.target.value)} placeholder="my-new-item" className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white placeholder-gray-400 focus:ring-2 focus:ring-blue-500 focus:border-transparent" required />
{/* Title field */}
setTitle(e.target.value)} placeholder="A descriptive title" className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white placeholder-gray-400 focus:ring-2 focus:ring-blue-500 focus:border-transparent" required />
{/* Initiative-specific fields */} {type === "initiative" && ( <>