summaryrefslogtreecommitdiff
path: root/lib/form-list/table/formLists-table-toolbar-actions.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'lib/form-list/table/formLists-table-toolbar-actions.tsx')
-rw-r--r--lib/form-list/table/formLists-table-toolbar-actions.tsx47
1 files changed, 40 insertions, 7 deletions
diff --git a/lib/form-list/table/formLists-table-toolbar-actions.tsx b/lib/form-list/table/formLists-table-toolbar-actions.tsx
index 346a3980..96494607 100644
--- a/lib/form-list/table/formLists-table-toolbar-actions.tsx
+++ b/lib/form-list/table/formLists-table-toolbar-actions.tsx
@@ -7,18 +7,49 @@ import { toast } from "sonner"
import { exportTableToExcel } from "@/lib/export"
import { Button } from "@/components/ui/button"
-import { TagTypeClassFormMappings } from "@/db/schema/vendorData"
+import { ExtendedFormMappings } from "../validation"
interface ItemsTableToolbarActionsProps {
- table: Table<TagTypeClassFormMappings>
+ table: Table<ExtendedFormMappings>
}
export function FormListsTableToolbarActions({ table }: ItemsTableToolbarActionsProps) {
- // 파일 input을 숨기고, 버튼 클릭 시 참조해 클릭하는 방식
- const fileInputRef = React.useRef<HTMLInputElement>(null)
+ const [isLoading, setIsLoading] = React.useState(false)
+ const syncForms = async () => {
+ try {
+ setIsLoading(true)
+
+ // API 엔드포인트 호출
+ const response = await fetch('/api/cron/forms')
+
+ if (!response.ok) {
+ const errorData = await response.json()
+ throw new Error(errorData.error || 'Failed to sync forms')
+ }
+
+ const data = await response.json()
+
+ // 성공 메시지 표시
+ toast.success(
+ `Forms synced successfully! ${data.result.items} items processed.`
+ )
+
+ // 페이지 새로고침으로 테이블 데이터 업데이트
+ window.location.reload()
+ } catch (error) {
+ console.error('Error syncing forms:', error)
+ toast.error(
+ error instanceof Error
+ ? error.message
+ : 'An error occurred while syncing forms'
+ )
+ } finally {
+ setIsLoading(false)
+ }
+ }
return (
@@ -29,8 +60,10 @@ export function FormListsTableToolbarActions({ table }: ItemsTableToolbarActions
size="sm"
className="gap-2"
>
- <RefreshCcw className="size-4" aria-hidden="true" />
- <span className="hidden sm:inline">Get Forms</span>
+ <RefreshCcw className={`size-4 ${isLoading ? 'animate-spin' : ''}`} aria-hidden="true" />
+ <span className="hidden sm:inline">
+ {isLoading ? 'Syncing...' : 'Get Forms'}
+ </span>
</Button>
{/** 4) Export 버튼 */}
@@ -39,7 +72,7 @@ export function FormListsTableToolbarActions({ table }: ItemsTableToolbarActions
size="sm"
onClick={() =>
exportTableToExcel(table, {
- filename: "tasks",
+ filename: "Forms",
excludeColumns: ["select", "actions"],
})
}