summaryrefslogtreecommitdiff
path: root/lib/menu-list/table/export-button.tsx
blob: 320e495fa58b922fe02398cc092642c1e329fd78 (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
63
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>
  );
}