summaryrefslogtreecommitdiff
path: root/lib/rfq-last/vendor-response/editor/vendor-response-editor.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rfq-last/vendor-response/editor/vendor-response-editor.tsx')
-rw-r--r--lib/rfq-last/vendor-response/editor/vendor-response-editor.tsx50
1 files changed, 46 insertions, 4 deletions
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 569546dd..fec9a2b9 100644
--- a/lib/rfq-last/vendor-response/editor/vendor-response-editor.tsx
+++ b/lib/rfq-last/vendor-response/editor/vendor-response-editor.tsx
@@ -14,6 +14,11 @@ import RfqInfoHeader from "./rfq-info-header"
import CommercialTermsForm from "./commercial-terms-form"
import QuotationItemsTable from "./quotation-items-table"
import AttachmentsUpload from "./attachments-upload"
+
+interface FileWithType extends File {
+ attachmentType?: "구매" | "설계"
+ description?: string
+}
import { formatDate, formatCurrency } from "@/lib/utils"
import { Shield, FileText, CheckCircle, XCircle, Clock, Download, Eye, Save, Send, AlertCircle, Upload, } from "lucide-react"
import { Progress } from "@/components/ui/progress"
@@ -103,11 +108,34 @@ export default function VendorResponseEditor({
const router = useRouter()
const [loading, setLoading] = useState(false)
const [activeTab, setActiveTab] = useState("info")
- const [attachments, setAttachments] = useState<File[]>([])
+ const [attachments, setAttachments] = useState<FileWithType[]>([])
+ const [existingAttachments, setExistingAttachments] = useState<any[]>([])
+ const [deletedAttachments, setDeletedAttachments] = useState<any[]>([])
const [uploadProgress, setUploadProgress] = useState(0) // 추가
console.log(existingResponse,"existingResponse")
+ // existingResponse가 변경될 때 existingAttachments 초기화
+ useEffect(() => {
+ if (existingResponse?.attachments) {
+ setExistingAttachments([...existingResponse.attachments])
+ setDeletedAttachments([]) // 삭제 목록 초기화
+ } else {
+ setExistingAttachments([])
+ setDeletedAttachments([])
+ }
+ }, [existingResponse?.attachments])
+
+ // 기존 첨부파일 삭제 처리
+ const handleExistingAttachmentsChange = (files: any[]) => {
+ const currentAttachments = existingResponse?.attachments || []
+ const deleted = currentAttachments.filter(
+ curr => !files.some(f => f.id === curr.id)
+ )
+ setExistingAttachments(files)
+ setDeletedAttachments(prev => [...prev, ...deleted])
+ }
+
// Form 초기값 설정
const defaultValues: VendorResponseFormData = {
@@ -229,10 +257,20 @@ export default function VendorResponseEditor({
try {
const formData = new FormData()
- const fileMetadata = attachments.map((file: any) => ({
+ const fileMetadata = attachments.map((file: FileWithType) => ({
attachmentType: file.attachmentType || "기타",
description: file.description || ""
}))
+
+ // 삭제된 첨부파일 ID 목록
+ const deletedAttachmentIds = deletedAttachments.map(file => file.id)
+
+ // 디버그: 첨부파일 attachmentType 확인
+ console.log('Attachments with types:', attachments.map(f => ({
+ name: f.name,
+ attachmentType: f.attachmentType,
+ size: f.size
+ })))
// 기본 데이터 추가
@@ -246,7 +284,8 @@ export default function VendorResponseEditor({
submittedBy: isSubmit ? userId : null,
totalAmount: data.quotationItems.reduce((sum, item) => sum + item.totalPrice, 0),
updatedBy: userId,
- fileMetadata
+ fileMetadata,
+ deletedAttachmentIds
}
console.log('Submitting data:', submitData) // 디버깅용
@@ -468,7 +507,10 @@ export default function VendorResponseEditor({
<AttachmentsUpload
attachments={attachments}
onAttachmentsChange={setAttachments}
- existingAttachments={existingResponse?.attachments}
+ existingAttachments={existingAttachments}
+ onExistingAttachmentsChange={handleExistingAttachmentsChange}
+ responseId={existingResponse?.id}
+ userId={userId}
/>
</TabsContent>
</Tabs>