// Client component directive for browser interactive pop-up modal 'use client'; // Import state hook from React import { useState } from 'react'; // Import Task and TaskStatus types import { Task, TaskStatus } from '../types'; // Import the update server action function import { updateTaskAction } from '../actions'; // Props needed for the modal: the task to edit, and an onClose function to close the pop-up interface TaskEditModalProps { task: Task; onClose: () => void; } export default function TaskEditModal({ task, onClose }: TaskEditModalProps) { // State to track if saving is in progress (shows 'Saving...' on button) const [isSaving, setIsSaving] = useState(false); // Form submit handler to update task details const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); // Stop normal page refresh setIsSaving(true); const formData = new FormData(e.currentTarget); // Get data entered into form inputs try { // Call the server action to update SQLite database using formData directly await updateTaskAction(task.id, formData); onClose(); // Close modal upon successful update } catch (err) { alert('Failed to update task'); } finally { setIsSaving(false); } }; return ( // Modal Overlay: dark background overlay that covers the entire screen
{/* Modal Dialog Box */}
{/* Modal Header */}

Edit Task #{task.id}

{/* Close button (X) */}
{/* Edit Form */}
{/* Title input (pre-populated with task.title) */}
{/* Topic input */}
{/* Due date picker */}
{/* Status dropdown */}
{/* Description text area */}
{/* Modal Action buttons */}
); }