diff options
Diffstat (limited to 'lib/items/table/items-table-toolbar-actions.tsx')
| -rw-r--r-- | lib/items/table/items-table-toolbar-actions.tsx | 63 |
1 files changed, 60 insertions, 3 deletions
diff --git a/lib/items/table/items-table-toolbar-actions.tsx b/lib/items/table/items-table-toolbar-actions.tsx index b3178ce1..7d8f7fb6 100644 --- a/lib/items/table/items-table-toolbar-actions.tsx +++ b/lib/items/table/items-table-toolbar-actions.tsx @@ -2,9 +2,10 @@ import * as React from "react" import { type Table } from "@tanstack/react-table" -import { Download, FileDown } from "lucide-react" +import { Download, FileDown, Database, Loader2 } from "lucide-react" import * as ExcelJS from 'exceljs' import { saveAs } from "file-saver" +import { toast } from "sonner" import { Button } from "@/components/ui/button" import { @@ -19,6 +20,9 @@ import { DeleteItemsDialog } from "./delete-items-dialog" import { AddItemDialog } from "./add-items-dialog" import { exportItemTemplate } from "./item-excel-template" import { ImportItemButton } from "./import-excel-button" +import { syncItemsFromCodeLists } from "@/lib/sedp/sync-package" + +// 동기화 함수 import (실제 경로로 수정 필요) interface ItemsTableToolbarActionsProps { table: Table<Item> @@ -26,12 +30,47 @@ interface ItemsTableToolbarActionsProps { export function ItemsTableToolbarActions({ table }: ItemsTableToolbarActionsProps) { const [refreshKey, setRefreshKey] = React.useState(0) + const [isSyncing, setIsSyncing] = React.useState(false) // 가져오기 성공 후 테이블 갱신 const handleImportSuccess = () => { setRefreshKey(prev => prev + 1) } + // 테이블 새로고침 함수 + const refreshTable = () => { + setRefreshKey(prev => prev + 1) + // 페이지 새로고침 또는 데이터 refetch 로직 + window.location.reload() + } + + // 전체 프로젝트 동기화 + const handleSyncAllProjects = async () => { + if (isSyncing) return + + setIsSyncing(true) + const loadingToast = toast.loading("모든 프로젝트의 아이템을 동기화하는 중...") + + try { + await syncItemsFromCodeLists() + toast.dismiss(loadingToast) + toast.success("모든 프로젝트의 아이템이 성공적으로 동기화되었습니다!") + + // 테이블 새로고침 + setTimeout(() => { + refreshTable() + }, 1000) + } catch (error) { + toast.dismiss(loadingToast) + toast.error("동기화 중 오류가 발생했습니다: " + (error as Error).message) + console.error("동기화 오류:", error) + } finally { + setIsSyncing(false) + } + } + + + // Excel 내보내기 함수 const exportTableToExcel = async ( table: Table<any>, @@ -125,10 +164,28 @@ export function ItemsTableToolbarActions({ table }: ItemsTableToolbarActionsProp ) : null} {/* 새 아이템 추가 다이얼로그 */} - <AddItemDialog /> + {/* <AddItemDialog /> */} {/* Import 버튼 */} - <ImportItemButton onSuccess={handleImportSuccess} /> + {/* <ImportItemButton onSuccess={handleImportSuccess} /> */} + + {/* 동기화 버튼 */} + <Button + variant="outline" + size="sm" + className="gap-2" + disabled={isSyncing} + onClick={handleSyncAllProjects} + > + {isSyncing ? ( + <Loader2 className="size-4 animate-spin" aria-hidden="true" /> + ) : ( + <Database className="size-4" aria-hidden="true" /> + )} + <span className="hidden sm:inline"> + {isSyncing ? "동기화 중..." : "동기화"} + </span> + </Button> {/* Export 드롭다운 메뉴 */} <DropdownMenu> |
