summaryrefslogtreecommitdiff
path: root/lib/rfqs-ship/vendor-table/vendors-table-toolbar-actions.tsx
blob: a8825cc7a034f7d0af08c7f550a4fcf6a7d94a85 (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
"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 { RfqType } from "@/lib/rfqs-ship/validations"

interface VendorsTableToolbarActionsProps {
  table: Table<MatchedVendorRow>
  rfqId: number
  rfqType: RfqType
}

export function VendorsTableToolbarActions({
  table,
  rfqId,
  rfqType,
}: VendorsTableToolbarActionsProps) {
  // 선택된 행이 있는지 확인
  const rowSelection = table.getState().rowSelection
  const selectedRows = Object.keys(rowSelection).length
  const hasSelectedRows = selectedRows > 0
  
  // 선택된 벤더 목록
  const selectedVendors = React.useMemo(() => {
    return Object.keys(rowSelection).map((id) =>
      table.getRow(id).original
    )
  }, [rowSelection, table])
  
  return (
    <div className="flex items-center justify-between gap-2">
      <div className="flex items-center gap-2">
        <AddVendorDialog rfqId={rfqId} />
      </div>
      <div className="flex items-center gap-2">
        {hasSelectedRows && (
          <InviteVendorsDialog
            rfqId={rfqId}
            rfqType={rfqType}
            vendors={selectedVendors}
            directCbe={true}
            onSuccess={() => table.toggleAllRowsSelected(false)}
          >
            <Button
              variant="default"
              size="sm"
              className="h-8"
              disabled={!hasSelectedRows}
            >
              CBE 요청 ({selectedRows})
            </Button>
          </InviteVendorsDialog>
        )}
      </div>
    </div>
  )
}