blob: abb34f856cda58037e32dfa851870b62e30cec2b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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<MatchedVendorRow>
rfqId: number
}
export function VendorsTableToolbarActions({ table, rfqId }: VendorsTableToolbarActionsProps) {
const { toast } = useToast()
const fileInputRef = React.useRef<HTMLInputElement>(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 (
<div className="flex items-center gap-2">
{selectedRows.length > 0 && (
<>
{showInviteDialog ? (
<InviteVendorsDialog
vendors={eligibleVendors}
rfqId={rfqId}
onSuccess={() => table.toggleAllRowsSelected(false)}
onOpenChange={(open) => {
// 다이얼로그가 열릴 때만 경고 표시
if (open && ineligibleCount > 0) {
handleInviteClick()
}
}}
/>
) : (
<Button
variant="default"
size="sm"
disabled={true}
title="선택된 벤더 중 초대 가능한 벤더가 없습니다"
>
초대 불가
</Button>
)}
</>
)}
<AddVendorDialog rfqId={rfqId} />
</div>
)
}
|