diff options
Diffstat (limited to 'lib/vendor-document-list/plant/upload/table.tsx')
| -rw-r--r-- | lib/vendor-document-list/plant/upload/table.tsx | 65 |
1 files changed, 56 insertions, 9 deletions
diff --git a/lib/vendor-document-list/plant/upload/table.tsx b/lib/vendor-document-list/plant/upload/table.tsx index 2247fc57..2edd9717 100644 --- a/lib/vendor-document-list/plant/upload/table.tsx +++ b/lib/vendor-document-list/plant/upload/table.tsx @@ -170,31 +170,31 @@ export function StageSubmissionsTable({ promises, selectedProjectId }: StageSubm if (type === "downloadCover") { const projectCode = row.original.projectCode; const project = projects.find(p => p.code === projectCode); - + if (!project) { toast.error("프로젝트 정보를 찾을 수 없습니다."); setRowAction(null); return; } - + (async () => { try { - const res = await fetch(`/api/projects/${project.id}/cover`, { - method: "GET" + const res = await fetch(`/api/projects/${project.id}/cover`, { + method: "GET" }); - + if (!res.ok) { const error = await res.json(); throw new Error(error.message || "커버 페이지를 가져올 수 없습니다"); } - + const { fileUrl, fileName } = await res.json(); - + // quickDownload 사용 quickDownload(fileUrl, fileName || `${projectCode}_cover.docx`); - + toast.success("커버 페이지 다운로드를 시작했습니다."); - + } catch (e) { toast.error(e instanceof Error ? e.message : "커버 페이지 다운로드에 실패했습니다."); console.error(e); @@ -202,6 +202,53 @@ export function StageSubmissionsTable({ promises, selectedProjectId }: StageSubm setRowAction(null); } })(); + } else if (type === "sync") { + // 개별 행 sync 처리 + const submissionId = row.original.latestSubmissionId; + + if (!submissionId) { + toast.error("제출물 ID를 찾을 수 없습니다."); + setRowAction(null); + return; + } + + (async () => { + try { + toast.info("동기화를 시작합니다..."); + + const response = await fetch('/api/stage-submissions/sync', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ submissionIds: [submissionId] }), + }); + + const result = await response.json(); + + if (result.success) { + toast.success("동기화가 완료되었습니다."); + + // 상세 결과 표시 + if (result.results?.details?.[0]) { + const detail = result.results.details[0]; + if (!detail.success) { + toast.warning(`동기화 실패: ${detail.error || '알 수 없는 오류'}`); + } + } + + // 테이블 새로고침 + window.location.reload(); + } else { + toast.error(result.error || "동기화에 실패했습니다."); + } + } catch (error) { + console.error("Sync error:", error); + toast.error("동기화 중 오류가 발생했습니다."); + } finally { + setRowAction(null); + } + })(); } }, [rowAction, setRowAction, projects]); |
