blob: c06051910704c2d55236fd00737ea37738151fd8 (
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
85
86
87
88
89
90
91
92
93
94
95
96
97
|
"use client"
import * as React from "react"
import { type Table } from "@tanstack/react-table"
import { Download, Upload, Check } from "lucide-react"
import { toast } from "sonner"
import { exportTableToExcel } from "@/lib/export"
import { Button } from "@/components/ui/button"
import { Vendor } from "@/db/schema/vendors"
import { ApproveVendorsDialog } from "./approve-vendor-dialog"
import { RequestPQVendorsDialog } from "./request-vendor-pg-dialog"
import { SendVendorsDialog } from "./send-vendor-dialog"
interface VendorsTableToolbarActionsProps {
table: Table<Vendor>
}
export function VendorsTableToolbarActions({ table }: VendorsTableToolbarActionsProps) {
// 파일 input을 숨기고, 버튼 클릭 시 참조해 클릭하는 방식
const fileInputRef = React.useRef<HTMLInputElement>(null)
// 선택된 벤더 중 PENDING_REVIEW 상태인 벤더만 필터링
const pendingReviewVendors = React.useMemo(() => {
return table
.getFilteredSelectedRowModel()
.rows
.map(row => row.original)
.filter(vendor => vendor.status === "PENDING_REVIEW");
}, [table.getFilteredSelectedRowModel().rows]);
// 선택된 벤더 중 PENDING_REVIEW 상태인 벤더만 필터링
const inReviewVendors = React.useMemo(() => {
return table
.getFilteredSelectedRowModel()
.rows
.map(row => row.original)
.filter(vendor => vendor.status === "IN_REVIEW");
}, [table.getFilteredSelectedRowModel().rows]);
const approvedVendors = React.useMemo(() => {
return table
.getFilteredSelectedRowModel()
.rows
.map(row => row.original)
.filter(vendor => vendor.status === "APPROVED");
}, [table.getFilteredSelectedRowModel().rows]);
return (
<div className="flex items-center gap-2">
{/* 승인 다이얼로그: PENDING_REVIEW 상태인 벤더가 있을 때만 표시 */}
{pendingReviewVendors.length > 0 && (
<ApproveVendorsDialog
vendors={pendingReviewVendors}
onSuccess={() => table.toggleAllRowsSelected(false)}
/>
)}
{inReviewVendors.length > 0 && (
<RequestPQVendorsDialog
vendors={inReviewVendors}
onSuccess={() => table.toggleAllRowsSelected(false)}
/>
)}
{approvedVendors.length > 0 && (
<SendVendorsDialog
vendors={approvedVendors}
onSuccess={() => table.toggleAllRowsSelected(false)}
/>
)}
{/** 4) Export 버튼 */}
<Button
variant="outline"
size="sm"
onClick={() =>
exportTableToExcel(table, {
filename: "vendors",
excludeColumns: ["select", "actions"],
})
}
className="gap-2"
>
<Download className="size-4" aria-hidden="true" />
<span className="hidden sm:inline">Export</span>
</Button>
</div>
)
}
|