"use client" import * as React from "react" import { OcrRow } from "@/db/schema" 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 { Input } from "@/components/ui/input" import { Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetTitle, } from "@/components/ui/sheet" import { modifyOcrRow } from "../service" import { updateOcrRowSchema, type UpdateOcrRowSchema } from "../validation" interface UpdateOcrRowSheetProps extends React.ComponentPropsWithRef { ocrRow: OcrRow | null } export function UpdateOcrRowSheet({ ocrRow, ...props }: UpdateOcrRowSheetProps) { const [isUpdatePending, startUpdateTransition] = React.useTransition() const form = useForm({ resolver: zodResolver(updateOcrRowSchema), defaultValues: { identificationNo: ocrRow?.identificationNo ?? "", tagNo: ocrRow?.tagNo ?? "", weldingDate: ocrRow?.weldingDate ?? "", jointType: ocrRow?.jointType ?? "", }, }) React.useEffect(() => { if (ocrRow) { form.reset({ identificationNo: ocrRow.identificationNo ?? "", tagNo: ocrRow.tagNo ?? "", weldingDate: ocrRow.weldingDate ?? "", jointType: ocrRow.jointType ?? "", }) } }, [ocrRow, form]) function onSubmit(input: UpdateOcrRowSchema) { startUpdateTransition(async () => { if (!ocrRow) return const { error } = await modifyOcrRow({ id: ocrRow.id, ...input, }) if (error) { toast.error(error) return } form.reset() props.onOpenChange?.(false) toast.success("OCR 행이 업데이트되었습니다") }) } return ( OCR 행 업데이트 OCR 행의 세부 정보를 수정하고 변경 사항을 저장하세요
( Identification No )} /> ( Tag No )} /> ( Welding Date )} /> ( Joint Type )} />
) }