summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--components/additional-info/join-form.tsx59
-rw-r--r--lib/rfq-last/approval-actions.ts26
-rw-r--r--lib/rfq-last/service.ts2
-rw-r--r--lib/rfq-last/vendor-response/editor/vendor-response-editor.tsx44
-rw-r--r--lib/techsales-rfq/approval-actions.ts71
5 files changed, 191 insertions, 11 deletions
diff --git a/components/additional-info/join-form.tsx b/components/additional-info/join-form.tsx
index fe5698d8..1642962f 100644
--- a/components/additional-info/join-form.tsx
+++ b/components/additional-info/join-form.tsx
@@ -223,6 +223,8 @@ export function InfoForm() {
})
const isFormValid = form.formState.isValid
+ const watchedCountry = form.watch("country")
+ const isDomesticVendor = watchedCountry === "KR"
// Field array for contacts
const { fields: contactFields, append: addContact, remove: removeContact, replace: replaceContacts } =
@@ -369,6 +371,29 @@ export function InfoForm() {
fetchVendorData()
}, [companyId, form, replaceContacts])
+ // 도로명주소 검색 결과 수신 (내자 벤더만)
+ React.useEffect(() => {
+ if (!isDomesticVendor) return
+
+ const handleMessage = (event: MessageEvent) => {
+ if (!event.data || event.data.type !== "JUSO_SELECTED") return
+ const { zipNo, roadAddrPart1, roadAddrPart2, addrDetail } = event.data.payload || {}
+ const road = [roadAddrPart1, roadAddrPart2].filter(Boolean).join(" ").trim()
+
+ form.setValue("postalCode", zipNo || form.getValues("postalCode") || "", { shouldDirty: true })
+ form.setValue("address", road || form.getValues("address") || "", { shouldDirty: true })
+ form.setValue("addressDetail", addrDetail || form.getValues("addressDetail") || "", { shouldDirty: true })
+ }
+
+ window.addEventListener("message", handleMessage)
+ return () => window.removeEventListener("message", handleMessage)
+ }, [isDomesticVendor, form])
+
+ const handleJusoSearch = () => {
+ if (!isDomesticVendor) return
+ window.open("/api/juso", "jusoSearch", "width=570,height=420,scrollbars=yes,resizable=yes")
+ }
+
// 컴포넌트 언마운트 시 미리보기 URL 정리 (blob URL만)
React.useEffect(() => {
return () => {
@@ -1224,11 +1249,29 @@ export function InfoForm() {
name="address"
render={({ field }) => (
<FormItem>
- <FormLabel className="after:content-['*'] after:ml-0.5 after:text-red-500">
- 주소
- </FormLabel>
+ <div className="flex items-center justify-between gap-2">
+ <FormLabel className="after:content-['*'] after:ml-0.5 after:text-red-500">
+ 주소
+ </FormLabel>
+ {isDomesticVendor && (
+ <Button
+ type="button"
+ variant="secondary"
+ size="sm"
+ onClick={handleJusoSearch}
+ disabled={isSubmitting}
+ >
+ 주소 검색
+ </Button>
+ )}
+ </div>
<FormControl>
- <Input {...field} disabled={isSubmitting} />
+ <Input
+ {...field}
+ disabled={isSubmitting}
+ readOnly={isDomesticVendor}
+ className={cn(isDomesticVendor && "bg-muted text-muted-foreground")}
+ />
</FormControl>
<FormMessage />
</FormItem>
@@ -1258,7 +1301,13 @@ export function InfoForm() {
<FormItem>
<FormLabel>우편번호</FormLabel>
<FormControl>
- <Input {...field} disabled={isSubmitting} placeholder="우편번호를 입력해주세요" />
+ <Input
+ {...field}
+ disabled={isSubmitting}
+ readOnly={isDomesticVendor}
+ className={cn(isDomesticVendor && "bg-muted text-muted-foreground")}
+ placeholder="우편번호를 입력해주세요"
+ />
</FormControl>
<FormMessage />
</FormItem>
diff --git a/lib/rfq-last/approval-actions.ts b/lib/rfq-last/approval-actions.ts
index be435931..2f9d0843 100644
--- a/lib/rfq-last/approval-actions.ts
+++ b/lib/rfq-last/approval-actions.ts
@@ -8,6 +8,7 @@
import { ApprovalSubmissionSaga } from '@/lib/approval';
import { mapRfqSendToTemplateVariables } from './approval-handlers';
+import { prepareEmailAttachments } from './service';
interface RfqSendApprovalData {
// RFQ 기본 정보
@@ -95,7 +96,27 @@ export async function requestRfqSendWithApproval(data: RfqSendApprovalData) {
applicationReason: data.applicationReason,
});
- // 3. 결재 상신용 payload 구성
+ // 3. Knox 상신용 첨부파일 준비 (실제 파일 객체로 변환)
+ const emailAttachments = await prepareEmailAttachments(data.rfqId, data.attachmentIds);
+ type PreparedAttachment = {
+ filename?: string | null;
+ content: BlobPart;
+ contentType?: string | null;
+ };
+ const knoxAttachments = (emailAttachments as PreparedAttachment[])
+ .filter((att): att is PreparedAttachment => Boolean(att && att.content))
+ .map(
+ (att) =>
+ new File([att.content], att.filename || 'attachment', {
+ type: att.contentType || 'application/octet-stream',
+ })
+ );
+
+ if (knoxAttachments.length === 0) {
+ throw new Error('상신할 첨부파일을 준비하지 못했습니다.');
+ }
+
+ // 4. 결재 상신용 payload 구성
// ⚠️ cronjob 환경에서 실행되므로 currentUser 정보를 포함해야 함
const approvalPayload = {
rfqId: data.rfqId,
@@ -113,7 +134,7 @@ export async function requestRfqSendWithApproval(data: RfqSendApprovalData) {
},
};
- // 4. Saga로 결재 상신
+ // 5. Saga로 결재 상신
const saga = new ApprovalSubmissionSaga(
'rfq_send_with_attachments', // 핸들러 키
approvalPayload, // 결재 승인 후 실행될 데이터
@@ -128,6 +149,7 @@ export async function requestRfqSendWithApproval(data: RfqSendApprovalData) {
epId: data.currentUser.epId,
email: data.currentUser.email,
},
+ attachments: knoxAttachments,
}
);
diff --git a/lib/rfq-last/service.ts b/lib/rfq-last/service.ts
index 68cfdac7..23f5f63a 100644
--- a/lib/rfq-last/service.ts
+++ b/lib/rfq-last/service.ts
@@ -3349,7 +3349,7 @@ async function getProjectInfo(projectId: number) {
return project;
}
-async function prepareEmailAttachments(rfqId: number, attachmentIds: number[]) {
+export async function prepareEmailAttachments(rfqId: number, attachmentIds: number[]) {
const attachments = await db
.select({
attachment: rfqLastAttachments,
diff --git a/lib/rfq-last/vendor-response/editor/vendor-response-editor.tsx b/lib/rfq-last/vendor-response/editor/vendor-response-editor.tsx
index 8c70b8dd..18fc5d50 100644
--- a/lib/rfq-last/vendor-response/editor/vendor-response-editor.tsx
+++ b/lib/rfq-last/vendor-response/editor/vendor-response-editor.tsx
@@ -9,6 +9,14 @@ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/com
import { Button } from "@/components/ui/button"
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
import { Badge } from "@/components/ui/badge"
+import {
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+} from "@/components/ui/dialog"
import { toast } from "sonner"
import RfqInfoHeader from "./rfq-info-header"
import CommercialTermsForm from "./commercial-terms-form"
@@ -130,6 +138,7 @@ export default function VendorResponseEditor({
const [deletedAttachments, setDeletedAttachments] = useState<any[]>([])
const [uploadProgress, setUploadProgress] = useState(0) // 추가
const [currencyDecimalPlaces, setCurrencyDecimalPlaces] = useState<number>(2) // 통화별 소수점 자리수
+ const [confirmOpen, setConfirmOpen] = useState(false)
console.log(existingResponse,"existingResponse")
@@ -682,7 +691,7 @@ export default function VendorResponseEditor({
<Button
type="button"
variant="default"
- onClick={() => handleFormSubmit(true)} // 직접 핸들러 호출
+ onClick={() => setConfirmOpen(true)} // 제출 전 확인 다이얼로그
disabled={loading || !allContractsSigned || isSubmitted || activeTab !== 'attachments'}
>
{!allContractsSigned ? (
@@ -714,6 +723,39 @@ export default function VendorResponseEditor({
</Button>
</div>
+ {/* 최종 제출 확인 다이얼로그 */}
+ <Dialog open={confirmOpen} onOpenChange={setConfirmOpen}>
+ <DialogContent>
+ <DialogHeader>
+ <DialogTitle>최종 제출</DialogTitle>
+ <DialogDescription>
+ 최종 제출하시겠습니까?
+ </DialogDescription>
+ </DialogHeader>
+ <DialogFooter className="flex gap-2 sm:justify-end">
+ <Button
+ type="button"
+ variant="outline"
+ onClick={() => setConfirmOpen(false)}
+ disabled={loading}
+ >
+ 취소
+ </Button>
+ <Button
+ type="button"
+ variant="default"
+ onClick={() => {
+ setConfirmOpen(false)
+ handleFormSubmit(true)
+ }}
+ disabled={loading || !allContractsSigned || isSubmitted || activeTab !== 'attachments'}
+ >
+ 제출하기
+ </Button>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+
</div>
</form>
</FormProvider>
diff --git a/lib/techsales-rfq/approval-actions.ts b/lib/techsales-rfq/approval-actions.ts
index cf914592..c85a950f 100644
--- a/lib/techsales-rfq/approval-actions.ts
+++ b/lib/techsales-rfq/approval-actions.ts
@@ -97,7 +97,13 @@ export async function requestTechSalesRfqSendWithApproval(data: TechSalesRfqSend
applicationReason: data.applicationReason,
});
- // 5. 결재 상신용 payload 구성
+ // 5. Knox 상신용 첨부파일 준비
+ const knoxAttachments = await prepareKnoxDrmAttachments(data.drmAttachmentIds);
+ if (knoxAttachments.length === 0) {
+ throw new Error('상신할 DRM 첨부파일을 준비하지 못했습니다.');
+ }
+
+ // 6. 결재 상신용 payload 구성
const approvalPayload = {
rfqId: data.rfqId,
rfqCode: data.rfqCode,
@@ -112,7 +118,7 @@ export async function requestTechSalesRfqSendWithApproval(data: TechSalesRfqSend
},
};
- // 6. Saga로 결재 상신
+ // 7. Saga로 결재 상신
const saga = new ApprovalSubmissionSaga(
'tech_sales_rfq_send_with_drm', // 핸들러 키
approvalPayload, // 결재 승인 후 실행될 데이터
@@ -127,6 +133,7 @@ export async function requestTechSalesRfqSendWithApproval(data: TechSalesRfqSend
epId: data.currentUser.epId,
email: data.currentUser.email,
},
+ attachments: knoxAttachments,
}
);
@@ -171,6 +178,59 @@ function getTechSalesRevalidationPath(rfqType: "SHIP" | "TOP" | "HULL"): string
return "/evcp/budgetary-tech-sales-ship";
}
}
+
+/**
+ * Knox 상신용 DRM 첨부파일을 File 객체로 준비
+ */
+async function prepareKnoxDrmAttachments(attachmentIds: number[]): Promise<File[]> {
+ if (!attachmentIds || attachmentIds.length === 0) return [];
+
+ const db = (await import('@/db/db')).default;
+ const { techSalesAttachments } = await import('@/db/schema/techSales');
+ const { inArray } = await import('drizzle-orm');
+
+ const attachments = await db.query.techSalesAttachments.findMany({
+ where: inArray(techSalesAttachments.id, attachmentIds),
+ columns: {
+ id: true,
+ filePath: true,
+ originalFileName: true,
+ fileName: true,
+ fileType: true,
+ },
+ });
+
+ const baseUrl = process.env.NEXT_PUBLIC_BASE_URL || process.env.NEXT_PUBLIC_URL;
+ const files: File[] = [];
+
+ for (const attachment of attachments) {
+ if (!attachment.filePath || !baseUrl) {
+ console.error('[TechSales RFQ Approval] 첨부파일 경로나 BASE_URL이 없습니다.', attachment.id);
+ continue;
+ }
+
+ const fileUrl = `${baseUrl}${attachment.filePath}`;
+ const response = await fetch(fileUrl);
+
+ if (!response.ok) {
+ console.error(`[TechSales RFQ Approval] 첨부파일 다운로드 실패: ${fileUrl} (status: ${response.status})`);
+ continue;
+ }
+
+ const blob = await response.blob();
+ const file = new File(
+ [blob],
+ attachment.originalFileName || attachment.fileName || 'attachment',
+ {
+ type: attachment.fileType || blob.type || 'application/octet-stream',
+ }
+ );
+
+ files.push(file);
+ }
+
+ return files;
+}
/**
* 기술영업 RFQ DRM 첨부 해제 결재 상신
*
@@ -214,6 +274,12 @@ export async function requestRfqResendWithDrmApproval(data: {
applicationReason: data.applicationReason,
});
+ // DRM 첨부파일을 Knox 상신용 File 객체로 준비
+ const knoxAttachments = await prepareKnoxDrmAttachments(data.drmAttachmentIds);
+ if (knoxAttachments.length === 0) {
+ throw new Error('상신할 DRM 첨부파일을 준비하지 못했습니다.');
+ }
+
// 결재 payload 구성
const approvalPayload = {
rfqId: data.rfqId,
@@ -244,6 +310,7 @@ export async function requestRfqResendWithDrmApproval(data: {
epId: data.currentUser.epId,
email: data.currentUser.email,
},
+ attachments: knoxAttachments,
}
);