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
|
"use client"
import * as React from "react"
import { type Table } from "@tanstack/react-table"
import { Download, FileDown, Upload } from "lucide-react"
import { exportTableToExcel } from "@/lib/export"
import { Button } from "@/components/ui/button"
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
import { AddCandidateDialog } from "./add-candidates-dialog"
import { VendorCandidates } from "@/db/schema/vendors"
import { DeleteCandidatesDialog } from "./delete-candidates-dialog"
import { InviteCandidatesDialog } from "./invite-candidates-dialog"
import { ImportVendorCandidatesButton } from "./import-button"
import { exportVendorCandidateTemplate } from "./excel-template-download"
interface CandidatesTableToolbarActionsProps {
table: Table<VendorCandidates>
}
export function CandidatesTableToolbarActions({ table }: CandidatesTableToolbarActionsProps) {
const selectedRows = table.getFilteredSelectedRowModel().rows
const hasSelection = selectedRows.length > 0
const [refreshKey, setRefreshKey] = React.useState(0)
// Handler to refresh the table after import
const handleImportSuccess = () => {
// Trigger a refresh of the table data
setRefreshKey(prev => prev + 1)
}
return (
<div className="flex items-center gap-2">
{/* Show actions only when rows are selected */}
{hasSelection ? (
<>
{/* Invite dialog - new addition */}
<InviteCandidatesDialog
candidates={selectedRows.map((row) => row.original)}
onSuccess={() => table.toggleAllRowsSelected(false)}
/>
{/* Delete dialog */}
<DeleteCandidatesDialog
candidates={selectedRows.map((row) => row.original)}
onSuccess={() => table.toggleAllRowsSelected(false)}
/>
</>
) : null}
{/* Add new candidate dialog */}
<AddCandidateDialog />
{/* Import Excel button */}
<ImportVendorCandidatesButton onSuccess={handleImportSuccess} />
{/* Export dropdown menu */}
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="outline" size="sm" className="gap-2">
<Download className="size-4" aria-hidden="true" />
<span className="hidden sm:inline">Export</span>
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem
onClick={() => {
exportTableToExcel(table, {
filename: "vendor-candidates",
excludeColumns: ["select", "actions"],
useGroupHeader: false,
})
}}
>
<FileDown className="mr-2 h-4 w-4" />
<span>Export Current Data</span>
</DropdownMenuItem>
<DropdownMenuItem onClick={exportVendorCandidateTemplate}>
<FileDown className="mr-2 h-4 w-4" />
<span>Download Template</span>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
)
}
|