From 1a2241c40e10193c5ff7008a7b7b36cc1d855d96 Mon Sep 17 00:00:00 2001 From: joonhoekim <26rote@gmail.com> Date: Tue, 25 Mar 2025 15:55:45 +0900 Subject: initial commit --- lib/tasks/table/update-task-sheet.tsx | 230 ++++++++++++++++++++++++++++++++++ 1 file changed, 230 insertions(+) create mode 100644 lib/tasks/table/update-task-sheet.tsx (limited to 'lib/tasks/table/update-task-sheet.tsx') diff --git a/lib/tasks/table/update-task-sheet.tsx b/lib/tasks/table/update-task-sheet.tsx new file mode 100644 index 00000000..1f4f5aa8 --- /dev/null +++ b/lib/tasks/table/update-task-sheet.tsx @@ -0,0 +1,230 @@ +"use client" + +import * as React from "react" +import { tasks, type Task } from "@/db/schema/tasks" +import { zodResolver } from "@hookform/resolvers/zod" +import { Loader } from "lucide-react" +import { useForm } from "react-hook-form" +import { toast } from "sonner" + +import { Button } from "@/components/ui/button" +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form" +import { + Select, + SelectContent, + SelectGroup, + SelectItem, + SelectTrigger, + SelectValue, +} from "@/components/ui/select" +import { + Sheet, + SheetClose, + SheetContent, + SheetDescription, + SheetFooter, + SheetHeader, + SheetTitle, +} from "@/components/ui/sheet" +import { Textarea } from "@/components/ui/textarea" + +import { modifiTask } from "@/lib//tasks/service" +import { updateTaskSchema, type UpdateTaskSchema } from "@/lib/tasks/validations" + +interface UpdateTaskSheetProps + extends React.ComponentPropsWithRef { + task: Task | null +} + +export function UpdateTaskSheet({ task, ...props }: UpdateTaskSheetProps) { + const [isUpdatePending, startUpdateTransition] = React.useTransition() + + const form = useForm({ + resolver: zodResolver(updateTaskSchema), + defaultValues: { + title: task?.title ?? "", + label: task?.label, + status: task?.status, + priority: task?.priority, + }, + }) + + function onSubmit(input: UpdateTaskSchema) { + startUpdateTransition(async () => { + if (!task) return + + const { error } = await modifiTask({ + id: task.id, + ...input, + }) + + if (error) { + toast.error(error) + return + } + + form.reset() + props.onOpenChange?.(false) + toast.success("Task updated") + }) + } + + return ( + + + + Update task + + Update the task details and save the changes + + +
+ + ( + + Title + +