diff options
| author | joonhoekim <26rote@gmail.com> | 2025-07-02 04:46:24 +0000 |
|---|---|---|
| committer | joonhoekim <26rote@gmail.com> | 2025-07-02 04:46:24 +0000 |
| commit | a42873419d14652d3639d2ae02d2ea54653b4749 (patch) | |
| tree | 3823f94d9c919f88f05fdfa5f262ea093447e24a /lib/bidding-projects/table/projects-table-toolbar-actions.tsx | |
| parent | 2acf5f8966a40c1c9a97680c8dc263ee3f1ad3d1 (diff) | |
(김준회) 견적프로젝트 해양 TOP - nonsap(견적물량관리시스템) 데이터 가져오기 추가
Diffstat (limited to 'lib/bidding-projects/table/projects-table-toolbar-actions.tsx')
| -rw-r--r-- | lib/bidding-projects/table/projects-table-toolbar-actions.tsx | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/lib/bidding-projects/table/projects-table-toolbar-actions.tsx b/lib/bidding-projects/table/projects-table-toolbar-actions.tsx index ee2f8c4e..3e2f3392 100644 --- a/lib/bidding-projects/table/projects-table-toolbar-actions.tsx +++ b/lib/bidding-projects/table/projects-table-toolbar-actions.tsx @@ -8,6 +8,7 @@ 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<BiddingProjects> @@ -16,28 +17,29 @@ interface ItemsTableToolbarActionsProps { 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/bid-projects') + // 서버 액션 호출 (NONSAP에서 데이터 동기화) + const result = await syncProjectsFromNonSap() - if (!response.ok) { - const errorData = await response.json() - throw new Error(errorData.error || 'Failed to sync projects') + 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 || '프로젝트 동기화에 실패했습니다.') } - - 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( @@ -64,7 +66,7 @@ export function ProjectTableToolbarActions({ table }: ItemsTableToolbarActionsPr aria-hidden="true" /> <span className="hidden sm:inline"> - {isLoading ? 'Syncing...' : 'Get Projects'} + {isLoading ? '동기화 중...' : '해양 TOP 견적물량시스템 동기화'} </span> </Button> |
