"use client" import * as React from "react" import { Button } from "@/components/ui/button" import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog" import { Label } from "@/components/ui/label" import { Textarea } from "@/components/ui/textarea" import { Switch } from "@/components/ui/switch" import { useToast } from "@/hooks/use-toast" import { updatePriceAdjustmentInfo } from "@/lib/bidding/detail/service" import { QuotationVendor } from "@/lib/bidding/detail/service" import { Loader2 } from "lucide-react" interface PriceAdjustmentDialogProps { open: boolean onOpenChange: (open: boolean) => void vendor: QuotationVendor | null onSuccess: () => void } export function PriceAdjustmentDialog({ open, onOpenChange, vendor, onSuccess, }: PriceAdjustmentDialogProps) { const { toast } = useToast() const [isSubmitting, setIsSubmitting] = React.useState(false) // 폼 상태 const [shiPriceAdjustmentApplied, setSHIPriceAdjustmentApplied] = React.useState(null) const [priceAdjustmentNote, setPriceAdjustmentNote] = React.useState("") const [hasChemicalSubstance, setHasChemicalSubstance] = React.useState(null) // 다이얼로그가 열릴 때 벤더 정보로 폼 초기화 React.useEffect(() => { if (open && vendor) { setSHIPriceAdjustmentApplied(vendor.shiPriceAdjustmentApplied ?? null) setPriceAdjustmentNote(vendor.priceAdjustmentNote || "") setHasChemicalSubstance(vendor.hasChemicalSubstance ?? null) } }, [open, vendor]) const handleSubmit = async () => { if (!vendor) return setIsSubmitting(true) try { const result = await updatePriceAdjustmentInfo({ biddingCompanyId: vendor.id, shiPriceAdjustmentApplied, priceAdjustmentNote: priceAdjustmentNote || null, hasChemicalSubstance, }) if (result.success) { toast({ title: "저장 완료", description: "연동제 정보가 저장되었습니다.", }) onOpenChange(false) onSuccess() } else { toast({ title: "오류", description: result.error || "저장 중 오류가 발생했습니다.", variant: "destructive", }) } } catch (error) { console.error("연동제 정보 저장 오류:", error) toast({ title: "오류", description: "저장 중 오류가 발생했습니다.", variant: "destructive", }) } finally { setIsSubmitting(false) } } if (!vendor) return null return ( 연동제 적용 설정 {vendor.vendorName} 업체의 연동제 적용 여부를 설정합니다.
{/* 업체가 제출한 연동제 요청 여부 (읽기 전용) */} {/*

업체가 제출한 연동제 적용 요청 여부입니다.

{vendor.isPriceAdjustmentApplicableQuestion === null ? '미정' : vendor.isPriceAdjustmentApplicableQuestion ? '예' : '아니오'}
*/} {/* SHI 연동제 적용여부 */}

해당 업체에 연동제를 적용할지 결정합니다.

미적용 setSHIPriceAdjustmentApplied(checked)} /> 적용
{/* 연동제 Note */}