'use client' import * as React from 'react' import { BiddingCompany } from './bidding-pre-quote-vendor-columns' import { updatePreQuoteSelection } from '../service' import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from '@/components/ui/dialog' import { Button } from '@/components/ui/button' import { Badge } from '@/components/ui/badge' import { CheckCircle, XCircle, AlertCircle } from 'lucide-react' import { useToast } from '@/hooks/use-toast' import { useTransition } from 'react' interface BiddingPreQuoteSelectionDialogProps { open: boolean onOpenChange: (open: boolean) => void selectedCompanies: BiddingCompany[] onSuccess: () => void } export function BiddingPreQuoteSelectionDialog({ open, onOpenChange, selectedCompanies, onSuccess }: BiddingPreQuoteSelectionDialogProps) { const { toast } = useToast() const [isPending, startTransition] = useTransition() // 선택된 업체들의 현재 상태 분석 (선정만 가능) const unselectedCompanies = selectedCompanies.filter(c => !c.isPreQuoteSelected) const hasQuotationCompanies = selectedCompanies.filter(c => c.preQuoteAmount && Number(c.preQuoteAmount) > 0) const handleConfirm = () => { const companyIds = selectedCompanies.map(c => c.id) const isSelected = true // 항상 선정으로 고정 startTransition(async () => { const result = await updatePreQuoteSelection( companyIds, isSelected ) if (result.success) { toast({ title: '성공', description: result.message, }) onSuccess() onOpenChange(false) } else { toast({ title: '오류', description: result.error, variant: 'destructive', }) } }) } const getActionIcon = (isSelected: boolean) => { return isSelected ? : } return ( 본입찰 선정 상태 변경 선택된 {selectedCompanies.length}개 업체의 본입찰 선정 상태를 변경합니다.
{/* 견적 제출 여부 안내 */} {hasQuotationCompanies.length !== selectedCompanies.length && (
알림

사전견적을 제출하지 않은 업체도 포함되어 있습니다. 견적 미제출 업체도 본입찰에 참여시키시겠습니까?

)} {/* 업체 목록 */}

대상 업체 목록

{selectedCompanies.map((company) => (
{getActionIcon(company.isPreQuoteSelected)}
{company.companyName}
{company.companyCode}
{company.isPreQuoteSelected ? '현재 선정' : '현재 미선정'} {company.preQuoteAmount && Number(company.preQuoteAmount) > 0 ? ( 견적 제출 ) : ( 견적 미제출 )}
))}
{/* 결과 요약 */}
변경 결과

• {unselectedCompanies.length}개 업체가 본입찰 대상으로 선정됩니다.

{selectedCompanies.length > unselectedCompanies.length && (

• {selectedCompanies.length - unselectedCompanies.length}개 업체는 이미 선정 상태이므로 변경되지 않습니다.

)}
) }