diff options
Diffstat (limited to 'lib/bidding/detail/table/bidding-detail-vendor-toolbar-actions.tsx')
| -rw-r--r-- | lib/bidding/detail/table/bidding-detail-vendor-toolbar-actions.tsx | 222 |
1 files changed, 79 insertions, 143 deletions
diff --git a/lib/bidding/detail/table/bidding-detail-vendor-toolbar-actions.tsx b/lib/bidding/detail/table/bidding-detail-vendor-toolbar-actions.tsx index 4d987739..e3db8861 100644 --- a/lib/bidding/detail/table/bidding-detail-vendor-toolbar-actions.tsx +++ b/lib/bidding/detail/table/bidding-detail-vendor-toolbar-actions.tsx @@ -4,22 +4,20 @@ import * as React from "react" import { useRouter } from "next/navigation" import { useTransition } from "react" import { Button } from "@/components/ui/button" -import { Plus, Send, RotateCcw, XCircle, Trophy, FileText, DollarSign } from "lucide-react" +import { Plus, Send, RotateCcw, XCircle, Trophy, FileText, DollarSign, RotateCw } from "lucide-react" import { registerBidding, markAsDisposal, createRebidding } from "@/lib/bidding/detail/service" import { sendBiddingBasicContracts, getSelectedVendorsForBidding } from "@/lib/bidding/pre-quote/service" +import { increaseRoundOrRebid } from "@/lib/bidding/service" import { BiddingDetailVendorCreateDialog } from "../../../../components/bidding/manage/bidding-detail-vendor-create-dialog" import { BiddingDocumentUploadDialog } from "./bidding-document-upload-dialog" -import { BiddingVendorPricesDialog } from "./bidding-vendor-prices-dialog" import { Bidding } from "@/db/schema" import { useToast } from "@/hooks/use-toast" -import { BiddingInvitationDialog } from "./bidding-invitation-dialog" interface BiddingDetailVendorToolbarActionsProps { biddingId: number bidding: Bidding userId: string - onOpenTargetPriceDialog: () => void onOpenAwardDialog: () => void onSuccess: () => void } @@ -28,7 +26,6 @@ export function BiddingDetailVendorToolbarActions({ biddingId, bidding, userId, - onOpenTargetPriceDialog, onOpenAwardDialog, onSuccess }: BiddingDetailVendorToolbarActionsProps) { @@ -75,52 +72,52 @@ export function BiddingDetailVendorToolbarActions({ setIsBiddingInvitationDialogOpen(true) } - const handleBiddingInvitationSend = async (data: any) => { - try { - // 1. 기본계약 발송 - const contractResult = await sendBiddingBasicContracts( - biddingId, - data.vendors, - data.generatedPdfs, - data.message - ) - - if (!contractResult.success) { - toast({ - title: '기본계약 발송 실패', - description: contractResult.error, - variant: 'destructive', - }) - return - } - - // 2. 입찰 등록 진행 - const registerResult = await registerBidding(bidding.id, userId) - - if (registerResult.success) { - toast({ - title: '본입찰 초대 완료', - description: '기본계약 발송 및 본입찰 초대가 완료되었습니다.', - }) - setIsBiddingInvitationDialogOpen(false) - router.refresh() - onSuccess() - } else { - toast({ - title: '오류', - description: registerResult.error, - variant: 'destructive', - }) - } - } catch (error) { - console.error('본입찰 초대 실패:', error) - toast({ - title: '오류', - description: '본입찰 초대에 실패했습니다.', - variant: 'destructive', - }) - } - } + // const handleBiddingInvitationSend = async (data: any) => { + // try { + // // 1. 기본계약 발송 + // const contractResult = await sendBiddingBasicContracts( + // biddingId, + // data.vendors, + // data.generatedPdfs, + // data.message + // ) + + // if (!contractResult.success) { + // toast({ + // title: '기본계약 발송 실패', + // description: contractResult.error, + // variant: 'destructive', + // }) + // return + // } + + // // 2. 입찰 등록 진행 + // const registerResult = await registerBidding(bidding.id, userId) + + // if (registerResult.success) { + // toast({ + // title: '본입찰 초대 완료', + // description: '기본계약 발송 및 본입찰 초대가 완료되었습니다.', + // }) + // setIsBiddingInvitationDialogOpen(false) + // router.refresh() + // onSuccess() + // } else { + // toast({ + // title: '오류', + // description: registerResult.error, + // variant: 'destructive', + // }) + // } + // } catch (error) { + // console.error('본입찰 초대 실패:', error) + // toast({ + // title: '오류', + // description: '본입찰 초대에 실패했습니다.', + // variant: 'destructive', + // }) + // } + // } // 선정된 업체들 조회 (서버 액션 함수 사용) const getSelectedVendors = async () => { @@ -158,21 +155,21 @@ export function BiddingDetailVendorToolbarActions({ }) } - const handleCreateRebidding = () => { + const handleRoundIncrease = () => { startTransition(async () => { - const result = await createRebidding(bidding.id, userId) + const result = await increaseRoundOrRebid(bidding.id, userId, 'round_increase') if (result.success) { toast({ - title: result.message, + title: "성공", description: result.message, }) router.refresh() onSuccess() } else { toast({ - title: result.error, - description: result.error, + title: "오류", + description: result.error || "차수증가 중 오류가 발생했습니다.", variant: 'destructive', }) } @@ -183,80 +180,47 @@ export function BiddingDetailVendorToolbarActions({ <> <div className="flex items-center gap-2"> {/* 상태별 액션 버튼 */} - {bidding.status !== 'bidding_closed' && bidding.status !== 'vendor_selected' && ( - <> - <Button - variant="default" - size="sm" - onClick={handleRegister} - disabled={isPending} - > - {/* 입찰등록 시점 재정의 필요*/} - <Send className="mr-2 h-4 w-4" /> - 입찰 등록 - </Button> - <Button - variant="destructive" - size="sm" - onClick={handleMarkAsDisposal} - disabled={isPending} - > - <XCircle className="mr-2 h-4 w-4" /> - 유찰 - </Button> - <Button - variant="default" - size="sm" - onClick={onOpenAwardDialog} - disabled={isPending} - > - <Trophy className="mr-2 h-4 w-4" /> - 낙찰 - </Button> - - - {bidding.status === 'bidding_disposal' && ( + {/* 차수증가: 입찰공고 또는 입찰 진행중 상태 */} + {(bidding.status === 'bidding_generated' || bidding.status === 'bidding_opened') && ( <Button variant="outline" size="sm" - onClick={handleCreateRebidding} + onClick={handleRoundIncrease} disabled={isPending} > - <RotateCcw className="mr-2 h-4 w-4" /> - 재입찰 + <RotateCw className="mr-2 h-4 w-4" /> + 차수증가 </Button> )} - {/* 구분선 */} - {(bidding.status === 'bidding_generated' || - bidding.status === 'bidding_disposal') && ( - <div className="h-4 w-px bg-border mx-1" /> - )} - - {/* 공통 관리 버튼들 */} - {/* <Button - variant="outline" - size="sm" - onClick={onOpenItemsDialog} - > - 품목 정보 - </Button> */} - + {/* 유찰/낙찰: 입찰 진행중 상태에서만 */} + {bidding.status === 'bidding_opened' && ( + <> <Button - variant="outline" + variant="destructive" size="sm" - onClick={onOpenTargetPriceDialog} + onClick={handleMarkAsDisposal} + disabled={isPending} > - 내정가 산정 + <XCircle className="mr-2 h-4 w-4" /> + 유찰 </Button> <Button - variant="outline" + variant="default" size="sm" - onClick={handleCreateVendor} + onClick={onOpenAwardDialog} + disabled={isPending} > - <Plus className="mr-2 h-4 w-4" /> - 업체 추가 + <Trophy className="mr-2 h-4 w-4" /> + 낙찰 </Button> + </> + )} + {/* 구분선 */} + {(bidding.status === 'bidding_generated' || + bidding.status === 'bidding_disposal') && ( + <div className="h-4 w-px bg-border mx-1" /> + )} <Button variant="outline" size="sm" @@ -265,16 +229,7 @@ export function BiddingDetailVendorToolbarActions({ <FileText className="mr-2 h-4 w-4" /> 입찰문서 등록 </Button> - <Button - variant="outline" - size="sm" - onClick={handleViewVendorPrices} - > - <DollarSign className="mr-2 h-4 w-4" /> - 입찰가 비교 - </Button> - </> - )} + </div> <BiddingDetailVendorCreateDialog @@ -295,25 +250,6 @@ export function BiddingDetailVendorToolbarActions({ onSuccess={onSuccess} /> - <BiddingVendorPricesDialog - open={isPricesDialogOpen} - onOpenChange={setIsPricesDialogOpen} - biddingId={biddingId} - biddingTitle={bidding.title} - budget={bidding.budget ? parseFloat(bidding.budget.toString()) : null} - targetPrice={bidding.targetPrice ? parseFloat(bidding.targetPrice.toString()) : null} - currency={bidding.currency || ''} - /> - - <BiddingInvitationDialog - open={isBiddingInvitationDialogOpen} - onOpenChange={setIsBiddingInvitationDialogOpen} - vendors={selectedVendors} - biddingId={biddingId} - biddingTitle={bidding.title || ''} - projectName={bidding.projectName || ''} - onSend={handleBiddingInvitationSend} - /> </> ) } |
