diff options
Diffstat (limited to 'lib/menu-list/table/export-button.tsx')
| -rw-r--r-- | lib/menu-list/table/export-button.tsx | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/lib/menu-list/table/export-button.tsx b/lib/menu-list/table/export-button.tsx new file mode 100644 index 00000000..320e495f --- /dev/null +++ b/lib/menu-list/table/export-button.tsx @@ -0,0 +1,64 @@ +// app/evcp/menu-list/components/export-button.tsx + +"use client"; + +import { useState } from "react"; +import { Button } from "@/components/ui/button"; +import { Download } from "lucide-react"; +import { toast } from "sonner"; +import { exportMenusToExcel } from "./excel-export"; + +interface MenuAssignment { + id: number; + menuPath: string; + menuTitle: string; + menuDescription?: string | null; + menuGroup?: string | null; + sectionTitle: string; + domain: string; + isActive: boolean; + manager1Name?: string | null; + manager1Email?: string | null; + manager2Name?: string | null; + manager2Email?: string | null; +} + +interface ExportButtonProps { + menus: MenuAssignment[]; + translate: (key: string) => string; +} + +export function ExportButton({ menus, translate }: ExportButtonProps) { + const [isExporting, setIsExporting] = useState(false); + + const handleExport = async () => { + if (menus.length === 0) { + toast.error("내보낼 데이터가 없습니다."); + return; + } + + setIsExporting(true); + + try { + await exportMenusToExcel(menus, translate); + toast.success(`${menus.length}개의 메뉴 데이터를 엑셀로 내보냈습니다.`); + } catch (error) { + console.error("Export error:", error); + toast.error("엑셀 파일 생성 중 오류가 발생했습니다."); + } finally { + setIsExporting(false); + } + }; + + return ( + <Button + onClick={handleExport} + disabled={isExporting || menus.length === 0} + variant="outline" + size="sm" + > + <Download className="mr-2 h-4 w-4" /> + {isExporting ? "내보내는 중..." : `엑셀 다운로드 (${menus.length}개)`} + </Button> + ); +}
\ No newline at end of file |
