From ba8cd44a0ed2c613a5f2cee06bfc9bd0f61f21c7 Mon Sep 17 00:00:00 2001 From: dujinkim Date: Fri, 7 Nov 2025 08:39:04 +0000 Subject: (최겸) 입찰/견적 수정사항 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/general-contract-update-sheet.tsx | 401 +++++++++++++++++++++ 1 file changed, 401 insertions(+) create mode 100644 lib/general-contracts_old/main/general-contract-update-sheet.tsx (limited to 'lib/general-contracts_old/main/general-contract-update-sheet.tsx') diff --git a/lib/general-contracts_old/main/general-contract-update-sheet.tsx b/lib/general-contracts_old/main/general-contract-update-sheet.tsx new file mode 100644 index 00000000..54f4ae4e --- /dev/null +++ b/lib/general-contracts_old/main/general-contract-update-sheet.tsx @@ -0,0 +1,401 @@ +"use client" + +import * as React from "react" +import { useForm } from "react-hook-form" +import { zodResolver } from "@hookform/resolvers/zod" +import { z } from "zod" +import { toast } from "sonner" +import { Button } from "@/components/ui/button" +import { + Sheet, + SheetContent, + SheetDescription, + SheetFooter, + SheetHeader, + SheetTitle, +} from "@/components/ui/sheet" +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form" +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from "@/components/ui/select" +import { Input } from "@/components/ui/input" +import { Textarea } from "@/components/ui/textarea" +import { + GENERAL_CONTRACT_CATEGORIES, + GENERAL_CONTRACT_TYPES, + GENERAL_EXECUTION_METHODS, +} from "@/lib/general-contracts/types" +import { updateContract } from "../service" +import { GeneralContractListItem } from "./general-contracts-table-columns" +import { useSession } from "next-auth/react" +const updateContractSchema = z.object({ + category: z.string().min(1, "계약구분을 선택해주세요"), + type: z.string().min(1, "계약종류를 선택해주세요"), + executionMethod: z.string().min(1, "체결방식을 선택해주세요"), + name: z.string().min(1, "계약명을 입력해주세요"), + startDate: z.string().min(1, "계약시작일을 선택해주세요"), + endDate: z.string().min(1, "계약종료일을 선택해주세요"), + validityEndDate: z.string().min(1, "유효기간종료일을 선택해주세요"), + contractScope: z.string().min(1, "계약확정범위를 선택해주세요"), + notes: z.string().optional(), + linkedRfqOrItb: z.string().optional(), + linkedPoNumber: z.string().optional(), + linkedBidNumber: z.string().optional(), +}) + +type UpdateContractFormData = z.infer + +interface GeneralContractUpdateSheetProps { + contract: GeneralContractListItem | null + open: boolean + onOpenChange: (open: boolean) => void + onSuccess?: () => void +} + +export function GeneralContractUpdateSheet({ + contract, + open, + onOpenChange, + onSuccess, +}: GeneralContractUpdateSheetProps) { + const [isSubmitting, setIsSubmitting] = React.useState(false) + const session = useSession() + const userId = session.data?.user?.id ? Number(session.data.user.id) : null + const form = useForm({ + resolver: zodResolver(updateContractSchema), + defaultValues: { + category: "", + type: "", + executionMethod: "", + name: "", + startDate: "", + endDate: "", + validityEndDate: "", + contractScope: "", + notes: "", + linkedRfqOrItb: "", + linkedPoNumber: "", + linkedBidNumber: "", + }, + }) + + // 계약확정범위에 따른 품목정보 필드 비활성화 여부 + const watchedContractScope = form.watch("contractScope") + const isItemsDisabled = watchedContractScope === '단가' || watchedContractScope === '물량(실적)' + + // 계약 데이터가 변경될 때 폼 초기화 + React.useEffect(() => { + if (contract) { + console.log("Loading contract data:", contract) + const formData = { + category: contract.category || "", + type: contract.type || "", + executionMethod: contract.executionMethod || "", + name: contract.name || "", + startDate: contract.startDate || "", + endDate: contract.endDate || "", + validityEndDate: contract.validityEndDate || "", + contractScope: contract.contractScope || "", + notes: contract.notes || "", + linkedRfqOrItb: contract.linkedRfqOrItb || "", + linkedPoNumber: contract.linkedPoNumber || "", + linkedBidNumber: contract.linkedBidNumber || "", + } + console.log("Form data to reset:", formData) + form.reset(formData) + } + }, [contract, form]) + + const onSubmit = async (data: UpdateContractFormData) => { + if (!contract) return + + try { + setIsSubmitting(true) + + await updateContract(contract.id, { + category: data.category, + type: data.type, + executionMethod: data.executionMethod, + name: data.name, + startDate: data.startDate, + endDate: data.endDate, + validityEndDate: data.validityEndDate, + contractScope: data.contractScope, + notes: data.notes, + linkedRfqOrItb: data.linkedRfqOrItb, + linkedPoNumber: data.linkedPoNumber, + linkedBidNumber: data.linkedBidNumber, + vendorId: contract.vendorId, + lastUpdatedById: userId, + }) + + toast.success("계약 정보가 성공적으로 수정되었습니다.") + onOpenChange(false) + onSuccess?.() + } catch (error) { + console.error("Error updating contract:", error) + toast.error("계약 정보 수정 중 오류가 발생했습니다.") + } finally { + setIsSubmitting(false) + } + } + + return ( + + + + 계약 정보 수정 + + 계약의 기본 정보를 수정합니다. 변경사항은 즉시 저장됩니다. + + + +
+
+ +
+ {/* 계약구분 */} + ( + + 계약구분 * + + + + )} + /> + + {/* 계약종류 */} + ( + + 계약종류 * + + + + )} + /> + + {/* 체결방식 */} + ( + + 체결방식 * + + + + )} + /> + + {/* 계약명 */} + ( + + 계약명 * + + + + + + )} + /> + + {/* 계약시작일 */} + ( + + 계약시작일 * + + + + + + )} + /> + + {/* 계약종료일 */} + ( + + 계약종료일 * + + + + + + )} + /> + + {/* 유효기간종료일 */} + ( + + 유효기간종료일 * + + + + + + )} + /> + + {/* 계약확정범위 */} + ( + + 계약확정범위 * + + +

+ 해당 계약으로 확정되는 범위를 선택하세요. +

+
+ )} + /> + + {/* 비고 */} + ( + + 비고 + +