diff --git a/src/app/api/task-notes/route.js b/src/app/api/task-notes/route.js new file mode 100644 index 0000000..8631073 --- /dev/null +++ b/src/app/api/task-notes/route.js @@ -0,0 +1,73 @@ +import { + getNotesByTaskId, + addNoteToTask, + deleteNote, +} from "@/lib/queries/notes"; +import { NextResponse } from "next/server"; + +// GET: Get notes for a specific task +export async function GET(req) { + const { searchParams } = new URL(req.url); + const taskId = searchParams.get("task_id"); + + if (!taskId) { + return NextResponse.json({ error: "task_id is required" }, { status: 400 }); + } + try { + const notes = getNotesByTaskId(taskId); + return NextResponse.json(notes); + } catch (error) { + console.error("Error fetching task notes:", error); + return NextResponse.json( + { error: "Failed to fetch task notes" }, + { status: 500 } + ); + } +} + +// POST: Add a note to a task +export async function POST(req) { + try { + const { task_id, note } = await req.json(); + + if (!task_id || !note) { + return NextResponse.json( + { error: "task_id and note are required" }, + { status: 400 } + ); + } + + addNoteToTask(task_id, note); + return NextResponse.json({ success: true }); + } catch (error) { + console.error("Error adding task note:", error); + return NextResponse.json( + { error: "Failed to add task note" }, + { status: 500 } + ); + } +} + +// DELETE: Delete a note +export async function DELETE(req) { + try { + const { searchParams } = new URL(req.url); + const noteId = searchParams.get("note_id"); + + if (!noteId) { + return NextResponse.json( + { error: "note_id is required" }, + { status: 400 } + ); + } + + deleteNote(noteId); + return NextResponse.json({ success: true }); + } catch (error) { + console.error("Error deleting note:", error); + return NextResponse.json( + { error: "Failed to delete note" }, + { status: 500 } + ); + } +} diff --git a/src/app/projects/[id]/edit/page.js b/src/app/projects/[id]/edit/page.js index d23bc06..adc6680 100644 --- a/src/app/projects/[id]/edit/page.js +++ b/src/app/projects/[id]/edit/page.js @@ -1,7 +1,8 @@ import ProjectForm from "@/components/ProjectForm"; export default async function EditProjectPage({ params }) { - const res = await fetch(`http://localhost:3000/api/projects/${params.id}`, { + const { id } = await params; + const res = await fetch(`http://localhost:3000/api/projects/${id}`, { cache: "no-store", }); const project = await res.json(); diff --git a/src/app/projects/[id]/page.js b/src/app/projects/[id]/page.js index 7674af4..7f3f2fe 100644 --- a/src/app/projects/[id]/page.js +++ b/src/app/projects/[id]/page.js @@ -13,8 +13,9 @@ import PageContainer from "@/components/ui/PageContainer"; import PageHeader from "@/components/ui/PageHeader"; export default async function ProjectViewPage({ params }) { - const project = getProjectWithContract(params.id); - const notes = getNotesForProject(params.id); + const { id } = await params; + const project = getProjectWithContract(id); + const notes = getNotesForProject(id); const daysRemaining = differenceInCalendarDays( parseISO(project.finish_date), new Date() @@ -70,8 +71,8 @@ export default async function ProjectViewPage({ params }) { Back to Projects - - + {" "} + @@ -142,7 +143,6 @@ export default async function ProjectViewPage({ params }) { )} -

@@ -175,10 +175,10 @@ export default async function ProjectViewPage({ params }) {

{project.investor}

- + {" "} - + @@ -186,7 +186,7 @@ export default async function ProjectViewPage({ params }) {
- +
{notes.length === 0 ? (
diff --git a/src/app/tasks/templates/[id]/edit/page.js b/src/app/tasks/templates/[id]/edit/page.js index 3fa63e6..d357906 100644 --- a/src/app/tasks/templates/[id]/edit/page.js +++ b/src/app/tasks/templates/[id]/edit/page.js @@ -6,10 +6,11 @@ import Button from "@/components/ui/Button"; import TaskTemplateForm from "@/components/TaskTemplateForm"; export default async function EditTaskTemplatePage({ params }) { + const { id } = await params; // Fetch the task template const template = db .prepare("SELECT * FROM tasks WHERE task_id = ? AND is_standard = 1") - .get(params.id); + .get(id); if (!template) { notFound(); diff --git a/src/components/ProjectTaskForm.js b/src/components/ProjectTaskForm.js index 01fc409..434ea2a 100644 --- a/src/components/ProjectTaskForm.js +++ b/src/components/ProjectTaskForm.js @@ -10,6 +10,7 @@ export default function ProjectTaskForm({ projectId, onTaskAdded }) { const [selectedTemplate, setSelectedTemplate] = useState(""); const [customTaskName, setCustomTaskName] = useState(""); const [customMaxWaitDays, setCustomMaxWaitDays] = useState(""); + const [customDescription, setCustomDescription] = useState(""); const [priority, setPriority] = useState("normal"); const [isSubmitting, setIsSubmitting] = useState(false); @@ -40,6 +41,7 @@ export default function ProjectTaskForm({ projectId, onTaskAdded }) { } else { requestData.custom_task_name = customTaskName.trim(); requestData.custom_max_wait_days = parseInt(customMaxWaitDays) || 0; + requestData.custom_description = customDescription.trim(); } const res = await fetch("/api/project-tasks", { @@ -47,12 +49,12 @@ export default function ProjectTaskForm({ projectId, onTaskAdded }) { headers: { "Content-Type": "application/json" }, body: JSON.stringify(requestData), }); - if (res.ok) { // Reset form setSelectedTemplate(""); setCustomTaskName(""); setCustomMaxWaitDays(""); + setCustomDescription(""); setPriority("normal"); if (onTaskAdded) onTaskAdded(); } else { @@ -141,6 +143,18 @@ export default function ProjectTaskForm({ projectId, onTaskAdded }) { min="0" />
+
+ +