"use client" import * as React from "react" import { type Table } from "@tanstack/react-table" import { Download, RefreshCcw } from "lucide-react" import { toast } from "sonner" import { exportTableToExcel } from "@/lib/export" import { Button } from "@/components/ui/button" import { BiddingProjects } from "@/db/schema" import { syncProjectsFromNonSap } from "../actions" interface ItemsTableToolbarActionsProps { table: Table } export function ProjectTableToolbarActions({ table }: ItemsTableToolbarActionsProps) { const [isLoading, setIsLoading] = React.useState(false) // 프로젝트 동기화 서버 액션 호출 함수 const syncProjects = async () => { try { setIsLoading(true) // 서버 액션 호출 (NONSAP에서 데이터 동기화) const result = await syncProjectsFromNonSap() if (result.success) { // 성공 메시지 표시 toast.success(result.message) // 오류가 있었다면 추가 정보 표시 if (result.errors && result.errors.length > 0) { console.warn('동기화 오류:', result.errors) toast.warning(`일부 프로젝트 동기화 중 오류가 발생했습니다. 콘솔을 확인해주세요.`) } // 페이지 새로고침으로 테이블 데이터 업데이트 window.location.reload() } else { throw new Error(result.error || '프로젝트 동기화에 실패했습니다.') } } catch (error) { console.error('Error syncing projects:', error) toast.error( error instanceof Error ? error.message : 'An error occurred while syncing projects' ) } finally { setIsLoading(false) } } return (
{/** 4) Export 버튼 */}
) }