diff --git a/src/app/(dashboard)/tasks/components/add-task-modal.tsx b/src/app/(dashboard)/tasks/components/add-task-modal.tsx deleted file mode 100644 index 940b4f5..0000000 --- a/src/app/(dashboard)/tasks/components/add-task-modal.tsx +++ /dev/null @@ -1,256 +0,0 @@ -"use client" - -import { useState } from "react" -import { Plus } from "lucide-react" -import { z } from "zod" - -import { Button } from "@/components/ui/button" -import { - Dialog, - DialogContent, - DialogDescription, - DialogHeader, - DialogTitle, - DialogTrigger, -} from "@/components/ui/dialog" -import { Input } from "@/components/ui/input" -import { Label } from "@/components/ui/label" -import { Textarea } from "@/components/ui/textarea" -import { - Select, - SelectContent, - SelectItem, - SelectTrigger, - SelectValue, -} from "@/components/ui/select" - -import { priorities, statuses, categories } from "../data/data" -import type { Task } from "../data/schema" - -// Extended task schema for the form -const taskFormSchema = z.object({ - id: z.string(), - title: z.string().min(1, "Title is required"), - description: z.string().optional(), - status: z.string(), - category: z.string(), - priority: z.string(), -}) - -type TaskFormData = z.infer - -interface AddTaskModalProps { - onAddTask?: (task: Task) => void - trigger?: React.ReactNode -} - -export function AddTaskModal({ onAddTask, trigger }: AddTaskModalProps) { - const [open, setOpen] = useState(false) - const [formData, setFormData] = useState({ - id: "", - title: "", - description: "", - status: "todo", - category: "feature", - priority: "normal", - }) - const [errors, setErrors] = useState>({}) - - // Generate unique task ID - const generateTaskId = () => { - const prefix = "TASK" - const number = Math.floor(Math.random() * 9999) + 1000 - return `${prefix}-${number}` - } - - const handleSubmit = (e: React.FormEvent) => { - e.preventDefault() - - try { - // Validate form data - const validatedData = taskFormSchema.parse({ - ...formData, - id: generateTaskId(), - }) - - // Create the task - const newTask: Task = { - id: validatedData.id, - title: validatedData.title, - status: validatedData.status, - category: validatedData.category, - priority: validatedData.priority, - } - - onAddTask?.(newTask) - - // Reset form and close modal - setFormData({ - id: "", - title: "", - description: "", - status: "todo", - category: "feature", - priority: "normal", - }) - setErrors({}) - setOpen(false) - } catch (error) { - if (error instanceof z.ZodError) { - const newErrors: Record = {} - error.issues.forEach((issue) => { - if (issue.path[0]) { - newErrors[issue.path[0] as string] = issue.message - } - }) - setErrors(newErrors) - } - } - } - - const handleCancel = () => { - setFormData({ - id: "", - title: "", - description: "", - status: "todo", - category: "feature", - priority: "normal", - }) - setErrors({}) - setOpen(false) - } - - return ( - - - {trigger || ( - - )} - - - - Add New Task - - Create a new task to track work and progress. Fill in the details below. - - - -
- {/* Task Title */} -
- - setFormData(prev => ({ ...prev, title: e.target.value }))} - className={errors.title ? "border-red-500" : ""} - /> - {errors.title && ( -

{errors.title}

- )} -
- - {/* Task Description */} -
- -