diff options
Diffstat (limited to 'lib/tag-numbering/table/tagNumbering-table-toolbar-actions.tsx')
| -rw-r--r-- | lib/tag-numbering/table/tagNumbering-table-toolbar-actions.tsx | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/lib/tag-numbering/table/tagNumbering-table-toolbar-actions.tsx b/lib/tag-numbering/table/tagNumbering-table-toolbar-actions.tsx index 1a7af254..7a14817f 100644 --- a/lib/tag-numbering/table/tagNumbering-table-toolbar-actions.tsx +++ b/lib/tag-numbering/table/tagNumbering-table-toolbar-actions.tsx @@ -16,10 +16,40 @@ interface ItemsTableToolbarActionsProps { } export function TagNumberingTableToolbarActions({ table }: ItemsTableToolbarActionsProps) { - // 파일 input을 숨기고, 버튼 클릭 시 참조해 클릭하는 방식 - const fileInputRef = React.useRef<HTMLInputElement>(null) + const [isLoading, setIsLoading] = React.useState(false) + const syncTags = async () => { + try { + setIsLoading(true) + // API 엔드포인트 호출 + const response = await fetch('/api/cron/object-classes') + + if (!response.ok) { + const errorData = await response.json() + throw new Error(errorData.error || 'Failed to sync tag numberings') + } + + const data = await response.json() + + // 성공 메시지 표시 + toast.success( + `tag numberings synced successfully! ${data.result.items} items processed.` + ) + + // 페이지 새로고침으로 테이블 데이터 업데이트 + window.location.reload() + } catch (error) { + console.error('Error syncing tag numberings:', error) + toast.error( + error instanceof Error + ? error.message + : 'An error occurred while syncing tag numberings' + ) + } finally { + setIsLoading(false) + } + } return ( <div className="flex items-center gap-2"> @@ -28,9 +58,14 @@ export function TagNumberingTableToolbarActions({ table }: ItemsTableToolbarActi variant="samsung" size="sm" className="gap-2" + onClick={syncTags} + disabled={isLoading} > - <RefreshCcw className="size-4" aria-hidden="true" /> - <span className="hidden sm:inline">Get Tag Numbering</span> + + <RefreshCcw className={`size-4 ${isLoading ? 'animate-spin' : ''}`} aria-hidden="true" /> + <span className="hidden sm:inline"> + {isLoading ? 'Syncing...' : 'Get Tag Numbering'} + </span> </Button> {/** 4) Export 버튼 */} |
