summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-12-09 03:04:05 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-12-09 03:04:05 +0000
commitb5c174429548a53e5c86a13bdbfc61516e5ee345 (patch)
tree4c3c6102c6e6357c6821446ddfe085bcff2291cf
parent1ea1dfa5c2684838d37ebfc58e3e8fd98c2dc60b (diff)
(최겸) 구매 구매자서명 내 삼성중공업 정보 입력 추가
-rw-r--r--app/[lng]/evcp/(evcp)/(master-data)/buyer-signature/page.tsx3
-rw-r--r--config/vendorInvestigationsColumnsConfig.ts1
-rw-r--r--db/schema/basicContractDocumnet.ts2
-rw-r--r--db/schema/pq.ts1
-rw-r--r--lib/bidding/vendor/partners-bidding-list-columns.tsx9
-rw-r--r--lib/general-contracts/service.ts23
-rw-r--r--lib/general-contracts/utils.ts10
-rw-r--r--lib/pq/pq-criteria/add-pq-dialog.tsx968
-rw-r--r--lib/pq/pq-criteria/update-pq-sheet.tsx952
-rw-r--r--lib/pq/pq-review-table-new/request-investigation-dialog.tsx48
-rw-r--r--lib/pq/pq-review-table-new/vendors-table-columns.tsx1
-rw-r--r--lib/pq/pq-review-table-new/vendors-table-toolbar-actions.tsx3
-rw-r--r--lib/pq/service.ts1
-rw-r--r--lib/shi-signature/buyer-signature.ts15
-rw-r--r--lib/shi-signature/signature-list.tsx10
-rw-r--r--lib/shi-signature/upload-form.tsx40
-rw-r--r--lib/vendor-investigation/table/investigation-progress-sheet.tsx47
17 files changed, 1159 insertions, 975 deletions
diff --git a/app/[lng]/evcp/(evcp)/(master-data)/buyer-signature/page.tsx b/app/[lng]/evcp/(evcp)/(master-data)/buyer-signature/page.tsx
index dfbd605b..5826b8d8 100644
--- a/app/[lng]/evcp/(evcp)/(master-data)/buyer-signature/page.tsx
+++ b/app/[lng]/evcp/(evcp)/(master-data)/buyer-signature/page.tsx
@@ -8,6 +8,7 @@ export default async function BuyerSignaturePage(props: { params: Promise<{ lng:
const { t } = await useTranslation(lng, 'menu')
const signatures = await getAllSignatures();
+ const activeSignature = signatures.find((signature) => signature.isActive);
return (
<div className="container mx-auto py-8 max-w-4xl">
@@ -19,7 +20,7 @@ export default async function BuyerSignaturePage(props: { params: Promise<{ lng:
</p>
</div>
- <BuyerSignatureUploadForm />
+ <BuyerSignatureUploadForm initialSignature={activeSignature} />
<SignatureList signatures={signatures} />
</div>
diff --git a/config/vendorInvestigationsColumnsConfig.ts b/config/vendorInvestigationsColumnsConfig.ts
index 7d74d8e0..0029b5a5 100644
--- a/config/vendorInvestigationsColumnsConfig.ts
+++ b/config/vendorInvestigationsColumnsConfig.ts
@@ -5,6 +5,7 @@ export type VendorInvestigationsViewRaw = {
// Investigation fields
investigationId: number
vendorId: number
+ vendorCountry: string | null
pqSubmissionId: number | null
requesterId: number | null
qmManagerId: number | null
diff --git a/db/schema/basicContractDocumnet.ts b/db/schema/basicContractDocumnet.ts
index 5edc9836..7c8d4bc5 100644
--- a/db/schema/basicContractDocumnet.ts
+++ b/db/schema/basicContractDocumnet.ts
@@ -284,6 +284,8 @@ export type BasicContractTemplateStatsView = typeof basicContractTemplateStatsVi
export const buyerSignatures = pgTable('buyer_signatures', {
id: integer("id").primaryKey().generatedAlwaysAsIdentity(),
name: varchar('name', { length: 255 }).notNull().default('삼성중공업'),
+ shiAddress: text('shi_address'),
+ shiCeoName: varchar('shi_ceo_name', { length: 255 }),
imageUrl: text('image_url').notNull(),
dataUrl: text('data_url'), // Base64 데이터
mimeType: varchar('mime_type', { length: 100 }),
diff --git a/db/schema/pq.ts b/db/schema/pq.ts
index 68c58613..e273f656 100644
--- a/db/schema/pq.ts
+++ b/db/schema/pq.ts
@@ -433,6 +433,7 @@ export const vendorInvestigationsView = pgView(
// Essential vendor fields
vendorName: vendors.vendorName,
vendorCode: vendors.vendorCode,
+ vendorCountry: vendors.country,
// PQ 정보
pqItems: vendorPQSubmissions.pqItems,
diff --git a/lib/bidding/vendor/partners-bidding-list-columns.tsx b/lib/bidding/vendor/partners-bidding-list-columns.tsx
index 09c3caad..c577ab89 100644
--- a/lib/bidding/vendor/partners-bidding-list-columns.tsx
+++ b/lib/bidding/vendor/partners-bidding-list-columns.tsx
@@ -174,7 +174,7 @@ export function getPartnersBiddingListColumns({ setRowAction }: PartnersBiddingL
const startDate = row.original.submissionStartDate ? new Date(row.original.submissionStartDate).toISOString().slice(0, 16) : null
const endDate = row.original.submissionEndDate ? new Date(row.original.submissionEndDate).toISOString().slice(0, 16) : null
console.log(startDate, endDate, "startDate, endDate")
- if (startDate && now < startDate) {
+ if (startDate && now < new Date (startDate)) {
toast.warning('입찰기간 전 접근 제한', {
description: `입찰기간이 아직 시작되지 않았습니다`,
duration: 5000,
@@ -249,9 +249,10 @@ export function getPartnersBiddingListColumns({ setRowAction }: PartnersBiddingL
// 입찰기간 체크 (현 시간 기준으로 입찰기간 시작 전이면 접근 불가)
const now = new Date()
- const startDate = row.original.submissionStartDate ? new Date(row.original.submissionStartDate) : null
-
- if (startDate && now < startDate) {
+ const startDate = row.original.submissionStartDate ? new Date(row.original.submissionStartDate).toISOString().slice(0, 16) : null
+ const endDate = row.original.submissionEndDate ? new Date(row.original.submissionEndDate).toISOString().slice(0, 16) : null
+ console.log(startDate, endDate, "startDate, endDate")
+ if (startDate && now < new Date (startDate)) {
toast.warning('입찰기간 전 접근 제한', {
description: `입찰기간이 아직 시작되지 않았습니다`,
duration: 5000,
diff --git a/lib/general-contracts/service.ts b/lib/general-contracts/service.ts
index b803d2d4..d0fa7b7a 100644
--- a/lib/general-contracts/service.ts
+++ b/lib/general-contracts/service.ts
@@ -7,7 +7,7 @@ import path from 'path'
import { promises as fs } from 'fs'
import { generalContracts, generalContractItems, generalContractAttachments } from '@/db/schema/generalContract'
import { contracts, contractItems, contractEnvelopes, contractSigners } from '@/db/schema/contract'
-import { basicContract, basicContractTemplates } from '@/db/schema/basicContractDocumnet'
+import { basicContract, basicContractTemplates, buyerSignatures } from '@/db/schema/basicContractDocumnet'
import { generalContractTemplates } from '@/db/schema'
import { vendors } from '@/db/schema/vendors'
import { users, roles, userRoles } from '@/db/schema/users'
@@ -21,6 +21,9 @@ import { v4 as uuidv4 } from 'uuid'
import { GetGeneralContractsSchema } from './validation'
import { sendEmail } from '../mail/sendEmail'
+const DEFAULT_SHI_ADDRESS = '경기도 성남시 분당구 판교로 227번길 23'
+const DEFAULT_SHI_CEO_NAME = '최성안'
+
export async function getGeneralContracts(input: GetGeneralContractsSchema) {
try {
const offset = (input.page - 1) * input.perPage
@@ -800,6 +803,16 @@ export async function getBasicInfo(contractId: number) {
}
const contract = result[0]
+ const [activeBuyerSignature] = await db
+ .select()
+ .from(buyerSignatures)
+ .where(eq(buyerSignatures.isActive, true))
+ .limit(1)
+
+ const shiAddress = activeBuyerSignature?.shiAddress || DEFAULT_SHI_ADDRESS
+ const shiCeoName = activeBuyerSignature?.shiCeoName || DEFAULT_SHI_CEO_NAME
+ const buyerSignatureName = activeBuyerSignature?.name || '삼성중공업'
+
return {
success: true,
enabled: true, // basic-info는 항상 활성화
@@ -844,7 +857,13 @@ export async function getBasicInfo(contractId: number) {
interlockingSystem: contract.interlockingSystem,
mandatoryDocuments: contract.mandatoryDocuments,
contractTerminationConditions: contract.contractTerminationConditions,
- externalYardEntry: contract.externalYardEntry || 'N'
+ externalYardEntry: contract.externalYardEntry || 'N',
+
+ // SHI 서명 정보
+ shiAddress,
+ shiCeoName,
+ buyerSignatureName,
+ buyerSignatureId: activeBuyerSignature?.id || null,
}
}
} catch (error) {
diff --git a/lib/general-contracts/utils.ts b/lib/general-contracts/utils.ts
index ec15a3a1..5bbb5980 100644
--- a/lib/general-contracts/utils.ts
+++ b/lib/general-contracts/utils.ts
@@ -1,5 +1,8 @@
import { format } from "date-fns"
+const DEFAULT_SHI_ADDRESS = "경기도 성남시 분당구 판교로 227번길 23"
+const DEFAULT_SHI_CEO_NAME = "최성안"
+
/**
* ContractSummary 인터페이스 (UI 컴포넌트와 맞춤)
*/
@@ -20,6 +23,9 @@ export function mapContractDataToTemplateVariables(contractSummary: ContractSumm
const { basicInfo, items, storageInfo } = contractSummary
const firstItem = items && items.length > 0 ? items[0] : {}
+ const shiAddress = basicInfo.shiAddress || DEFAULT_SHI_ADDRESS
+ const shiCeoName = basicInfo.shiCeoName || DEFAULT_SHI_CEO_NAME
+
// 날짜 포맷팅 헬퍼 (YYYY-MM-DD)
const formatDate = (date: any) => {
if (!date) return ''
@@ -206,8 +212,8 @@ export function mapContractDataToTemplateVariables(contractSummary: ContractSumm
// ----------------------------------
// 당사(SHI) 정보 (고정값/설정값)
// ----------------------------------
- shiAddress: "경기도 성남시 분당구 판교로 227번길 23", // {{SHI_Address}}, {{위탁자 주소}}
- shiCeoName: "최성안", // {{SHI_CEO_Name}}, {{대표이사}}
+ shiAddress: shiAddress, // {{SHI_Address}}, {{위탁자 주소}}
+ shiCeoName: shiCeoName, // {{SHI_CEO_Name}}, {{대표이사}}
// ----------------------------------
// 품목 정보
diff --git a/lib/pq/pq-criteria/add-pq-dialog.tsx b/lib/pq/pq-criteria/add-pq-dialog.tsx
index 1752f503..144e5ce4 100644
--- a/lib/pq/pq-criteria/add-pq-dialog.tsx
+++ b/lib/pq/pq-criteria/add-pq-dialog.tsx
@@ -1,485 +1,485 @@
-"use client"
-
-import * as React from "react"
-import { useForm } from "react-hook-form"
-import { zodResolver } from "@hookform/resolvers/zod"
-import { z } from "zod"
-import { Plus } from "lucide-react"
-import { useRouter } from "next/navigation"
-
-import {
- Dialog,
- DialogTrigger,
- DialogContent,
- DialogHeader,
- DialogTitle,
- DialogDescription,
- DialogFooter
-} from "@/components/ui/dialog"
-import { Button } from "@/components/ui/button"
-import { Input } from "@/components/ui/input"
-import { Textarea } from "@/components/ui/textarea"
-import {
- Form,
- FormControl,
- FormDescription,
- FormField,
- FormItem,
- FormLabel,
- FormMessage,
-} from "@/components/ui/form"
-import {
- Select,
- SelectContent,
- SelectItem,
- SelectTrigger,
- SelectValue,
-} from "@/components/ui/select"
-
-import { useToast } from "@/hooks/use-toast"
-import { createPqCriteria } from "../service"
-import { uploadPqCriteriaFileAction } from "@/lib/pq/service"
-import { Dropzone, DropzoneInput, DropzoneZone, DropzoneUploadIcon, DropzoneTitle, DropzoneDescription } from "@/components/ui/dropzone"
-import { FileList, FileListHeader, FileListInfo, FileListItem, FileListName, FileListDescription, FileListAction } from "@/components/ui/file-list"
-import { X, Loader2 } from "lucide-react"
-
-// PQ 생성을 위한 Zod 스키마 정의
-const createPqSchema = z.object({
- code: z.string().min(1, "Code is required"),
- checkPoint: z.string().min(1, "Check point is required"),
- groupName: z.string().min(1, "Group is required"),
- subGroupName: z.string().optional(),
- description: z.string().optional(),
- remarks: z.string().optional(),
- inputFormat: z.string().default("TEXT"),
- type: z.string().optional(),
-});
-
-type CreatePqFormType = z.infer<typeof createPqSchema>;
-
-// 그룹 이름 옵션
-export const groupOptions = [
- "GENERAL",
- "QMS",
- "Warranty",
- "HSE+",
- "기타",
-];
-
-// 입력 형식 옵션
-const inputFormatOptions = [
- { value: "TEXT", label: "텍스트" },
- { value: "FILE", label: "파일" },
- { value: "EMAIL", label: "이메일" },
- { value: "PHONE", label: "전화번호" },
- { value: "FAX", label: "팩스번호" },
- { value: "NUMBER", label: "숫자" },
- { value: "NUMBER_WITH_UNIT", label: "숫자+단위" },
- { value: "TEXT_FILE", label: "텍스트 + 파일" },
-];
-
-const typeOptions = [
- { value: "내자", label: "내자" },
- { value: "외자", label: "외자" },
- { value: "내외자", label: "내외자" },
-];
-
-interface AddPqDialogProps {
- pqListId: number;
-}
-
-export function AddPqDialog({ pqListId }: AddPqDialogProps) {
- const [open, setOpen] = React.useState(false)
- const [isSubmitting, setIsSubmitting] = React.useState(false)
- const [isUploading, setIsUploading] = React.useState(false)
- const [uploadedFiles, setUploadedFiles] = React.useState<
- { fileName: string; url: string; size?: number; originalFileName?: string }[]
- >([])
- const router = useRouter()
- const { toast } = useToast()
-
- // react-hook-form 설정
- const form = useForm<CreatePqFormType>({
- resolver: zodResolver(createPqSchema),
- defaultValues: {
- code: "",
- checkPoint: "",
- groupName: groupOptions[0],
- subGroupName: "",
- description: "",
- remarks: "",
- inputFormat: "TEXT",
- type: "내외자",
- },
- })
- const formState = form.formState
-
- async function onSubmit(data: CreatePqFormType) {
- try {
- setIsSubmitting(true)
-
- // 서버 액션 호출
- const result = await createPqCriteria(pqListId, {
- ...data,
- attachments: uploadedFiles,
- })
-
- if (!result.success) {
- toast({
- title: "오류",
- description: result.message || "PQ 항목 생성에 실패했습니다",
- variant: "destructive",
- })
- return
- }
-
- // 성공 시 처리
- toast({
- title: "성공",
- description: result.message || "PQ 항목이 성공적으로 생성되었습니다",
- })
-
- // 모달 닫고 폼 리셋
- form.reset()
- setUploadedFiles([])
- setOpen(false)
-
- // 페이지 새로고침
- router.refresh()
-
- } catch (error) {
- console.error('Error creating PQ criteria:', error)
- toast({
- title: "오류",
- description: "예상치 못한 오류가 발생했습니다",
- variant: "destructive",
- })
- } finally {
- setIsSubmitting(false)
- }
- }
-
- function handleDialogOpenChange(nextOpen: boolean) {
- if (!nextOpen) {
- form.reset()
- setUploadedFiles([])
- }
- setOpen(nextOpen)
- }
-
- const handleUpload = async (files: File[]) => {
- try {
- setIsUploading(true)
- for (const file of files) {
- const uploaded = await uploadPqCriteriaFileAction(file)
- setUploadedFiles((prev) => [...prev, uploaded])
- }
- toast({
- title: "업로드 완료",
- description: "첨부파일이 업로드되었습니다.",
- })
- } catch (error) {
- console.error(error)
- toast({
- title: "업로드 실패",
- description: "첨부파일 업로드 중 오류가 발생했습니다.",
- variant: "destructive",
- })
- } finally {
- setIsUploading(false)
- }
- }
-
- return (
- <Dialog open={open} onOpenChange={handleDialogOpenChange}>
- <DialogTrigger asChild>
- <Button variant="default" size="sm">
- <Plus className="size-4" />
- Add PQ
- </Button>
- </DialogTrigger>
-
- <DialogContent className="sm:max-w-[600px] max-h-[80vh] flex flex-col">
- <DialogHeader>
- <DialogTitle>PQ 항목 생성</DialogTitle>
- <DialogDescription>
- 새 PQ 항목을 추가합니다.
- </DialogDescription>
- </DialogHeader>
-
- <Form {...form}>
- <form onSubmit={form.handleSubmit(onSubmit)} className="flex-1 overflow-auto space-y-4">
- <div className="space-y-4 px-1">
- {/* Group Name 필드 */}
- <FormField
- control={form.control}
- name="groupName"
- render={({ field }) => (
- <FormItem>
- <FormLabel>대분류 <span className="text-destructive">*</span></FormLabel>
- <Select onValueChange={field.onChange} defaultValue={field.value}>
- <FormControl>
- <SelectTrigger>
- <SelectValue placeholder="그룹을 선택하세요" />
- </SelectTrigger>
- </FormControl>
- <SelectContent>
- {groupOptions.map((group) => (
- <SelectItem key={group} value={group}>
- {group}
- </SelectItem>
- ))}
- </SelectContent>
- </Select>
- <FormMessage />
- </FormItem>
- )}
- />
-
- {/* Sub Group Name 필드 */}
- <FormField
- control={form.control}
- name="subGroupName"
- render={({ field }) => (
- <FormItem>
- <FormLabel>소분류</FormLabel>
- <FormControl>
- <Input
- placeholder="서브 그룹명을 입력하세요"
- {...field}
- value={field.value || ""}
- />
- </FormControl>
- <FormDescription>
- 세부 분류를 위한 서브 그룹명을 입력하세요 (선택사항)
- </FormDescription>
- <FormMessage />
- </FormItem>
- )}
- />
- {/* Code 필드 */}
- <FormField
- control={form.control}
- name="code"
- render={({ field }) => (
- <FormItem>
- <FormLabel>일련번호 <span className="text-destructive">*</span></FormLabel>
- <FormControl>
- <Input
- placeholder="예: 1-1, A.2.3"
- {...field}
- />
- </FormControl>
- <FormDescription>
- PQ 항목의 고유 코드를 입력하세요
- </FormDescription>
- <FormMessage />
- </FormItem>
- )}
- />
- {/* Check Point 필드 */}
- <FormField
- control={form.control}
- name="checkPoint"
- render={({ field }) => (
- <FormItem>
- <FormLabel>PQ 항목 <span className="text-destructive">*</span></FormLabel>
- <FormControl>
- <Input
- placeholder="PQ 항목을 입력하세요"
- {...field}
- />
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
-
- {/* Type 필드 */}
- <FormField
- control={form.control}
- name="type"
- render={({ field }) => (
- <FormItem>
- <FormLabel>내/외자 구분</FormLabel>
- <Select onValueChange={field.onChange} value={field.value}>
- <FormControl>
- <SelectTrigger>
- <SelectValue placeholder="구분을 선택하세요" />
- </SelectTrigger>
- </FormControl>
- <SelectContent>
- {typeOptions.map((option) => (
- <SelectItem key={option.value} value={option.value}>
- {option.label}
- </SelectItem>
- ))}
- </SelectContent>
- </Select>
- <FormDescription>미선택 시 기본값은 내외자입니다.</FormDescription>
- <FormMessage />
- </FormItem>
- )}
- />
-
- {/* Input Format 필드 */}
- <FormField
- control={form.control}
- name="inputFormat"
- render={({ field }) => (
- <FormItem>
- <FormLabel>협력업체 입력사항 <span className="text-destructive">*</span></FormLabel>
- <Select onValueChange={field.onChange} defaultValue={field.value}>
- <FormControl>
- <SelectTrigger>
- <SelectValue placeholder="입력 형식을 선택하세요" />
- </SelectTrigger>
- </FormControl>
- <SelectContent>
- {inputFormatOptions.map((option) => (
- <SelectItem key={option.value} value={option.value}>
- {option.label}
- </SelectItem>
- ))}
- </SelectContent>
- </Select>
- <FormMessage />
- </FormItem>
- )}
- />
-
- {/* 첨부 파일 업로드 */}
- <div className="space-y-2">
- <div className="flex items-center justify-between">
- <FormLabel>첨부 파일</FormLabel>
- {isUploading && (
- <div className="flex items-center text-xs text-muted-foreground">
- <Loader2 className="mr-1 h-3 w-3 animate-spin" /> 업로드 중...
- </div>
- )}
- </div>
- <Dropzone
- maxSize={6e8}
- onDropAccepted={(files) => handleUpload(files)}
- onDropRejected={() =>
- toast({
- title: "업로드 실패",
- description: "파일 크기/형식을 확인하세요.",
- variant: "destructive",
- })
- }
- disabled={isUploading}
- >
- {() => (
- <FormItem>
- <DropzoneZone className="flex justify-center h-28">
- <FormControl>
- <DropzoneInput />
- </FormControl>
- <div className="flex items-center gap-4">
- <DropzoneUploadIcon />
- <div className="grid gap-0.5">
- <DropzoneTitle>파일을 드래그하거나 클릭하여 업로드</DropzoneTitle>
- <DropzoneDescription>PDF, 이미지, 문서 (최대 600MB)</DropzoneDescription>
- </div>
- </div>
- </DropzoneZone>
- <FormDescription>기준 문서 첨부가 필요한 경우 업로드하세요.</FormDescription>
- </FormItem>
- )}
- </Dropzone>
-
- {uploadedFiles.length > 0 && (
- <div className="space-y-2">
- <p className="text-sm font-medium">첨부된 파일 ({uploadedFiles.length})</p>
- <FileList>
- {uploadedFiles.map((file, idx) => (
- <FileListItem key={idx}>
- <FileListHeader>
- <FileListInfo>
- <FileListName>{file.originalFileName || file.fileName}</FileListName>
- {file.size && (
- <FileListDescription>{`${file.size} bytes`}</FileListDescription>
- )}
- </FileListInfo>
- <FileListAction
- onClick={() =>
- setUploadedFiles((prev) => prev.filter((_, i) => i !== idx))
- }
- >
- <X className="h-4 w-4" />
- <span className="sr-only">Remove</span>
- </FileListAction>
- </FileListHeader>
- </FileListItem>
- ))}
- </FileList>
- </div>
- )}
- </div>
-
- {/* Description 필드 */}
- <FormField
- control={form.control}
- name="description"
- render={({ field }) => (
- <FormItem>
- <FormLabel>설명</FormLabel>
- <FormControl>
- <Textarea
- placeholder="상세 설명을 입력하세요"
- className="min-h-[100px]"
- {...field}
- value={field.value || ""}
- />
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
-
- {/* Remarks 필드 */}
- <FormField
- control={form.control}
- name="remarks"
- render={({ field }) => (
- <FormItem>
- <FormLabel>비고</FormLabel>
- <FormControl>
- <Textarea
- placeholder="비고 사항을 입력하세요"
- className="min-h-[80px]"
- {...field}
- value={field.value || ""}
- />
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
- </div>
-
- <DialogFooter>
- <Button
- type="button"
- variant="outline"
- onClick={() => {
- form.reset();
- setOpen(false);
- }}
- >
- 취소
- </Button>
- <Button
- type="submit"
- disabled={isSubmitting || !formState.isValid}
- >
- {isSubmitting ? "생성 중..." : "생성"}
- </Button>
- </DialogFooter>
- </form>
- </Form>
- </DialogContent>
- </Dialog>
- )
+"use client"
+
+import * as React from "react"
+import { useForm } from "react-hook-form"
+import { zodResolver } from "@hookform/resolvers/zod"
+import { z } from "zod"
+import { Plus } from "lucide-react"
+import { useRouter } from "next/navigation"
+
+import {
+ Dialog,
+ DialogTrigger,
+ DialogContent,
+ DialogHeader,
+ DialogTitle,
+ DialogDescription,
+ DialogFooter
+} from "@/components/ui/dialog"
+import { Button } from "@/components/ui/button"
+import { Input } from "@/components/ui/input"
+import { Textarea } from "@/components/ui/textarea"
+import {
+ Form,
+ FormControl,
+ FormDescription,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+} from "@/components/ui/form"
+import {
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from "@/components/ui/select"
+
+import { useToast } from "@/hooks/use-toast"
+import { createPqCriteria } from "../service"
+import { uploadPqCriteriaFileAction } from "@/lib/pq/service"
+import { Dropzone, DropzoneInput, DropzoneZone, DropzoneUploadIcon, DropzoneTitle, DropzoneDescription } from "@/components/ui/dropzone"
+import { FileList, FileListHeader, FileListInfo, FileListItem, FileListName, FileListDescription, FileListAction } from "@/components/ui/file-list"
+import { X, Loader2 } from "lucide-react"
+
+// PQ 생성을 위한 Zod 스키마 정의
+const createPqSchema = z.object({
+ code: z.string().min(1, "Code is required"),
+ checkPoint: z.string().min(1, "Check point is required"),
+ groupName: z.string().min(1, "Group is required"),
+ subGroupName: z.string().optional(),
+ description: z.string().optional(),
+ remarks: z.string().optional(),
+ inputFormat: z.string().default("TEXT"),
+ type: z.string().optional(),
+});
+
+type CreatePqFormType = z.infer<typeof createPqSchema>;
+
+// 그룹 이름 옵션
+export const groupOptions = [
+ "GENERAL",
+ "QMS",
+ "Warranty",
+ "HSE+",
+ "기타",
+];
+
+// 입력 형식 옵션
+const inputFormatOptions = [
+ { value: "TEXT", label: "텍스트" },
+ { value: "FILE", label: "파일" },
+ { value: "EMAIL", label: "이메일" },
+ { value: "PHONE", label: "전화번호" },
+ { value: "FAX", label: "팩스번호" },
+ { value: "NUMBER", label: "숫자" },
+ { value: "NUMBER_WITH_UNIT", label: "숫자+단위" },
+ { value: "TEXT_FILE", label: "텍스트 + 파일" },
+];
+
+const typeOptions = [
+ { value: "내자", label: "내자" },
+ { value: "외자", label: "외자" },
+ { value: "내외자", label: "내외자" },
+];
+
+interface AddPqDialogProps {
+ pqListId: number;
+}
+
+export function AddPqDialog({ pqListId }: AddPqDialogProps) {
+ const [open, setOpen] = React.useState(false)
+ const [isSubmitting, setIsSubmitting] = React.useState(false)
+ const [isUploading, setIsUploading] = React.useState(false)
+ const [uploadedFiles, setUploadedFiles] = React.useState<
+ { fileName: string; url: string; size?: number; originalFileName?: string }[]
+ >([])
+ const router = useRouter()
+ const { toast } = useToast()
+
+ // react-hook-form 설정
+ const form = useForm<CreatePqFormType>({
+ resolver: zodResolver(createPqSchema),
+ defaultValues: {
+ code: "",
+ checkPoint: "",
+ groupName: groupOptions[0],
+ subGroupName: "",
+ description: "",
+ remarks: "",
+ inputFormat: "TEXT",
+ type: "내외자",
+ },
+ })
+ const formState = form.formState
+
+ async function onSubmit(data: CreatePqFormType) {
+ try {
+ setIsSubmitting(true)
+
+ // 서버 액션 호출
+ const result = await createPqCriteria(pqListId, {
+ ...data,
+ attachments: uploadedFiles,
+ })
+
+ if (!result.success) {
+ toast({
+ title: "오류",
+ description: result.message || "PQ 항목 생성에 실패했습니다",
+ variant: "destructive",
+ })
+ return
+ }
+
+ // 성공 시 처리
+ toast({
+ title: "성공",
+ description: result.message || "PQ 항목이 성공적으로 생성되었습니다",
+ })
+
+ // 모달 닫고 폼 리셋
+ form.reset()
+ setUploadedFiles([])
+ setOpen(false)
+
+ // 페이지 새로고침
+ router.refresh()
+
+ } catch (error) {
+ console.error('Error creating PQ criteria:', error)
+ toast({
+ title: "오류",
+ description: "예상치 못한 오류가 발생했습니다",
+ variant: "destructive",
+ })
+ } finally {
+ setIsSubmitting(false)
+ }
+ }
+
+ function handleDialogOpenChange(nextOpen: boolean) {
+ if (!nextOpen) {
+ form.reset()
+ setUploadedFiles([])
+ }
+ setOpen(nextOpen)
+ }
+
+ const handleUpload = async (files: File[]) => {
+ try {
+ setIsUploading(true)
+ for (const file of files) {
+ const uploaded = await uploadPqCriteriaFileAction(file)
+ setUploadedFiles((prev) => [...prev, uploaded])
+ }
+ toast({
+ title: "업로드 완료",
+ description: "첨부파일이 업로드되었습니다.",
+ })
+ } catch (error) {
+ console.error(error)
+ toast({
+ title: "업로드 실패",
+ description: "첨부파일 업로드 중 오류가 발생했습니다.",
+ variant: "destructive",
+ })
+ } finally {
+ setIsUploading(false)
+ }
+ }
+
+ return (
+ <Dialog open={open} onOpenChange={handleDialogOpenChange}>
+ <DialogTrigger asChild>
+ <Button variant="default" size="sm">
+ <Plus className="size-4" />
+ Add PQ
+ </Button>
+ </DialogTrigger>
+
+ <DialogContent className="sm:max-w-[600px] max-h-[80vh] flex flex-col">
+ <DialogHeader>
+ <DialogTitle>PQ 항목 생성</DialogTitle>
+ <DialogDescription>
+ 새 PQ 항목을 추가합니다.
+ </DialogDescription>
+ </DialogHeader>
+
+ <Form {...form}>
+ <form onSubmit={form.handleSubmit(onSubmit)} className="flex-1 overflow-auto space-y-4">
+ <div className="space-y-4 px-1">
+ {/* Group Name 필드 */}
+ <FormField
+ control={form.control}
+ name="groupName"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>대분류 <span className="text-destructive">*</span></FormLabel>
+ <Select onValueChange={field.onChange} defaultValue={field.value}>
+ <FormControl>
+ <SelectTrigger>
+ <SelectValue placeholder="그룹을 선택하세요" />
+ </SelectTrigger>
+ </FormControl>
+ <SelectContent>
+ {groupOptions.map((group) => (
+ <SelectItem key={group} value={group}>
+ {group}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+
+ {/* Sub Group Name 필드 */}
+ <FormField
+ control={form.control}
+ name="subGroupName"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>소분류</FormLabel>
+ <FormControl>
+ <Input
+ placeholder="서브 그룹명을 입력하세요"
+ {...field}
+ value={field.value || ""}
+ />
+ </FormControl>
+ <FormDescription>
+ 세부 분류를 위한 서브 그룹명을 입력하세요 (선택사항)
+ </FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ {/* Code 필드 */}
+ <FormField
+ control={form.control}
+ name="code"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>일련번호 <span className="text-destructive">*</span></FormLabel>
+ <FormControl>
+ <Input
+ placeholder="예: 1-1, A.2.3"
+ {...field}
+ />
+ </FormControl>
+ <FormDescription>
+ PQ 항목의 고유 코드를 입력하세요
+ </FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ {/* Check Point 필드 */}
+ <FormField
+ control={form.control}
+ name="checkPoint"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>PQ 항목 <span className="text-destructive">*</span></FormLabel>
+ <FormControl>
+ <Input
+ placeholder="PQ 항목을 입력하세요"
+ {...field}
+ />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+
+ {/* Type 필드 */}
+ <FormField
+ control={form.control}
+ name="type"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>내/외자 구분</FormLabel>
+ <Select onValueChange={field.onChange} value={field.value}>
+ <FormControl>
+ <SelectTrigger>
+ <SelectValue placeholder="구분을 선택하세요" />
+ </SelectTrigger>
+ </FormControl>
+ <SelectContent>
+ {typeOptions.map((option) => (
+ <SelectItem key={option.value} value={option.value}>
+ {option.label}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ <FormDescription>미선택 시 기본값은 내외자입니다.</FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+
+ {/* Input Format 필드 */}
+ <FormField
+ control={form.control}
+ name="inputFormat"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>협력업체 입력사항 <span className="text-destructive">*</span></FormLabel>
+ <Select onValueChange={field.onChange} defaultValue={field.value}>
+ <FormControl>
+ <SelectTrigger>
+ <SelectValue placeholder="입력 형식을 선택하세요" />
+ </SelectTrigger>
+ </FormControl>
+ <SelectContent>
+ {inputFormatOptions.map((option) => (
+ <SelectItem key={option.value} value={option.value}>
+ {option.label}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+
+ {/* 첨부 파일 업로드 */}
+ <div className="space-y-2">
+ <div className="flex items-center justify-between">
+ <FormLabel>첨부 파일</FormLabel>
+ {isUploading && (
+ <div className="flex items-center text-xs text-muted-foreground">
+ <Loader2 className="mr-1 h-3 w-3 animate-spin" /> 업로드 중...
+ </div>
+ )}
+ </div>
+ <Dropzone
+ maxSize={6e8}
+ onDropAccepted={(files) => handleUpload(files)}
+ onDropRejected={() =>
+ toast({
+ title: "업로드 실패",
+ description: "파일 크기/형식을 확인하세요.",
+ variant: "destructive",
+ })
+ }
+ disabled={isUploading}
+ >
+ {() => (
+ <FormItem>
+ <DropzoneZone className="flex justify-center h-28">
+ <FormControl>
+ <DropzoneInput />
+ </FormControl>
+ <div className="flex items-center gap-4">
+ <DropzoneUploadIcon />
+ <div className="grid gap-0.5">
+ <DropzoneTitle>파일을 드래그하거나 클릭하여 업로드</DropzoneTitle>
+ <DropzoneDescription>PDF, 이미지, 문서 (최대 600MB)</DropzoneDescription>
+ </div>
+ </div>
+ </DropzoneZone>
+ <FormDescription>기준 문서 첨부가 필요한 경우 업로드하세요.</FormDescription>
+ </FormItem>
+ )}
+ </Dropzone>
+
+ {uploadedFiles.length > 0 && (
+ <div className="space-y-2">
+ <p className="text-sm font-medium">첨부된 파일 ({uploadedFiles.length})</p>
+ <FileList>
+ {uploadedFiles.map((file, idx) => (
+ <FileListItem key={idx}>
+ <FileListHeader>
+ <FileListInfo>
+ <FileListName>{file.originalFileName || file.fileName}</FileListName>
+ {file.size && (
+ <FileListDescription>{`${file.size} bytes`}</FileListDescription>
+ )}
+ </FileListInfo>
+ <FileListAction
+ onClick={() =>
+ setUploadedFiles((prev) => prev.filter((_, i) => i !== idx))
+ }
+ >
+ <X className="h-4 w-4" />
+ <span className="sr-only">Remove</span>
+ </FileListAction>
+ </FileListHeader>
+ </FileListItem>
+ ))}
+ </FileList>
+ </div>
+ )}
+ </div>
+
+ {/* Description 필드 */}
+ <FormField
+ control={form.control}
+ name="description"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>설명</FormLabel>
+ <FormControl>
+ <Textarea
+ placeholder="상세 설명을 입력하세요"
+ className="min-h-[100px]"
+ {...field}
+ value={field.value || ""}
+ />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+
+ {/* Remarks 필드 */}
+ <FormField
+ control={form.control}
+ name="remarks"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>비고</FormLabel>
+ <FormControl>
+ <Textarea
+ placeholder="비고 사항을 입력하세요"
+ className="min-h-[80px]"
+ {...field}
+ value={field.value || ""}
+ />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </div>
+
+ <DialogFooter>
+ <Button
+ type="button"
+ variant="outline"
+ onClick={() => {
+ form.reset();
+ setOpen(false);
+ }}
+ >
+ 취소
+ </Button>
+ <Button
+ type="submit"
+ disabled={isSubmitting || !formState.isValid}
+ >
+ {isSubmitting ? "생성 중..." : "생성"}
+ </Button>
+ </DialogFooter>
+ </form>
+ </Form>
+ </DialogContent>
+ </Dialog>
+ )
} \ No newline at end of file
diff --git a/lib/pq/pq-criteria/update-pq-sheet.tsx b/lib/pq/pq-criteria/update-pq-sheet.tsx
index 6aeb689f..1d8092cd 100644
--- a/lib/pq/pq-criteria/update-pq-sheet.tsx
+++ b/lib/pq/pq-criteria/update-pq-sheet.tsx
@@ -1,477 +1,477 @@
-"use client"
-
-import * as React from "react"
-import { zodResolver } from "@hookform/resolvers/zod"
-import { Loader, Save } from "lucide-react"
-import { useForm } from "react-hook-form"
-import { toast } from "sonner"
-import { z } from "zod"
-import { useRouter } from "next/navigation"
-
-import { Button } from "@/components/ui/button"
-import {
- Form,
- FormControl,
- FormDescription,
- FormField,
- FormItem,
- FormLabel,
- FormMessage,
-} from "@/components/ui/form"
-import {
- Select,
- SelectContent,
- // SelectGroup,
- SelectItem,
- SelectTrigger,
- SelectValue,
-} from "@/components/ui/select"
-import {
- Sheet,
- SheetClose,
- SheetContent,
- SheetDescription,
- SheetFooter,
- SheetHeader,
- SheetTitle,
-} from "@/components/ui/sheet"
-import { Input } from "@/components/ui/input"
-import { Textarea } from "@/components/ui/textarea"
-
-import { updatePqCriteria } from "../service"
-import { groupOptions } from "./add-pq-dialog"
-import { Checkbox } from "@/components/ui/checkbox"
-import { uploadPqCriteriaFileAction, getPqCriteriaAttachments } from "@/lib/pq/service"
-import { Dropzone, DropzoneInput, DropzoneZone, DropzoneUploadIcon, DropzoneTitle, DropzoneDescription } from "@/components/ui/dropzone"
-import { FileList, FileListHeader, FileListInfo, FileListItem, FileListName, FileListDescription, FileListAction } from "@/components/ui/file-list"
-import { X, Loader2 } from "lucide-react"
-
-// PQ 수정을 위한 Zod 스키마 정의
-const updatePqSchema = z.object({
- code: z.string().min(1, "Code is required"),
- checkPoint: z.string().min(1, "Check point is required"),
- groupName: z.string().min(1, "Group is required"),
- description: z.string().optional(),
- remarks: z.string().optional(),
- inputFormat: z.string().default("TEXT"),
-
- subGroupName: z.string().optional(),
- type: z.string().optional(),
-});
-
-type UpdatePqSchema = z.infer<typeof updatePqSchema>;
-
-// 입력 형식 옵션
-const inputFormatOptions = [
- { value: "TEXT", label: "텍스트" },
- { value: "FILE", label: "파일" },
- { value: "EMAIL", label: "이메일" },
- { value: "PHONE", label: "전화번호" },
- { value: "NUMBER", label: "숫자" },
- { value: "NUMBER_WITH_UNIT", label: "숫자+단위" },
- { value: "TEXT_FILE", label: "텍스트 + 파일" }
-];
-
-const typeOptions = [
- { value: "내자", label: "내자" },
- { value: "외자", label: "외자" },
- { value: "내외자", label: "내외자" },
-];
-
-interface UpdatePqSheetProps
- extends React.ComponentPropsWithRef<typeof Sheet> {
- pq: {
- id: number;
- code: string;
- checkPoint: string;
- description: string | null;
- remarks: string | null;
- groupName: string | null;
- inputFormat: string;
-
- subGroupName: string | null;
- type?: string | null;
- } | null
-}
-
-export function UpdatePqSheet({ pq, ...props }: UpdatePqSheetProps) {
- const [isUpdatePending, startUpdateTransition] = React.useTransition()
- const [isUploading, setIsUploading] = React.useState(false)
- const [attachments, setAttachments] = React.useState<
- { fileName: string; url: string; size?: number; originalFileName?: string }[]
- >([])
- const router = useRouter()
-
- const form = useForm<UpdatePqSchema>({
- resolver: zodResolver(updatePqSchema),
- defaultValues: {
- code: pq?.code ?? "",
- checkPoint: pq?.checkPoint ?? "",
- groupName: pq?.groupName ?? groupOptions[0],
- description: pq?.description ?? "",
- remarks: pq?.remarks ?? "",
- inputFormat: pq?.inputFormat ?? "TEXT",
-
- subGroupName: pq?.subGroupName ?? "",
- type: pq?.type ?? "내외자",
- },
- })
-
- // 폼 초기화 (pq가 변경될 때)
- React.useEffect(() => {
- if (pq) {
- form.reset({
- code: pq.code,
- checkPoint: pq.checkPoint,
- groupName: pq.groupName ?? groupOptions[0],
- description: pq.description ?? "",
- remarks: pq.remarks ?? "",
- inputFormat: pq.inputFormat ?? "TEXT",
-
- subGroupName: pq.subGroupName ?? "",
- type: pq.type ?? "내외자",
- });
-
- // 기존 첨부 로드
- getPqCriteriaAttachments(pq.id).then((res) => {
- if (res.success && res.data) {
- setAttachments(
- res.data.map((a) => ({
- fileName: a.fileName,
- url: a.filePath,
- size: a.fileSize ?? undefined,
- originalFileName: a.originalFileName || a.fileName,
- }))
- )
- } else {
- setAttachments([])
- }
- })
- }
- }, [pq, form]);
-
- const handleUpload = async (files: File[]) => {
- try {
- setIsUploading(true)
- for (const file of files) {
- const uploaded = await uploadPqCriteriaFileAction(file)
- setAttachments((prev) => [...prev, uploaded])
- }
- toast.success("첨부파일이 업로드되었습니다")
- } catch (error) {
- console.error(error)
- toast.error("첨부파일 업로드에 실패했습니다")
- } finally {
- setIsUploading(false)
- }
- }
-
- function onSubmit(input: UpdatePqSchema) {
- startUpdateTransition(async () => {
- if (!pq) return
-
- const result = await updatePqCriteria(pq.id, {
- ...input,
- attachments,
- })
-
- if (!result.success) {
- toast.error(result.message || "PQ 항목 수정에 실패했습니다")
- return
- }
-
- toast.success(result.message || "PQ 항목이 성공적으로 수정되었습니다")
- form.reset()
- props.onOpenChange?.(false)
- router.refresh()
- })
- }
- return (
- <Sheet {...props}>
- <SheetContent className="flex flex-col gap-6 sm:max-w-md">
- <SheetHeader className="text-left">
- <SheetTitle>Update PQ Criteria</SheetTitle>
- <SheetDescription>
- Update the PQ criteria details and save the changes
- </SheetDescription>
- </SheetHeader>
- <Form {...form}>
- <form
- onSubmit={form.handleSubmit(onSubmit)}
- className="flex flex-col gap-4"
- >
- {/* Code 필드 */}
- <FormField
- control={form.control}
- name="code"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Code <span className="text-destructive">*</span></FormLabel>
- <FormControl>
- <Input
- placeholder="예: 1-1, A.2.3"
- {...field}
- />
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
-
- {/* Check Point 필드 */}
- <FormField
- control={form.control}
- name="checkPoint"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Check Point <span className="text-destructive">*</span></FormLabel>
- <FormControl>
- <Input
- placeholder="검증 항목을 입력하세요"
- {...field}
- />
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
-
- {/* Group Name 필드 (Select) */}
- <FormField
- control={form.control}
- name="groupName"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Group <span className="text-destructive">*</span></FormLabel>
- <Select
- onValueChange={field.onChange}
- defaultValue={field.value}
- value={field.value}
- >
- <FormControl>
- <SelectTrigger>
- <SelectValue placeholder="그룹을 선택하세요" />
- </SelectTrigger>
- </FormControl>
- <SelectContent>
- {groupOptions.map((group) => (
- <SelectItem key={group} value={group}>
- {group}
- </SelectItem>
- ))}
- </SelectContent>
- </Select>
- <FormMessage />
- </FormItem>
- )}
- />
- {/* Sub Group Name 필드 */}
- <FormField
- control={form.control}
- name="subGroupName"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Sub Group Name</FormLabel>
- <FormControl>
- <Input
- placeholder="서브 그룹명을 입력하세요"
- {...field}
- value={field.value || ""}
- />
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
-
- {/* Type 필드 */}
- <FormField
- control={form.control}
- name="type"
- render={({ field }) => (
- <FormItem>
- <FormLabel>내/외자 구분</FormLabel>
- <Select onValueChange={field.onChange} value={field.value}>
- <FormControl>
- <SelectTrigger>
- <SelectValue placeholder="구분을 선택하세요" />
- </SelectTrigger>
- </FormControl>
- <SelectContent>
- {typeOptions.map((option) => (
- <SelectItem key={option.value} value={option.value}>
- {option.label}
- </SelectItem>
- ))}
- </SelectContent>
- </Select>
- <FormDescription>미선택 시 기본값은 내외자입니다.</FormDescription>
- <FormMessage />
- </FormItem>
- )}
- />
-
- {/* Input Format 필드 */}
- <FormField
- control={form.control}
- name="inputFormat"
- render={({ field }) => (
- <FormItem>
- <FormLabel>입력 형식</FormLabel>
- <Select onValueChange={field.onChange} defaultValue={field.value}>
- <FormControl>
- <SelectTrigger>
- <SelectValue placeholder="입력 형식을 선택하세요" />
- </SelectTrigger>
- </FormControl>
- <SelectContent>
- {inputFormatOptions.map((option) => (
- <SelectItem key={option.value} value={option.value}>
- {option.label}
- </SelectItem>
- ))}
- </SelectContent>
- </Select>
- <FormMessage />
- </FormItem>
- )}
- />
-
- {/* 첨부 파일 업로드 */}
- <div className="space-y-2">
- <div className="flex items-center justify-between">
- <FormLabel>첨부 파일</FormLabel>
- {isUploading && (
- <div className="flex items-center text-xs text-muted-foreground">
- <Loader2 className="mr-1 h-3 w-3 animate-spin" /> 업로드 중...
- </div>
- )}
- </div>
- <Dropzone
- maxSize={6e8}
- onDropAccepted={(files) => handleUpload(files)}
- onDropRejected={() =>
- toast.error("파일 크기/형식을 확인하세요.")
- }
- disabled={isUploading}
- >
- {() => (
- <FormItem>
- <DropzoneZone className="flex justify-center h-24">
- <FormControl>
- <DropzoneInput />
- </FormControl>
- <div className="flex items-center gap-4">
- <DropzoneUploadIcon />
- <div className="grid gap-0.5">
- <DropzoneTitle>파일을 드래그하거나 클릭하여 업로드</DropzoneTitle>
- <DropzoneDescription>PDF, 이미지, 문서 (최대 600MB)</DropzoneDescription>
- </div>
- </div>
- </DropzoneZone>
- <FormDescription>기준 문서 첨부가 필요한 경우 업로드하세요.</FormDescription>
- </FormItem>
- )}
- </Dropzone>
-
- {attachments.length > 0 && (
- <div className="space-y-2">
- <p className="text-sm font-medium">첨부된 파일 ({attachments.length})</p>
- <FileList>
- {attachments.map((file, idx) => (
- <FileListItem key={idx}>
- <FileListHeader>
- <FileListInfo>
- <FileListName>{file.originalFileName || file.fileName}</FileListName>
- {file.size && (
- <FileListDescription>{`${file.size} bytes`}</FileListDescription>
- )}
- </FileListInfo>
- <FileListAction
- onClick={() =>
- setAttachments((prev) => prev.filter((_, i) => i !== idx))
- }
- >
- <X className="h-4 w-4" />
- <span className="sr-only">Remove</span>
- </FileListAction>
- </FileListHeader>
- </FileListItem>
- ))}
- </FileList>
- </div>
- )}
- </div>
-
- {/* Required 체크박스 */}
-
-
- {/* Description 필드 */}
- <FormField
- control={form.control}
- name="description"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Description</FormLabel>
- <FormControl>
- <Textarea
- placeholder="상세 설명을 입력하세요"
- className="min-h-[120px] whitespace-pre-wrap"
- {...field}
- value={field.value || ""}
- />
- </FormControl>
- <FormDescription>
- 줄바꿈이 필요한 경우 Enter 키를 누르세요. 입력한 대로 저장됩니다.
- </FormDescription>
- <FormMessage />
- </FormItem>
- )}
- />
-
- {/* Remarks 필드 */}
- <FormField
- control={form.control}
- name="remarks"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Remarks</FormLabel>
- <FormControl>
- <Textarea
- placeholder="비고 사항을 입력하세요"
- className="min-h-[80px]"
- {...field}
- value={field.value || ""}
- />
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
-
- <SheetFooter className="gap-2 pt-2 sm:space-x-0">
- <SheetClose asChild>
- <Button
- type="button"
- variant="outline"
- onClick={() => form.reset()}
- >
- Cancel
- </Button>
- </SheetClose>
- <Button disabled={isUpdatePending}>
- {isUpdatePending && (
- <Loader
- className="mr-2 size-4 animate-spin"
- aria-hidden="true"
- />
- )}
- <Save className="mr-2 size-4" /> Save
- </Button>
- </SheetFooter>
- </form>
- </Form>
- </SheetContent>
- </Sheet>
- )
+"use client"
+
+import * as React from "react"
+import { zodResolver } from "@hookform/resolvers/zod"
+import { Loader, Save } from "lucide-react"
+import { useForm } from "react-hook-form"
+import { toast } from "sonner"
+import { z } from "zod"
+import { useRouter } from "next/navigation"
+
+import { Button } from "@/components/ui/button"
+import {
+ Form,
+ FormControl,
+ FormDescription,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+} from "@/components/ui/form"
+import {
+ Select,
+ SelectContent,
+ // SelectGroup,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from "@/components/ui/select"
+import {
+ Sheet,
+ SheetClose,
+ SheetContent,
+ SheetDescription,
+ SheetFooter,
+ SheetHeader,
+ SheetTitle,
+} from "@/components/ui/sheet"
+import { Input } from "@/components/ui/input"
+import { Textarea } from "@/components/ui/textarea"
+
+import { updatePqCriteria } from "../service"
+import { groupOptions } from "./add-pq-dialog"
+import { Checkbox } from "@/components/ui/checkbox"
+import { uploadPqCriteriaFileAction, getPqCriteriaAttachments } from "@/lib/pq/service"
+import { Dropzone, DropzoneInput, DropzoneZone, DropzoneUploadIcon, DropzoneTitle, DropzoneDescription } from "@/components/ui/dropzone"
+import { FileList, FileListHeader, FileListInfo, FileListItem, FileListName, FileListDescription, FileListAction } from "@/components/ui/file-list"
+import { X, Loader2 } from "lucide-react"
+
+// PQ 수정을 위한 Zod 스키마 정의
+const updatePqSchema = z.object({
+ code: z.string().min(1, "Code is required"),
+ checkPoint: z.string().min(1, "Check point is required"),
+ groupName: z.string().min(1, "Group is required"),
+ description: z.string().optional(),
+ remarks: z.string().optional(),
+ inputFormat: z.string().default("TEXT"),
+
+ subGroupName: z.string().optional(),
+ type: z.string().optional(),
+});
+
+type UpdatePqSchema = z.infer<typeof updatePqSchema>;
+
+// 입력 형식 옵션
+const inputFormatOptions = [
+ { value: "TEXT", label: "텍스트" },
+ { value: "FILE", label: "파일" },
+ { value: "EMAIL", label: "이메일" },
+ { value: "PHONE", label: "전화번호" },
+ { value: "NUMBER", label: "숫자" },
+ { value: "NUMBER_WITH_UNIT", label: "숫자+단위" },
+ { value: "TEXT_FILE", label: "텍스트 + 파일" }
+];
+
+const typeOptions = [
+ { value: "내자", label: "내자" },
+ { value: "외자", label: "외자" },
+ { value: "내외자", label: "내외자" },
+];
+
+interface UpdatePqSheetProps
+ extends React.ComponentPropsWithRef<typeof Sheet> {
+ pq: {
+ id: number;
+ code: string;
+ checkPoint: string;
+ description: string | null;
+ remarks: string | null;
+ groupName: string | null;
+ inputFormat: string;
+
+ subGroupName: string | null;
+ type?: string | null;
+ } | null
+}
+
+export function UpdatePqSheet({ pq, ...props }: UpdatePqSheetProps) {
+ const [isUpdatePending, startUpdateTransition] = React.useTransition()
+ const [isUploading, setIsUploading] = React.useState(false)
+ const [attachments, setAttachments] = React.useState<
+ { fileName: string; url: string; size?: number; originalFileName?: string }[]
+ >([])
+ const router = useRouter()
+
+ const form = useForm<UpdatePqSchema>({
+ resolver: zodResolver(updatePqSchema),
+ defaultValues: {
+ code: pq?.code ?? "",
+ checkPoint: pq?.checkPoint ?? "",
+ groupName: pq?.groupName ?? groupOptions[0],
+ description: pq?.description ?? "",
+ remarks: pq?.remarks ?? "",
+ inputFormat: pq?.inputFormat ?? "TEXT",
+
+ subGroupName: pq?.subGroupName ?? "",
+ type: pq?.type ?? "내외자",
+ },
+ })
+
+ // 폼 초기화 (pq가 변경될 때)
+ React.useEffect(() => {
+ if (pq) {
+ form.reset({
+ code: pq.code,
+ checkPoint: pq.checkPoint,
+ groupName: pq.groupName ?? groupOptions[0],
+ description: pq.description ?? "",
+ remarks: pq.remarks ?? "",
+ inputFormat: pq.inputFormat ?? "TEXT",
+
+ subGroupName: pq.subGroupName ?? "",
+ type: pq.type ?? "내외자",
+ });
+
+ // 기존 첨부 로드
+ getPqCriteriaAttachments(pq.id).then((res) => {
+ if (res.success && res.data) {
+ setAttachments(
+ res.data.map((a) => ({
+ fileName: a.fileName,
+ url: a.filePath,
+ size: a.fileSize ?? undefined,
+ originalFileName: a.originalFileName || a.fileName,
+ }))
+ )
+ } else {
+ setAttachments([])
+ }
+ })
+ }
+ }, [pq, form]);
+
+ const handleUpload = async (files: File[]) => {
+ try {
+ setIsUploading(true)
+ for (const file of files) {
+ const uploaded = await uploadPqCriteriaFileAction(file)
+ setAttachments((prev) => [...prev, uploaded])
+ }
+ toast.success("첨부파일이 업로드되었습니다")
+ } catch (error) {
+ console.error(error)
+ toast.error("첨부파일 업로드에 실패했습니다")
+ } finally {
+ setIsUploading(false)
+ }
+ }
+
+ function onSubmit(input: UpdatePqSchema) {
+ startUpdateTransition(async () => {
+ if (!pq) return
+
+ const result = await updatePqCriteria(pq.id, {
+ ...input,
+ attachments,
+ })
+
+ if (!result.success) {
+ toast.error(result.message || "PQ 항목 수정에 실패했습니다")
+ return
+ }
+
+ toast.success(result.message || "PQ 항목이 성공적으로 수정되었습니다")
+ form.reset()
+ props.onOpenChange?.(false)
+ router.refresh()
+ })
+ }
+ return (
+ <Sheet {...props}>
+ <SheetContent className="flex flex-col gap-6 sm:max-w-md">
+ <SheetHeader className="text-left">
+ <SheetTitle>Update PQ Criteria</SheetTitle>
+ <SheetDescription>
+ Update the PQ criteria details and save the changes
+ </SheetDescription>
+ </SheetHeader>
+ <Form {...form}>
+ <form
+ onSubmit={form.handleSubmit(onSubmit)}
+ className="flex flex-col gap-4"
+ >
+ {/* Code 필드 */}
+ <FormField
+ control={form.control}
+ name="code"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Code <span className="text-destructive">*</span></FormLabel>
+ <FormControl>
+ <Input
+ placeholder="예: 1-1, A.2.3"
+ {...field}
+ />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+
+ {/* Check Point 필드 */}
+ <FormField
+ control={form.control}
+ name="checkPoint"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Check Point <span className="text-destructive">*</span></FormLabel>
+ <FormControl>
+ <Input
+ placeholder="검증 항목을 입력하세요"
+ {...field}
+ />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+
+ {/* Group Name 필드 (Select) */}
+ <FormField
+ control={form.control}
+ name="groupName"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Group <span className="text-destructive">*</span></FormLabel>
+ <Select
+ onValueChange={field.onChange}
+ defaultValue={field.value}
+ value={field.value}
+ >
+ <FormControl>
+ <SelectTrigger>
+ <SelectValue placeholder="그룹을 선택하세요" />
+ </SelectTrigger>
+ </FormControl>
+ <SelectContent>
+ {groupOptions.map((group) => (
+ <SelectItem key={group} value={group}>
+ {group}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ {/* Sub Group Name 필드 */}
+ <FormField
+ control={form.control}
+ name="subGroupName"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Sub Group Name</FormLabel>
+ <FormControl>
+ <Input
+ placeholder="서브 그룹명을 입력하세요"
+ {...field}
+ value={field.value || ""}
+ />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+
+ {/* Type 필드 */}
+ <FormField
+ control={form.control}
+ name="type"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>내/외자 구분</FormLabel>
+ <Select onValueChange={field.onChange} value={field.value}>
+ <FormControl>
+ <SelectTrigger>
+ <SelectValue placeholder="구분을 선택하세요" />
+ </SelectTrigger>
+ </FormControl>
+ <SelectContent>
+ {typeOptions.map((option) => (
+ <SelectItem key={option.value} value={option.value}>
+ {option.label}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ <FormDescription>미선택 시 기본값은 내외자입니다.</FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+
+ {/* Input Format 필드 */}
+ <FormField
+ control={form.control}
+ name="inputFormat"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>입력 형식</FormLabel>
+ <Select onValueChange={field.onChange} defaultValue={field.value}>
+ <FormControl>
+ <SelectTrigger>
+ <SelectValue placeholder="입력 형식을 선택하세요" />
+ </SelectTrigger>
+ </FormControl>
+ <SelectContent>
+ {inputFormatOptions.map((option) => (
+ <SelectItem key={option.value} value={option.value}>
+ {option.label}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+
+ {/* 첨부 파일 업로드 */}
+ <div className="space-y-2">
+ <div className="flex items-center justify-between">
+ <FormLabel>첨부 파일</FormLabel>
+ {isUploading && (
+ <div className="flex items-center text-xs text-muted-foreground">
+ <Loader2 className="mr-1 h-3 w-3 animate-spin" /> 업로드 중...
+ </div>
+ )}
+ </div>
+ <Dropzone
+ maxSize={6e8}
+ onDropAccepted={(files) => handleUpload(files)}
+ onDropRejected={() =>
+ toast.error("파일 크기/형식을 확인하세요.")
+ }
+ disabled={isUploading}
+ >
+ {() => (
+ <FormItem>
+ <DropzoneZone className="flex justify-center h-24">
+ <FormControl>
+ <DropzoneInput />
+ </FormControl>
+ <div className="flex items-center gap-4">
+ <DropzoneUploadIcon />
+ <div className="grid gap-0.5">
+ <DropzoneTitle>파일을 드래그하거나 클릭하여 업로드</DropzoneTitle>
+ <DropzoneDescription>PDF, 이미지, 문서 (최대 600MB)</DropzoneDescription>
+ </div>
+ </div>
+ </DropzoneZone>
+ <FormDescription>기준 문서 첨부가 필요한 경우 업로드하세요.</FormDescription>
+ </FormItem>
+ )}
+ </Dropzone>
+
+ {attachments.length > 0 && (
+ <div className="space-y-2">
+ <p className="text-sm font-medium">첨부된 파일 ({attachments.length})</p>
+ <FileList>
+ {attachments.map((file, idx) => (
+ <FileListItem key={idx}>
+ <FileListHeader>
+ <FileListInfo>
+ <FileListName>{file.originalFileName || file.fileName}</FileListName>
+ {file.size && (
+ <FileListDescription>{`${file.size} bytes`}</FileListDescription>
+ )}
+ </FileListInfo>
+ <FileListAction
+ onClick={() =>
+ setAttachments((prev) => prev.filter((_, i) => i !== idx))
+ }
+ >
+ <X className="h-4 w-4" />
+ <span className="sr-only">Remove</span>
+ </FileListAction>
+ </FileListHeader>
+ </FileListItem>
+ ))}
+ </FileList>
+ </div>
+ )}
+ </div>
+
+ {/* Required 체크박스 */}
+
+
+ {/* Description 필드 */}
+ <FormField
+ control={form.control}
+ name="description"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Description</FormLabel>
+ <FormControl>
+ <Textarea
+ placeholder="상세 설명을 입력하세요"
+ className="min-h-[120px] whitespace-pre-wrap"
+ {...field}
+ value={field.value || ""}
+ />
+ </FormControl>
+ <FormDescription>
+ 줄바꿈이 필요한 경우 Enter 키를 누르세요. 입력한 대로 저장됩니다.
+ </FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+
+ {/* Remarks 필드 */}
+ <FormField
+ control={form.control}
+ name="remarks"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Remarks</FormLabel>
+ <FormControl>
+ <Textarea
+ placeholder="비고 사항을 입력하세요"
+ className="min-h-[80px]"
+ {...field}
+ value={field.value || ""}
+ />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+
+ <SheetFooter className="gap-2 pt-2 sm:space-x-0">
+ <SheetClose asChild>
+ <Button
+ type="button"
+ variant="outline"
+ onClick={() => form.reset()}
+ >
+ Cancel
+ </Button>
+ </SheetClose>
+ <Button disabled={isUpdatePending}>
+ {isUpdatePending && (
+ <Loader
+ className="mr-2 size-4 animate-spin"
+ aria-hidden="true"
+ />
+ )}
+ <Save className="mr-2 size-4" /> Save
+ </Button>
+ </SheetFooter>
+ </form>
+ </Form>
+ </SheetContent>
+ </Sheet>
+ )
} \ No newline at end of file
diff --git a/lib/pq/pq-review-table-new/request-investigation-dialog.tsx b/lib/pq/pq-review-table-new/request-investigation-dialog.tsx
index f5a7ff91..febc308c 100644
--- a/lib/pq/pq-review-table-new/request-investigation-dialog.tsx
+++ b/lib/pq/pq-review-table-new/request-investigation-dialog.tsx
@@ -83,6 +83,7 @@ interface RequestInvestigationDialogProps {
investigationMethod?: string,
investigationNotes?: string
}
+ vendorCountry?: string | null
}
export function RequestInvestigationDialog({
@@ -91,7 +92,9 @@ export function RequestInvestigationDialog({
onSubmit,
selectedCount,
initialData,
+ vendorCountry,
}: RequestInvestigationDialogProps) {
+ const isDomesticVendor = vendorCountry === "KR" || vendorCountry === "한국"
const [isPending, setIsPending] = React.useState(false)
const [qmManagers, setQMManagers] = React.useState<QMUser[]>([])
const [isLoadingManagers, setIsLoadingManagers] = React.useState(false)
@@ -121,6 +124,36 @@ export function RequestInvestigationDialog({
}
}, [isOpen, initialData, form]);
+ // 도로명 주소 검색 결과 수신 및 주소 포맷팅
+ React.useEffect(() => {
+ if (!isOpen || !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()
+ const baseAddress = [zipNo ? `(${zipNo})` : "", road].filter(Boolean).join(" ").trim()
+ const detail = (addrDetail || "").trim()
+ const formatted = detail ? `${baseAddress}, ${detail}` : baseAddress
+
+ if (formatted) {
+ form.setValue("investigationAddress", formatted, { shouldDirty: true })
+ }
+ }
+
+ window.addEventListener("message", handleMessage)
+ return () => window.removeEventListener("message", handleMessage)
+ }, [isOpen, isDomesticVendor, form])
+
+ const handleJusoSearch = () => {
+ if (!isDomesticVendor) return
+ window.open(
+ "/api/juso",
+ "jusoSearch",
+ "width=570,height=420,scrollbars=yes,resizable=yes"
+ )
+ }
+
// Dialog가 열릴 때 QM 담당자 목록 로드
React.useEffect(() => {
if (isOpen && qmManagers.length === 0) {
@@ -227,7 +260,20 @@ export function RequestInvestigationDialog({
name="investigationAddress"
render={({ field }) => (
<FormItem>
- <FormLabel>실사 장소</FormLabel>
+ <div className="flex items-center justify-between gap-2">
+ <FormLabel>실사 장소</FormLabel>
+ {isDomesticVendor && (
+ <Button
+ type="button"
+ size="sm"
+ variant="secondary"
+ onClick={handleJusoSearch}
+ disabled={isPending}
+ >
+ 도로명 주소 검색
+ </Button>
+ )}
+ </div>
<FormControl>
<Textarea
placeholder="실사가 진행될 주소를 입력하세요"
diff --git a/lib/pq/pq-review-table-new/vendors-table-columns.tsx b/lib/pq/pq-review-table-new/vendors-table-columns.tsx
index ae684172..a35884fc 100644
--- a/lib/pq/pq-review-table-new/vendors-table-columns.tsx
+++ b/lib/pq/pq-review-table-new/vendors-table-columns.tsx
@@ -46,6 +46,7 @@ export interface PQSubmission {
taxId: string
vendorStatus: string
email: string
+ vendorCountry?: string | null
// 프로젝트 정보
projectId: number | null
projectName: string | null
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 4584e772..a9d37a4b 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
@@ -38,6 +38,7 @@ interface InvestigationInitialData {
createdAt?: Date;
investigationAddress?: string;
investigationNotes?: string;
+ vendorCountry?: string | null;
}
export function VendorsTableToolbarActions({ table }: VendorsTableToolbarActionsProps) {
@@ -87,6 +88,7 @@ const handleOpenRequestDialog = async () => {
// 선택된 행이 정확히 1개인 경우에만 초기값 설정
if (selectedRows.length === 1) {
const row = selectedRows[0].original;
+ initialData.vendorCountry = row.vendorCountry ?? null;
// 승인된 PQ이고 아직 실사가 없는 경우
if (row.status === "APPROVED" && !row.investigation) {
@@ -784,6 +786,7 @@ const handleOpenRequestDialog = async () => {
onSubmit={handleRequestInvestigation}
selectedCount={approvedPQsCount}
initialData={dialogInitialData} // 초기 데이터 전달
+ vendorCountry={dialogInitialData?.vendorCountry}
/>
diff --git a/lib/pq/service.ts b/lib/pq/service.ts
index 6d60e193..d9f84db4 100644
--- a/lib/pq/service.ts
+++ b/lib/pq/service.ts
@@ -1970,6 +1970,7 @@ export async function getPQSubmissions(input: GetPQSubmissionsSchema) {
email: vendors.email,
taxId: vendors.taxId,
vendorStatus: vendors.status,
+ vendorCountry: vendors.country,
// Project 정보 (프로젝트 PQ인 경우)
projectId: projects.id,
projectName: projects.name,
diff --git a/lib/shi-signature/buyer-signature.ts b/lib/shi-signature/buyer-signature.ts
index d464ae54..1055fdd2 100644
--- a/lib/shi-signature/buyer-signature.ts
+++ b/lib/shi-signature/buyer-signature.ts
@@ -8,6 +8,9 @@ import { writeFile, mkdir } from 'fs/promises';
import path from 'path';
import { v4 as uuidv4 } from 'uuid';
+const DEFAULT_SHI_ADDRESS = '경기도 성남시 분당구 판교로 227번길 23';
+const DEFAULT_SHI_CEO_NAME = '최성안';
+
export async function uploadBuyerSignature(formData: FormData) {
try {
const file = formData.get('file') as File;
@@ -25,6 +28,16 @@ export async function uploadBuyerSignature(formData: FormData) {
return { success: false, error: '이미지 파일만 업로드 가능합니다.' };
}
+ const addressInput = formData.get('shiAddress');
+ const ceoNameInput = formData.get('shiCeoName');
+
+ const shiAddress = typeof addressInput === 'string' && addressInput.trim()
+ ? addressInput.trim()
+ : DEFAULT_SHI_ADDRESS;
+ const shiCeoName = typeof ceoNameInput === 'string' && ceoNameInput.trim()
+ ? ceoNameInput.trim()
+ : DEFAULT_SHI_CEO_NAME;
+
const bytes = await file.arrayBuffer();
const buffer = Buffer.from(bytes);
@@ -50,6 +63,8 @@ export async function uploadBuyerSignature(formData: FormData) {
const [newSignature] = await db.insert(buyerSignatures)
.values({
name: '삼성중공업',
+ shiAddress,
+ shiCeoName,
imageUrl: `/uploads/signatures/${fileName}`,
dataUrl: base64,
mimeType: file.type,
diff --git a/lib/shi-signature/signature-list.tsx b/lib/shi-signature/signature-list.tsx
index 93cd3dbe..2d47589a 100644
--- a/lib/shi-signature/signature-list.tsx
+++ b/lib/shi-signature/signature-list.tsx
@@ -1,7 +1,7 @@
'use client';
import { useState } from 'react';
-import { BuyerSignature } from '@/db/schemae';
+import { BuyerSignature } from '@/db/schema';
import { setActiveSignature, deleteSignature } from './buyer-signature';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { Button } from '@/components/ui/button';
@@ -93,6 +93,12 @@ export function SignatureList({ signatures }: SignatureListProps) {
)}
</div>
<p className="text-sm text-muted-foreground">
+ 주소: {signature.shiAddress}
+ </p>
+ <p className="text-sm text-muted-foreground">
+ 대표이사: {signature.shiCeoName}
+ </p>
+ <p className="text-xs text-muted-foreground">
{new Date(signature.createdAt).toLocaleDateString()}
</p>
</div>
@@ -120,7 +126,7 @@ export function SignatureList({ signatures }: SignatureListProps) {
<Button
variant="outline"
size="sm"
- disabled={signature.isActive}
+ disabled={!!signature.isActive}
>
<Trash2 className="h-4 w-4" />
</Button>
diff --git a/lib/shi-signature/upload-form.tsx b/lib/shi-signature/upload-form.tsx
index 642cd1a5..4aa1c442 100644
--- a/lib/shi-signature/upload-form.tsx
+++ b/lib/shi-signature/upload-form.tsx
@@ -7,12 +7,22 @@ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/com
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Alert, AlertDescription } from '@/components/ui/alert';
-import { Upload, Loader2, CheckCircle } from 'lucide-react';
+import { Upload, Loader2 } from 'lucide-react';
import { toast } from 'sonner';
+import { BuyerSignature } from '@/db/schema';
-export function BuyerSignatureUploadForm() {
+const DEFAULT_SHI_ADDRESS = '경기도 성남시 분당구 판교로 227번길 23';
+const DEFAULT_SHI_CEO_NAME = '최성안';
+
+interface BuyerSignatureUploadFormProps {
+ initialSignature?: BuyerSignature | null;
+}
+
+export function BuyerSignatureUploadForm({ initialSignature }: BuyerSignatureUploadFormProps) {
const [isUploading, setIsUploading] = useState(false);
const [preview, setPreview] = useState<string | null>(null);
+ const [shiAddress, setShiAddress] = useState(initialSignature?.shiAddress ?? DEFAULT_SHI_ADDRESS);
+ const [shiCeoName, setShiCeoName] = useState(initialSignature?.shiCeoName ?? DEFAULT_SHI_CEO_NAME);
const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const file = e.target.files?.[0];
@@ -30,6 +40,8 @@ export function BuyerSignatureUploadForm() {
setIsUploading(true);
const formData = new FormData(e.currentTarget);
+ formData.set('shiAddress', shiAddress);
+ formData.set('shiCeoName', shiCeoName);
try {
const result = await uploadBuyerSignature(formData);
@@ -74,6 +86,30 @@ export function BuyerSignatureUploadForm() {
</p>
</div>
+ <div className="space-y-2">
+ <Label htmlFor="shiAddress">삼성중공업 주소</Label>
+ <Input
+ id="shiAddress"
+ name="shiAddress"
+ value={shiAddress}
+ onChange={(event) => setShiAddress(event.target.value)}
+ required
+ disabled={isUploading}
+ />
+ </div>
+
+ <div className="space-y-2">
+ <Label htmlFor="shiCeoName">대표이사 이름</Label>
+ <Input
+ id="shiCeoName"
+ name="shiCeoName"
+ value={shiCeoName}
+ onChange={(event) => setShiCeoName(event.target.value)}
+ required
+ disabled={isUploading}
+ />
+ </div>
+
{preview && (
<div className="border rounded-lg p-4 bg-gray-50">
<Label className="text-sm font-medium mb-2 block">미리보기</Label>
diff --git a/lib/vendor-investigation/table/investigation-progress-sheet.tsx b/lib/vendor-investigation/table/investigation-progress-sheet.tsx
index a9fbdfdb..6b040ad7 100644
--- a/lib/vendor-investigation/table/investigation-progress-sheet.tsx
+++ b/lib/vendor-investigation/table/investigation-progress-sheet.tsx
@@ -96,6 +96,38 @@ export function InvestigationProgressSheet({
}
}, [investigation, form])
+ // 도로명 주소 검색 결과 수신 및 주소 포맷팅
+ React.useEffect(() => {
+ const isDomestic = investigation?.vendorCountry === "KR" || investigation?.vendorCountry === "한국"
+ if (!props.open || !isDomestic) 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()
+ const baseAddress = [zipNo ? `(${zipNo})` : "", road].filter(Boolean).join(" ").trim()
+ const detail = (addrDetail || "").trim()
+ const formatted = detail ? `${baseAddress}, ${detail}` : baseAddress
+
+ if (formatted) {
+ form.setValue("investigationAddress", formatted, { shouldDirty: true })
+ }
+ }
+
+ window.addEventListener("message", handleMessage)
+ return () => window.removeEventListener("message", handleMessage)
+ }, [props.open, investigation?.vendorCountry, form])
+
+ const handleJusoSearch = () => {
+ const isDomestic = investigation?.vendorCountry === "KR" || investigation?.vendorCountry === "한국"
+ if (!isDomestic) return
+ window.open(
+ "/api/juso",
+ "jusoSearch",
+ "width=570,height=420,scrollbars=yes,resizable=yes"
+ )
+ }
+
// Submit handler
async function onSubmit(values: UpdateVendorInvestigationProgressSchema) {
console.log("실사 진행 관리 onSubmit 호출됨:", values)
@@ -193,7 +225,20 @@ export function InvestigationProgressSheet({
name="investigationAddress"
render={({ field }) => (
<FormItem>
- <FormLabel>실사 주소</FormLabel>
+ <div className="flex items-center justify-between gap-2">
+ <FormLabel>실사 주소</FormLabel>
+ { (investigation?.vendorCountry === "KR" || investigation?.vendorCountry === "한국") && (
+ <Button
+ type="button"
+ size="sm"
+ variant="secondary"
+ onClick={handleJusoSearch}
+ disabled={isPending}
+ >
+ 도로명 주소 검색
+ </Button>
+ )}
+ </div>
<FormControl>
<Textarea
placeholder="실사가 진행될 주소를 입력하세요..."