summaryrefslogtreecommitdiff
path: root/lib/pq/pq-review-table-new/vendors-table-toolbar-actions.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pq/pq-review-table-new/vendors-table-toolbar-actions.tsx')
-rw-r--r--lib/pq/pq-review-table-new/vendors-table-toolbar-actions.tsx99
1 files changed, 68 insertions, 31 deletions
diff --git a/lib/pq/pq-review-table-new/vendors-table-toolbar-actions.tsx b/lib/pq/pq-review-table-new/vendors-table-toolbar-actions.tsx
index a68d9b23..f93959a6 100644
--- a/lib/pq/pq-review-table-new/vendors-table-toolbar-actions.tsx
+++ b/lib/pq/pq-review-table-new/vendors-table-toolbar-actions.tsx
@@ -16,6 +16,7 @@ import {
getQMManagers
} from "@/lib/pq/service"
import { SiteVisitDialog } from "./site-visit-dialog"
+import type { SiteVisitRequestFormValues } from "./site-visit-dialog"
import { RequestInvestigationDialog } from "./request-investigation-dialog"
import { CancelInvestigationDialog, ReRequestInvestigationDialog } from "./cancel-investigation-dialog"
import { SendResultsDialog } from "./send-results-dialog"
@@ -444,12 +445,10 @@ const handleOpenRequestDialog = async () => {
}
// 재실사 요청 처리
- const handleRequestReinspection = async (data: {
- qmManagerId: number,
- forecastedAt: Date,
- investigationAddress: string,
- investigationNotes?: string
- }) => {
+ const handleRequestReinspection = async (
+ data: SiteVisitRequestFormValues,
+ attachments?: File[]
+ ) => {
try {
// 보완-재실사 대상 실사만 필터링
const supplementReinspectInvestigations = selectedRows.filter(row =>
@@ -463,23 +462,27 @@ const handleOpenRequestDialog = async () => {
}
// 첫 번째 대상 실사로 재실사 요청 생성
- const targetInvestigation = supplementReinspectInvestigations[0].original.investigation!;
+ const targetRow = supplementReinspectInvestigations[0].original;
+ const targetInvestigation = targetRow.investigation!;
const { requestSupplementReinspectionAction } = await import('@/lib/vendor-investigation/service');
+ // SiteVisitRequestFormValues를 requestSupplementReinspectionAction 형식으로 변환
+ // shiAttendees는 그대로 전달 (새로운 형식: {checked, attendees})
const result = await requestSupplementReinspectionAction({
investigationId: targetInvestigation.id,
siteVisitData: {
- inspectionDuration: 1.0, // 기본 1일
- requestedStartDate: data.forecastedAt,
- requestedEndDate: new Date(data.forecastedAt.getTime() + 24 * 60 * 60 * 1000), // 1일 후
- shiAttendees: {},
- vendorRequests: {},
- additionalRequests: data.investigationNotes || "보완을 위한 재실사 요청입니다.",
- }
+ inspectionDuration: data.inspectionDuration,
+ requestedStartDate: data.requestedStartDate,
+ requestedEndDate: data.requestedEndDate,
+ shiAttendees: data.shiAttendees || {},
+ vendorRequests: data.vendorRequests || {},
+ additionalRequests: data.additionalRequests || "",
+ },
});
if (result.success) {
toast.success("재실사 요청이 생성되었습니다.");
+ setIsReinspectionDialogOpen(false);
window.location.reload();
} else {
toast.error(result.error || "재실사 요청 생성 중 오류가 발생했습니다.");
@@ -563,6 +566,16 @@ const handleOpenRequestDialog = async () => {
row.original.investigation.evaluationResult === "SUPPLEMENT_REINSPECT"
).length
+ // 재실사 요청 가능 여부 확인 (방문실사평가 또는 제품검사평가만 가능)
+ const canRequestReinspection = selectedRows.some(row => {
+ const investigation = row.original.investigation
+ if (!investigation) return false
+ if (investigation.evaluationResult !== "SUPPLEMENT_REINSPECT") return false
+ const method = investigation.investigationMethod
+ // 서류평가 또는 구매자체평가는 재방문실사 불가
+ return method === "SITE_VISIT_EVAL" || method === "PRODUCT_INSPECTION"
+ })
+
// 미실사 PQ가 선택되었는지 확인
const hasNonInspectionPQ = selectedRows.some(row =>
row.original.type === "NON_INSPECTION"
@@ -720,9 +733,15 @@ const handleOpenRequestDialog = async () => {
disabled={
isLoading ||
selectedRows.length === 0 ||
- reinspectInvestigationsCount === 0
+ reinspectInvestigationsCount === 0 ||
+ !canRequestReinspection
}
className="gap-2"
+ title={
+ !canRequestReinspection && reinspectInvestigationsCount > 0
+ ? "재방문 실사 요청은 방문실사평가 또는 제품검사평가에만 가능합니다."
+ : undefined
+ }
>
<RefreshCw className="size-4" aria-hidden="true" />
<span className="hidden sm:inline">재방문 실사 요청</span>
@@ -805,22 +824,40 @@ const handleOpenRequestDialog = async () => {
/>
{/* 재방문실사 요청 Dialog */}
- <SiteVisitDialog
- isOpen={isReinspectionDialogOpen}
- onClose={() => setIsReinspectionDialogOpen(false)}
- onSubmit={handleRequestReinspection}
- investigation={{
- id: 0, // 재실사용으로 0으로 설정 (기존 데이터 로드 안함)
- investigationMethod: "SITE_VISIT_EVAL",
- investigationAddress: "",
- vendorName: "재실사 대상",
- vendorCode: "N/A",
- projectName: "",
- projectCode: "",
- pqItems: null
- }}
- isReinspection={true}
- />
+ {(() => {
+ // 보완-재실사 대상 실사 찾기
+ const supplementReinspectInvestigations = selectedRows.filter(row =>
+ row.original.investigation &&
+ row.original.investigation.evaluationResult === "SUPPLEMENT_REINSPECT"
+ );
+
+ if (supplementReinspectInvestigations.length === 0) {
+ return null;
+ }
+
+ const targetRow = supplementReinspectInvestigations[0].original;
+ const targetInvestigation = targetRow.investigation!;
+
+ return (
+ <SiteVisitDialog
+ isOpen={isReinspectionDialogOpen}
+ onClose={() => setIsReinspectionDialogOpen(false)}
+ onSubmit={handleRequestReinspection}
+ investigation={{
+ id: targetInvestigation.id,
+ investigationMethod: targetInvestigation.investigationMethod || undefined,
+ investigationAddress: targetInvestigation.investigationAddress || undefined,
+ investigationNotes: targetInvestigation.investigationNotes || undefined,
+ vendorName: targetRow.vendorName,
+ vendorCode: targetRow.vendorCode,
+ projectName: targetRow.projectName || undefined,
+ projectCode: targetRow.projectCode || undefined,
+ pqItems: targetRow.pqItems || null,
+ }}
+ isReinspection={true}
+ />
+ );
+ })()}
{/* 결재 미리보기 Dialog - 실사 의뢰 */}
{session?.user && investigationFormData && (