"use client"; import { useState, useEffect } from "react"; import { Project, Task } from "@/types/models"; import { Button, buttonVariants } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog"; import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle, SheetTrigger, } from "@/components/ui/sheet"; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form"; import { useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; import * as z from "zod"; const taskSchema = z.object({ description: z.string().min(10, "Description must be at least 10 characters"), status: z.string().optional(), priority: z.string().optional(), dueDate: z.date().optional(), tags: z.array(z.string()).optional(), }); export default function Project({ params }: { params: { id: string } }) { const [project, setProject] = useState(); const [loading, setLoading] = useState(true); const [open, setOpen] = useState(false); const [task, setTask] = useState(); const form = useForm>({ resolver: zodResolver(taskSchema), defaultValues: { description: "", status: "", priority: "", dueDate: undefined, }, }); useEffect(() => { if (params.id) { fetch(`/api/projects/${params.id}`) .then((res) => { if (!res.ok) throw new Error("HTTP status " + res.status); return res.json(); }) .then((data) => { setProject(data); setLoading(false); }) .catch((err) => console.error("Failed to fetch project:", err)); } }, [params.id]); async function handleSubmit(values: z.infer) { try { const res = await fetch(`/api/projects/${params.id}/tasks`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(values), }); if (!res.ok) throw new Error("HTTP status " + res.status); const newTask = await res.json(); setProject((prevProject) => { if (!prevProject) return; const prevTasks = prevProject.tasks || []; return { ...prevProject, tasks: [...prevTasks, newTask], }; }); setOpen(false); } catch (err) { console.error("Failed to create task:", err); } } if (loading) return

Loading...

; if (!project) return

No project found.

; return (

{project.title}

{project.description}

Add Task Add Task
( Task Description )} /> ( Task Status )} /> ( Task Priority )} />

Tasks

{project.tasks?.map((task: Task) => (
console.log("hey")}> {task.description}
))}
Are you sure absolutely sure? This action cannot be undone. This will permanently delete your account and remove your data from our servers.
); }