From 1a2241c40e10193c5ff7008a7b7b36cc1d855d96 Mon Sep 17 00:00:00 2001 From: joonhoekim <26rote@gmail.com> Date: Tue, 25 Mar 2025 15:55:45 +0900 Subject: initial commit --- .../vendor-table/vendors-table-toolbar-actions.tsx | 84 ++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 lib/rfqs/vendor-table/vendors-table-toolbar-actions.tsx (limited to 'lib/rfqs/vendor-table/vendors-table-toolbar-actions.tsx') diff --git a/lib/rfqs/vendor-table/vendors-table-toolbar-actions.tsx b/lib/rfqs/vendor-table/vendors-table-toolbar-actions.tsx new file mode 100644 index 00000000..abb34f85 --- /dev/null +++ b/lib/rfqs/vendor-table/vendors-table-toolbar-actions.tsx @@ -0,0 +1,84 @@ +"use client" + +import * as React from "react" +import { type Table } from "@tanstack/react-table" + +import { MatchedVendorRow } from "@/config/vendorRfbColumnsConfig" +import { InviteVendorsDialog } from "./invite-vendors-dialog" +import { AddVendorDialog } from "./add-vendor-dialog" +import { Button } from "@/components/ui/button" +import { useToast } from "@/hooks/use-toast" + +interface VendorsTableToolbarActionsProps { + table: Table + rfqId: number +} + +export function VendorsTableToolbarActions({ table, rfqId }: VendorsTableToolbarActionsProps) { + const { toast } = useToast() + const fileInputRef = React.useRef(null) + + // 선택된 모든 행 + const selectedRows = table.getFilteredSelectedRowModel().rows + + // 조건에 맞는 벤더만 필터링 + const eligibleVendors = React.useMemo(() => { + return selectedRows + .map(row => row.original) + .filter(vendor => !vendor.rfqVendorStatus || vendor.rfqVendorStatus === "INVITED") + }, [selectedRows]) + + // 조건에 맞지 않는 벤더 수 + const ineligibleCount = selectedRows.length - eligibleVendors.length + + function handleImportClick() { + fileInputRef.current?.click() + } + + function handleInviteClick() { + // 조건에 맞지 않는 벤더가 있다면 토스트 메시지 표시 + if (ineligibleCount > 0) { + toast({ + title: "일부 벤더만 초대됩니다", + description: `선택한 ${selectedRows.length}개 중 ${eligibleVendors.length}개만 초대 가능합니다. 나머지 ${ineligibleCount}개는 초대 불가능한 상태입니다.`, + // variant: "warning", + }) + } + } + + // 다이얼로그 표시 여부 - 적합한 벤더가 1개 이상 있으면 표시 + const showInviteDialog = eligibleVendors.length > 0 + + return ( +
+ {selectedRows.length > 0 && ( + <> + {showInviteDialog ? ( + table.toggleAllRowsSelected(false)} + onOpenChange={(open) => { + // 다이얼로그가 열릴 때만 경고 표시 + if (open && ineligibleCount > 0) { + handleInviteClick() + } + }} + /> + ) : ( + + )} + + )} + + +
+ ) +} \ No newline at end of file -- cgit v1.2.3