diff options
Diffstat (limited to 'lib/rfq-last/vendor/batch-update-conditions-dialog.tsx')
| -rw-r--r-- | lib/rfq-last/vendor/batch-update-conditions-dialog.tsx | 69 |
1 files changed, 59 insertions, 10 deletions
diff --git a/lib/rfq-last/vendor/batch-update-conditions-dialog.tsx b/lib/rfq-last/vendor/batch-update-conditions-dialog.tsx index 7eae48db..70d5569f 100644 --- a/lib/rfq-last/vendor/batch-update-conditions-dialog.tsx +++ b/lib/rfq-last/vendor/batch-update-conditions-dialog.tsx @@ -44,7 +44,7 @@ import { format } from "date-fns"; import { ko } from "date-fns/locale"; import { cn } from "@/lib/utils"; import { toast } from "sonner"; -import { updateVendorConditionsBatch } from "../service"; +import { updateVendorConditionsBatch, getVendorConditions } from "../service"; import { Badge } from "@/components/ui/badge"; import { TAX_CONDITIONS } from "@/lib/tax-conditions/types"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; @@ -72,8 +72,8 @@ interface BatchUpdateConditionsDialogProps { } // 타입 정의 -interface SelectOption { - id: number; +type SelectOption = { + id?: number; code: string; description: string; } @@ -169,7 +169,7 @@ export function BatchUpdateConditionsDialog({ setIncotermsLoading(true); try { const data = await getIncotermsForSelection(); - setIncoterms(data); + setIncoterms(data as unknown as SelectOption[]); } catch (error) { console.error("Failed to load incoterms:", error); toast.error("Incoterms 목록을 불러오는데 실패했습니다."); @@ -182,7 +182,7 @@ export function BatchUpdateConditionsDialog({ setPaymentTermsLoading(true); try { const data = await getPaymentTermsForSelection(); - setPaymentTerms(data); + setPaymentTerms(data as unknown as SelectOption[]); } catch (error) { console.error("Failed to load payment terms:", error); toast.error("결제조건 목록을 불러오는데 실패했습니다."); @@ -195,7 +195,7 @@ export function BatchUpdateConditionsDialog({ setShippingLoading(true); try { const data = await getPlaceOfShippingForSelection(); - setShippingPlaces(data); + setShippingPlaces(data as unknown as SelectOption[]); } catch (error) { console.error("Failed to load shipping places:", error); toast.error("선적지 목록을 불러오는데 실패했습니다."); @@ -208,7 +208,7 @@ export function BatchUpdateConditionsDialog({ setDestinationLoading(true); try { const data = await getPlaceOfDestinationForSelection(); - setDestinationPlaces(data); + setDestinationPlaces(data as unknown as SelectOption[]); } catch (error) { console.error("Failed to load destination places:", error); toast.error("도착지 목록을 불러오는데 실패했습니다."); @@ -217,6 +217,33 @@ export function BatchUpdateConditionsDialog({ } }, []); + // 벤더별 조건 로드 함수 + const loadVendorConditions = React.useCallback(async (vendorId: number) => { + try { + const conditions = await getVendorConditions(rfqId, vendorId); + // 가져온 조건으로 폼 초기화 + form.reset({ + currency: conditions.currency || "", + paymentTermsCode: conditions.paymentTermsCode || "", + incotermsCode: conditions.incotermsCode || "", + incotermsDetail: conditions.incotermsDetail || "", + deliveryDate: conditions.deliveryDate || undefined, + contractDuration: conditions.contractDuration || "", + taxCode: conditions.taxCode || "", + placeOfShipping: conditions.placeOfShipping || "", + placeOfDestination: conditions.placeOfDestination || "", + materialPriceRelatedYn: conditions.materialPriceRelatedYn || false, + sparepartYn: conditions.sparepartYn || false, + firstYn: conditions.firstYn || false, + firstDescription: conditions.firstDescription || "", + sparepartDescription: conditions.sparepartDescription || "", + }); + } catch (error) { + console.error("Failed to load vendor conditions:", error); + toast.error("벤더 조건을 불러오는데 실패했습니다."); + } + }, [rfqId, form]); + // 초기 데이터 로드 React.useEffect(() => { if (open) { @@ -224,13 +251,35 @@ export function BatchUpdateConditionsDialog({ loadPaymentTerms(); loadShippingPlaces(); loadDestinationPlaces(); + + // 선택된 벤더가 1개일 때만 해당 벤더의 조건을 가져옴 + if (selectedVendors.length === 1) { + loadVendorConditions(selectedVendors[0].id); + } } - }, [open, loadIncoterms, loadPaymentTerms, loadShippingPlaces, loadDestinationPlaces]); + }, [open, loadIncoterms, loadPaymentTerms, loadShippingPlaces, loadDestinationPlaces, selectedVendors, loadVendorConditions]); // 다이얼로그 닫힐 때 초기화 React.useEffect(() => { if (!open) { - form.reset(); + // 선택된 벤더가 2개 이상이거나 없다면 기본값으로 초기화 + if (selectedVendors.length !== 1) { + form.reset({ + currency: "", + paymentTermsCode: "", + incotermsCode: "", + incotermsDetail: "", + contractDuration: "", + taxCode: "", + placeOfShipping: "", + placeOfDestination: "", + materialPriceRelatedYn: false, + sparepartYn: false, + firstYn: false, + firstDescription: "", + sparepartDescription: "", + }); + } setFieldsToUpdate({ currency: false, paymentTermsCode: false, @@ -244,7 +293,7 @@ export function BatchUpdateConditionsDialog({ first: false, }); } - }, [open, form]); + }, [open, form, selectedVendors]); // 제출 처리 const onSubmit = async (data: FormValues) => { |
