summaryrefslogtreecommitdiff
path: root/lib/menu-list/table/initialize-button.tsx
blob: 1b8a2458d0d807014a31c57d2c7a29f409c16a36 (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
// app/evcp/menu-list/components/initialize-button.tsx

"use client";

import { useState } from "react";
import { Button } from "@/components/ui/button";
import { RefreshCw } from "lucide-react";
import { toast } from "sonner";
import { initializeMenuAssignments } from "../servcie";

export function InitializeButton() {
  const [isLoading, setIsLoading] = useState(false);

  const handleInitialize = async () => {
    setIsLoading(true);
    try {
      const result = await initializeMenuAssignments();
      
      if (result.success) {
        toast.success(result.message);
      } else {
        toast.error(result.message);
      }
    } catch (error) {
      toast.error("메뉴 초기화 중 오류가 발생했습니다.");
    } finally {
      setIsLoading(false);
    }
  };

  return (
    <Button 
      onClick={handleInitialize} 
      disabled={isLoading}
      variant="outline"
      size="sm"
    >
      <RefreshCw className={`h-4 w-4 mr-2 ${isLoading ? 'animate-spin' : ''}`} />
      메뉴 초기화
    </Button>
  );
}