"use client" import * as React from "react" import { useForm } from "react-hook-form" import { zodResolver } from "@hookform/resolvers/zod" import * as z from "zod" import { Button } from "@/components/ui/button" import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog" import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form" import { Input } from "@/components/ui/input" import { Textarea } from "@/components/ui/textarea" import { Calendar } from "@/components/ui/calendar" import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover" import { CalendarIcon } from "lucide-react" import { format } from "date-fns" import { cn } from "@/lib/utils" import { toast } from "sonner" import { PcrPoData } from "@/lib/pcr/types" import { createPcrPrAction } from "@/lib/pcr/actions" const pcrPrSchema = z.object({ materialNumber: z.string().min(1, "자재번호는 필수입니다"), materialDetails: z.string().optional(), quantityBefore: z.number().optional(), quantityAfter: z.number().optional(), weightBefore: z.number().optional(), weightAfter: z.number().optional(), subcontractorWeightBefore: z.number().optional(), subcontractorWeightAfter: z.number().optional(), supplierWeightBefore: z.number().optional(), supplierWeightAfter: z.number().optional(), specDrawingBefore: z.string().optional(), specDrawingAfter: z.string().optional(), initialPoContractDate: z.date().optional(), specChangeDate: z.date().optional(), poContractModifiedDate: z.date().optional(), confirmationDate: z.date().optional(), designManager: z.string().optional(), }) type PcrPrFormData = z.infer interface CreatePcrPrDialogProps { open: boolean onOpenChange: (open: boolean) => void selectedPcrPo: PcrPoData | null onSuccess: () => void } export function CreatePcrPrDialog({ open, onOpenChange, selectedPcrPo, onSuccess, }: CreatePcrPrDialogProps) { const [isSubmitting, setIsSubmitting] = React.useState(false) const form = useForm({ resolver: zodResolver(pcrPrSchema), defaultValues: { materialNumber: "", materialDetails: "", quantityBefore: undefined, quantityAfter: undefined, weightBefore: undefined, weightAfter: undefined, subcontractorWeightBefore: undefined, subcontractorWeightAfter: undefined, supplierWeightBefore: undefined, supplierWeightAfter: undefined, specDrawingBefore: "", specDrawingAfter: "", initialPoContractDate: undefined, specChangeDate: undefined, poContractModifiedDate: undefined, confirmationDate: undefined, designManager: "", }, }) const onSubmit = async (data: PcrPrFormData) => { if (!selectedPcrPo) { toast.error("선택된 PCR_PO가 없습니다") return } setIsSubmitting(true) try { const result = await createPcrPrAction({ ...data, poContractNumber: selectedPcrPo.poContractNumber, }) if (result.success) { toast.success("PCR_PR이 성공적으로 생성되었습니다") form.reset() onOpenChange(false) onSuccess() } else { toast.error(result.error || "PCR_PR 생성에 실패했습니다") } } catch (error) { console.error("PCR_PR 생성 오류:", error) toast.error("PCR_PR 생성 중 오류가 발생했습니다") } finally { setIsSubmitting(false) } } return ( PCR_PR 생성 PO/계약번호: {selectedPcrPo?.poContractNumber}
{/* 기본 정보 섹션 */}
( 자재번호 * )} /> ( 설계 담당자 )} />
( 자재내역