"use client" import * as React from "react" import { type Table } from "@tanstack/react-table" import { Download, Plus, Trash2, Upload, FileSpreadsheet } from "lucide-react" import { toast } from "sonner" import { exportTableToExcel } from "@/lib/export" import { Button } from "@/components/ui/button" import { EsgEvaluationsView } from "@/db/schema" import { EsgEvaluationBatchDeleteDialog } from "./esg-evaluation-delete-dialog" import { downloadEsgTemplate } from "./excel-utils" import { useRouter } from "next/navigation" import { ExcelImportDialog } from "./esg-excel-import" interface EsgEvaluationsTableToolbarActionsProps { table: Table onCreateNew?: () => void onRefresh?: () => void } export function EsgEvaluationsTableToolbarActions({ table, onCreateNew, onRefresh }: EsgEvaluationsTableToolbarActionsProps) { const [isRefreshing, setIsRefreshing] = React.useState(false) const [deleteDialogOpen, setDeleteDialogOpen] = React.useState(false) const [importDialogOpen, setImportDialogOpen] = React.useState(false) const router = useRouter() // 선택된 행들 const selectedRows = table.getFilteredSelectedRowModel().rows const hasSelection = selectedRows.length > 0 const selectedEvaluations = selectedRows.map(row => row.original) // ---------------------------------------------------------------- // 새 평가표 생성 // ---------------------------------------------------------------- const handleCreateNew = () => { if (onCreateNew) { onCreateNew() } else { toast.info("새 ESG 평가표 생성 기능을 구현해주세요.") } } // ---------------------------------------------------------------- // 선택된 평가표들 삭제 다이얼로그 열기 // ---------------------------------------------------------------- const handleDeleteSelected = () => { if (!hasSelection) return setDeleteDialogOpen(true) } // ---------------------------------------------------------------- // 삭제 성공 후 처리 // ---------------------------------------------------------------- const handleDeleteSuccess = async () => { // 선택 해제 table.resetRowSelection() router.refresh() } // ---------------------------------------------------------------- // Excel 템플릿 다운로드 // ---------------------------------------------------------------- const handleDownloadTemplate = async () => { try { await downloadEsgTemplate() toast.success("Excel 템플릿이 다운로드되었습니다.") } catch (error) { console.error('Error downloading template:', error) toast.error("템플릿 다운로드 중 오류가 발생했습니다.") } } // ---------------------------------------------------------------- // Excel 내보내기 // ---------------------------------------------------------------- const handleExport = () => { try { exportTableToExcel(table, { filename: "ESG_Evaluations", excludeColumns: ["select", "actions"], }) toast.success("Excel 파일이 다운로드되었습니다.") } catch (error) { console.error('Error exporting to Excel:', error) toast.error("Excel 내보내기 중 오류가 발생했습니다.") } } // ---------------------------------------------------------------- // 임포트 성공 후 처리 // ---------------------------------------------------------------- const handleImportSuccess = () => { router.refresh() } return ( <>
{/* 새 평가표 생성 버튼 */} {/* Excel 관련 버튼들 */}
{/* Excel 템플릿 다운로드 */} {/* Excel 데이터 임포트 */} {/* Excel 데이터 내보내기 */}
{/* 선택된 항목 삭제 버튼 */} {hasSelection && ( )}
{/* 배치 삭제 다이얼로그 */} {/* Excel 임포트 다이얼로그 */} ) }