summaryrefslogtreecommitdiff
path: root/lib/docu-list-rule/combo-box-settings/table/combo-box-options-table-toolbar.tsx
blob: 3bb3c95f6a83817a36af4b18128765fc553a2287 (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
"use client"

import * as React from "react"
import { type Table } from "@tanstack/react-table"

import { ComboBoxOptionsAddDialog } from "@/lib/docu-list-rule/combo-box-settings/table/combo-box-options-add-dialog"
import { DeleteComboBoxOptionsDialog } from "@/lib/docu-list-rule/combo-box-settings/table/delete-combo-box-options-dialog"

interface ComboBoxOption {
  id: number
  codeGroupId: number
  code: string
  description: string
  remark: string | null
  isActive: boolean
  createdAt: Date
  updatedAt: Date
}

interface ComboBoxOptionsTableToolbarActionsProps {
  table: Table<ComboBoxOption>
  codeGroupId: number
  onSuccess?: () => void
}

export function ComboBoxOptionsTableToolbarActions({
  table,
  codeGroupId,
  onSuccess,
}: ComboBoxOptionsTableToolbarActionsProps) {
  const selectedRows = table.getFilteredSelectedRowModel().rows
  const selectedOptions = selectedRows.map((row) => row.original)

  return (
    <div className="flex items-center gap-2">
      {/** 선택된 로우가 있으면 삭제 다이얼로그 */}
      {selectedOptions.length > 0 ? (
        <DeleteComboBoxOptionsDialog
          options={selectedOptions}
          onSuccess={() => {
            table.toggleAllRowsSelected(false)
            onSuccess?.()
          }}
        />
      ) : null}

      <ComboBoxOptionsAddDialog
        codeGroupId={codeGroupId}
        onSuccess={onSuccess}
      />
    </div>
  )
}