summaryrefslogtreecommitdiff
path: root/lib/projects/table/projects-table-toolbar-actions.tsx
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-04-08 03:08:19 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-04-08 03:08:19 +0000
commit9ceed79cf32c896f8a998399bf1b296506b2cd4a (patch)
treef84750fa6cac954d5e31221fc47a54c655fc06a9 /lib/projects/table/projects-table-toolbar-actions.tsx
parent230ce796836c25df26c130dbcd616ef97d12b2ec (diff)
로그인 및 미들웨어 처리. 구조 변경
Diffstat (limited to 'lib/projects/table/projects-table-toolbar-actions.tsx')
-rw-r--r--lib/projects/table/projects-table-toolbar-actions.tsx89
1 files changed, 89 insertions, 0 deletions
diff --git a/lib/projects/table/projects-table-toolbar-actions.tsx b/lib/projects/table/projects-table-toolbar-actions.tsx
new file mode 100644
index 00000000..dc55423d
--- /dev/null
+++ b/lib/projects/table/projects-table-toolbar-actions.tsx
@@ -0,0 +1,89 @@
+"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 { Project } from "@/db/schema"
+
+interface ItemsTableToolbarActionsProps {
+ table: Table<Project>
+}
+
+export function ProjectTableToolbarActions({ table }: ItemsTableToolbarActionsProps) {
+ const [isLoading, setIsLoading] = React.useState(false)
+
+ // 프로젝트 동기화 API 호출 함수
+ const syncProjects = async () => {
+ try {
+ setIsLoading(true)
+
+ // API 엔드포인트 호출
+ const response = await fetch('/api/cron/projects')
+
+ if (!response.ok) {
+ const errorData = await response.json()
+ throw new Error(errorData.error || 'Failed to sync projects')
+ }
+
+ const data = await response.json()
+
+ // 성공 메시지 표시
+ toast.success(
+ `Projects synced successfully! ${data.result.items} items processed.`
+ )
+
+ // 페이지 새로고침으로 테이블 데이터 업데이트
+ window.location.reload()
+ } 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 (
+ <div className="flex items-center gap-2">
+ <Button
+ variant="samsung"
+ size="sm"
+ className="gap-2"
+ onClick={syncProjects}
+ disabled={isLoading}
+ >
+ <RefreshCcw
+ className={`size-4 ${isLoading ? 'animate-spin' : ''}`}
+ aria-hidden="true"
+ />
+ <span className="hidden sm:inline">
+ {isLoading ? 'Syncing...' : 'Get Projects'}
+ </span>
+ </Button>
+
+ {/** 4) Export 버튼 */}
+ <Button
+ variant="outline"
+ size="sm"
+ onClick={() =>
+ exportTableToExcel(table, {
+ filename: "Projects",
+ excludeColumns: ["select", "actions"],
+ })
+ }
+ className="gap-2"
+ disabled={isLoading}
+ >
+ <Download className="size-4" aria-hidden="true" />
+ <span className="hidden sm:inline">Export</span>
+ </Button>
+ </div>
+ )
+} \ No newline at end of file