From ee77f36b1ceece1236d45fba102c3ea410acebc1 Mon Sep 17 00:00:00 2001 From: dujinkim Date: Thu, 11 Sep 2025 11:20:42 +0000 Subject: (최겸) 구매 계약 메인 및 상세 기능 개발(템플릿 연동 및 계약 전달 개발 필요) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../general-contracts-table-toolbar-actions.tsx | 124 +++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 lib/general-contracts/main/general-contracts-table-toolbar-actions.tsx (limited to 'lib/general-contracts/main/general-contracts-table-toolbar-actions.tsx') diff --git a/lib/general-contracts/main/general-contracts-table-toolbar-actions.tsx b/lib/general-contracts/main/general-contracts-table-toolbar-actions.tsx new file mode 100644 index 00000000..28d64824 --- /dev/null +++ b/lib/general-contracts/main/general-contracts-table-toolbar-actions.tsx @@ -0,0 +1,124 @@ +"use client" + +import * as React from "react" +import { type Table } from "@tanstack/react-table" +import { + Download, FileSpreadsheet, + Trash2, +} from "lucide-react" +import { deleteContract } from "../service" +import { toast } from "sonner" +import { exportTableToExcel } from "@/lib/export" +import { Button } from "@/components/ui/button" +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuTrigger, +} from "@/components/ui/dropdown-menu" +import { GeneralContractListItem } from "./general-contracts-table-columns" +import { CreateGeneralContractDialog } from "./create-general-contract-dialog" + +interface GeneralContractsTableToolbarActionsProps { + table: Table +} + +export function GeneralContractsTableToolbarActions({ table }: GeneralContractsTableToolbarActionsProps) { + const [isExporting, setIsExporting] = React.useState(false) + + // 선택된 계약들 + const selectedContracts = React.useMemo(() => { + return table + .getFilteredSelectedRowModel() + .rows + .map(row => row.original) + }, [table.getFilteredSelectedRowModel().rows]) + + const handleExport = async () => { + try { + setIsExporting(true) + await exportTableToExcel(table, { + filename: "general-contracts", + excludeColumns: ["select", "actions"], + }) + toast.success("계약 목록이 성공적으로 내보내졌습니다.") + } catch (error) { + toast.error("내보내기 중 오류가 발생했습니다.") + } finally { + setIsExporting(false) + } + } + + + const handleDelete = async () => { + if (selectedContracts.length === 0) { + toast.error("계약폐기할 계약을 선택해주세요.") + return + } + + // 계약폐기 확인 + const confirmed = window.confirm( + `선택한 ${selectedContracts.length}개 계약을 폐기하시겠습니까?\n계약폐기 후에는 복구할 수 없습니다.` + ) + + if (!confirmed) return + + try { + // 선택된 모든 계약을 폐기 처리 + const deletePromises = selectedContracts.map(contract => + deleteContract(contract.id) + ) + + await Promise.all(deletePromises) + + toast.success(`${selectedContracts.length}개 계약이 폐기되었습니다.`) + + // 테이블 새로고침 + } catch (error) { + console.error('Error deleting contracts:', error) + toast.error("계약폐기 중 오류가 발생했습니다.") + } + } + + return ( +
+ {/* 신규 등록 */} + + + {/* 계약폐기 */} + + + {/* Export */} + + + + + + + + 계약 목록 내보내기 + + + +
+ ) +} -- cgit v1.2.3