From 4fcbdaff827e298ecd8a57939a287f61cc1b30d6 Mon Sep 17 00:00:00 2001 From: joonhoekim <26rote@gmail.com> Date: Fri, 24 Oct 2025 10:50:51 +0900 Subject: (김준회) 벤더 연락처 삭제 기능 구현 MDG vendor 송신부 csv에 설명 추가 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/vendors/contacts-table/contact-table.tsx | 77 ++++++++++++++++++++++- lib/vendors/service.ts | 30 +++++++++ lib/vendors/validations.ts | 7 +++ public/wsdl/P2MD3007_AO.csv | 92 ++++++++++++++-------------- 4 files changed, 159 insertions(+), 47 deletions(-) diff --git a/lib/vendors/contacts-table/contact-table.tsx b/lib/vendors/contacts-table/contact-table.tsx index 65b12451..c0e76292 100644 --- a/lib/vendors/contacts-table/contact-table.tsx +++ b/lib/vendors/contacts-table/contact-table.tsx @@ -13,10 +13,20 @@ import { DataTable } from "@/components/data-table/data-table" import { DataTableAdvancedToolbar } from "@/components/data-table/data-table-advanced-toolbar" import { useFeatureFlags } from "./feature-flags-provider" import { getColumns } from "./contact-table-columns" -import { getVendorContacts, } from "../service" +import { getVendorContacts, deleteVendorContact } from "../service" import { VendorContact, vendors } from "@/db/schema/vendors" import { VendorsTableToolbarActions } from "./contact-table-toolbar-actions" import { EditContactDialog } from "./edit-contact-dialog" +import { toast } from "sonner" +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, +} from "@/components/ui/dialog" +import { Button } from "@/components/ui/button" interface VendorsTableProps { promises: Promise< @@ -36,6 +46,8 @@ export function VendorContactsTable({ promises , vendorId}: VendorsTableProps) { const [rowAction, setRowAction] = React.useState | null>(null) const [editDialogOpen, setEditDialogOpen] = React.useState(false) const [selectedContact, setSelectedContact] = React.useState(null) + const [deleteDialogOpen, setDeleteDialogOpen] = React.useState(false) + const [isDeleting, setIsDeleting] = React.useState(false) // Edit 액션 처리 React.useEffect(() => { @@ -43,9 +55,41 @@ export function VendorContactsTable({ promises , vendorId}: VendorsTableProps) { setSelectedContact(rowAction.row.original) setEditDialogOpen(true) setRowAction(null) + } else if (rowAction?.type === "delete") { + setSelectedContact(rowAction.row.original) + setDeleteDialogOpen(true) + setRowAction(null) } }, [rowAction]) + // Delete 액션 처리 함수 + const handleDelete = React.useCallback(async () => { + if (!selectedContact) return + + setIsDeleting(true) + try { + const result = await deleteVendorContact({ + id: selectedContact.id, + vendorId: vendorId + }) + + if (result.success) { + toast.success(result.message) + // 페이지를 새로고침하거나 데이터를 다시 가져오기 + window.location.reload() + } else { + toast.error(result.message) + } + } catch (error) { + toast.error("Failed to delete contact") + console.error("Error deleting contact:", error) + } finally { + setIsDeleting(false) + setDeleteDialogOpen(false) + setSelectedContact(null) + } + }, [selectedContact, vendorId]) + // 데이터 새로고침 함수 const handleEditSuccess = React.useCallback(() => { // 페이지를 새로고침하거나 데이터를 다시 가져오기 @@ -107,6 +151,37 @@ export function VendorContactsTable({ promises , vendorId}: VendorsTableProps) { onOpenChange={setEditDialogOpen} onSuccess={handleEditSuccess} /> + + {/* Delete 확인 다이얼로그 */} + {selectedContact && ( + + + + 연락처 삭제 + + 정말로 "{selectedContact.contactName}" 연락처를 삭제하시겠습니까? + 이 작업은 되돌릴 수 없습니다. + + + + + + + + + )} ) } \ No newline at end of file diff --git a/lib/vendors/service.ts b/lib/vendors/service.ts index 98c72349..6813f717 100644 --- a/lib/vendors/service.ts +++ b/lib/vendors/service.ts @@ -45,6 +45,7 @@ import type { GetVendorContactsSchema, CreateVendorContactSchema, UpdateVendorContactSchema, + DeleteVendorContactSchema, GetVendorItemsSchema, CreateVendorItemSchema, GetRfqHistorySchema, @@ -3680,4 +3681,33 @@ export async function getBidHistory(input: GetBidHistorySchema, vendorId: number console.error("Error fetching bid history:", err); return { data: [], pageCount: 0 }; } +} + +// deleteVendorContact 함수 추가 +export async function deleteVendorContact(input: DeleteVendorContactSchema) { + unstable_noStore(); // Next.js 서버 액션 캐싱 방지 + try { + await db.transaction(async (tx) => { + // DB Delete + await tx + .delete(vendorContacts) + .where(and( + eq(vendorContacts.id, input.id), + eq(vendorContacts.vendorId, input.vendorId) + )); + }); + + // 캐시 무효화 (협력업체 연락처 목록 등) + revalidateTag(`vendor-contacts-${input.vendorId}`); + + return { success: true, message: "Contact deleted successfully" }; + } catch (error) { + console.error("Error deleting vendor contact:", error); + return { + success: false, + message: error instanceof z.ZodError + ? error.errors[0].message + : "Failed to delete contact" + }; + } } \ No newline at end of file diff --git a/lib/vendors/validations.ts b/lib/vendors/validations.ts index 88a39651..4a165f03 100644 --- a/lib/vendors/validations.ts +++ b/lib/vendors/validations.ts @@ -372,6 +372,12 @@ export const updateVendorItemSchema = z.object({ description: z.string().optional() }); +// DeleteVendorContactSchema 추가 +export const deleteVendorContactSchema = z.object({ + id: z.number().min(1, "Contact ID is required"), + vendorId: z.number().min(1, "Vendor ID is required"), +}) + export const searchParamsRfqHistoryCache = createSearchParamsCache({ // 공통 플래그 flags: parseAsArrayOf(z.enum(["advancedTable", "floatingBar"])).withDefault( @@ -413,6 +419,7 @@ export type CreateVendorContactSchema = z.infer export type CreateVendorItemSchema = z.infer export type UpdateVendorItemSchema = z.infer +export type DeleteVendorContactSchema = z.infer export type GetRfqHistorySchema = Awaited> diff --git a/public/wsdl/P2MD3007_AO.csv b/public/wsdl/P2MD3007_AO.csv index 25d3ef65..ddef7bb6 100644 --- a/public/wsdl/P2MD3007_AO.csv +++ b/public/wsdl/P2MD3007_AO.csv @@ -1,47 +1,47 @@ SEQ,Table,Field,M/O,Type,Size,Description -1,SUPPLIER_MASTER,BP_HEADER,M,CHAR,10,Business Partner Number -2,SUPPLIER_MASTER,ZZSRMCD,M,CHAR,20,SRM Vendor Code -3,SUPPLIER_MASTER,SORT1,M,NUMC,20,Search Term 1 -4,SUPPLIER_MASTER,NAME1,M,CHAR,40,Name 1 -5,SUPPLIER_MASTER,NAME2,,CHAR,40,Name 2 -6,SUPPLIER_MASTER,NAME3,,CHAR,40,Name 3 -7,SUPPLIER_MASTER,NAME4,,CHAR,40,Name 4 -8,SUPPLIER_MASTER,KTOKK,M,CHAR,4,Vendor account group -9,SUPPLIER_MASTER,ZTYPE,,CHAR,2,Account Group type -10,SUPPLIER_MASTER,VBUND,,CHAR,6,Company ID of Trading Partner -11,SUPPLIER_MASTER,J_1KFREPRE,,CHAR,10,Name of Representative -12,SUPPLIER_MASTER,J_1KFTBUS,,CHAR,30,Type of Business -13,SUPPLIER_MASTER,J_1KFTIND,,CHAR,30,Type of Industry -14,SUPPLIER_MASTER,VQMGRP,,CHAR,20,Vendor QM Group -15,SUPPLIER_MASTER,VTELNO,,CHAR,30,Vendor QM Group Tel. -16,SUPPLIER_MASTER,VEMAIL,,CHAR,30,Vendor QM Group E-Mail -17,SUPPLIER_MASTER,ZZCNAME1,,CHAR,35,First name -18,SUPPLIER_MASTER,ZZCNAME2,,CHAR,35,Name 1 -19,SUPPLIER_MASTER,ZZTELF1_C,,CHAR,16,First telephone number -20,SUPPLIER_MASTER,MASTERFLAG,M,CHAR,1,Master Flag -21,SUPPLIER_MASTER,IBND_TYPE,M,CHAR,1,Inbound Type -22,SUPPLIER_MASTER,ZZVNDTYP,,CHAR,2,Vendor Type -23,SUPPLIER_MASTER,ZZREQID,M,VARCHAR2,12,Registered User -24,SUPPLIER_MASTER,ZZIND01,,VARCHAR2,1,Indicator 01 -25,SUPPLIER_MASTER,ADDRNO,M,CHAR,10,Address Number -26,SUPPLIER_MASTER,NATION,,CHAR,1,International address version ID -27,SUPPLIER_MASTER,COUNTRY,M,CHAR,3,Country Key -28,SUPPLIER_MASTER,LANGU,,LANG,1,Language Key -29,SUPPLIER_MASTER,POST_CODE1,M,CHAR,10,Postal Code -30,SUPPLIER_MASTER,CITY1,M,CHAR,40,City -31,SUPPLIER_MASTER,CITY2,,CHAR,40,District -32,SUPPLIER_MASTER,REGION,,CHAR,3,"Region (State, Province, County)" -33,SUPPLIER_MASTER,STREET,M,CHAR,60,Street -34,SUPPLIER_MASTER,CONSNUMBER,,NUMC,3,Sequence number -35,SUPPLIER_MASTER,TEL_NUMBER,,CHAR,30,Telephone no.: dialling code+number -36,SUPPLIER_MASTER,TEL_EXTENS,,CHAR,10,Telephone no.: Extension -37,SUPPLIER_MASTER,R3_USER,M,CHAR,1,ndicator: Telephone is a Mobile Telephone -38,SUPPLIER_MASTER,FAX_NUMBER,,CHAR,30,Fax number -39,SUPPLIER_MASTER,FAX_EXTENS,,CHAR,10,Fax no.: Extension -40,SUPPLIER_MASTER,URI_ADDR,,LCHR,2048,Universal Resource Identifier (URI) -41,SUPPLIER_MASTER,SMTP_ADDR,,CHAR,241,E-Mail Address -42,SUPPLIER_MASTER,TAXTYPE,M,CHAR,4,Tax Number Category -43,SUPPLIER_MASTER,TAXNUM,,CHAR,20,Business Partner Tax Number -44,SUPPLIER_MASTER,BP_TX_TYP,,VARCHAR2,6,Resident Registration Number -45,SUPPLIER_MASTER,STCD3,,CHAR,18,법인등록번호 -46,SUPPLIER_MASTER,ZZIND03,,CHAR,1,기업규모 \ No newline at end of file +1,SUPPLIER_MASTER,BP_HEADER,M,CHAR,10,Business Partner Number (벤더코드입력(없는데..어떻게?)) +2,SUPPLIER_MASTER,ZZSRMCD,M,CHAR,20,SRM Vendor Code (SRM코드 없음. 일단 필수값이긴 하니 고정값 보낼 것임.) +3,SUPPLIER_MASTER,SORT1,M,NUMC,20,Search Term 1 (벤더명과 동일하게) +4,SUPPLIER_MASTER,NAME1,M,CHAR,40,Name 1 (벤더명과 동일하게) +5,SUPPLIER_MASTER,NAME2,,CHAR,40,Name 2 (무시) +6,SUPPLIER_MASTER,NAME3,,CHAR,40,Name 3 (무시) +7,SUPPLIER_MASTER,NAME4,,CHAR,40,Name 4 (무시) +8,SUPPLIER_MASTER,KTOKK,M,CHAR,4,Vendor account group (항상 LIEF) +9,SUPPLIER_MASTER,ZTYPE,,CHAR,2,Account Group type (무시) +10,SUPPLIER_MASTER,VBUND,,CHAR,6,Company ID of Trading Partner (무시) +11,SUPPLIER_MASTER,J_1KFREPRE,,CHAR,10,Name of Representative: 대표자명 +12,SUPPLIER_MASTER,J_1KFTBUS,,CHAR,30,Type of Business: 사업유형 +13,SUPPLIER_MASTER,J_1KFTIND,,CHAR,30,Type of Industry: 산업유형 +14,SUPPLIER_MASTER,VQMGRP,,CHAR,20,Vendor QM Group: 무시 +15,SUPPLIER_MASTER,VTELNO,,CHAR,30,Vendor QM Group Tel.: 무시 +16,SUPPLIER_MASTER,VEMAIL,,CHAR,30,Vendor QM Group E-Mail: 무시 +17,SUPPLIER_MASTER,ZZCNAME1,,CHAR,35,First name: ? +18,SUPPLIER_MASTER,ZZCNAME2,,CHAR,35,Name 1: ? +19,SUPPLIER_MASTER,ZZTELF1_C,,CHAR,16,First telephone number: ? +20,SUPPLIER_MASTER,MASTERFLAG,M,CHAR,1,Master Flag: (항상 V?) +21,SUPPLIER_MASTER,IBND_TYPE,M,CHAR,1,Inbound Type: (항상 I?) +22,SUPPLIER_MASTER,ZZVNDTYP,,CHAR,2,Vendor Type: 무시 +23,SUPPLIER_MASTER,ZZREQID,M,VARCHAR2,12,Registered User: (?요청자 녹스ID 대문자?) +24,SUPPLIER_MASTER,ZZIND01,,VARCHAR2,1,Indicator 01: 무시 +25,SUPPLIER_MASTER,ADDRNO,M,CHAR,10,Address Number: (값을 보내면 안된다고 함.. 정의서에 필수값인데..) +26,SUPPLIER_MASTER,NATION,,CHAR,1,International address version ID: (값을 보내면 안된다고 함) +27,SUPPLIER_MASTER,COUNTRY,M,CHAR,3,Country Key: (국가코드 2자리인듯. 내자(국내업체)는 KR) +28,SUPPLIER_MASTER,LANGU,,LANG,1,Language Key: 무시 +29,SUPPLIER_MASTER,POST_CODE1,M,CHAR,10,Postal Code: 우편번호 +30,SUPPLIER_MASTER,CITY1,M,CHAR,40,City: 이게 주소로 쓰이는 걸로 보임. 상세주소 (ex: 한화오션내 H안벽생산지원센터 403) +31,SUPPLIER_MASTER,CITY2,,CHAR,40,District: 무시 +32,SUPPLIER_MASTER,REGION,,CHAR,3,"Region (State, Province, County) : 무시" +33,SUPPLIER_MASTER,STREET,M,CHAR,60,Street: 이게 주소로 쓰이는 걸로 보임. 기본주소 (ex: 경상남도 거제시 거제대로 3370 (한화오션) +34,SUPPLIER_MASTER,CONSNUMBER,,NUMC,3,Sequence number: 뭔지 모르겠음. 같은 벤더 여러값 보낼 때 시퀀스인듯. 단건은 항상1로 고정 +35,SUPPLIER_MASTER,TEL_NUMBER,,CHAR,30,Telephone no.: dialling code+number (-를 포함한 전화번호) +36,SUPPLIER_MASTER,TEL_EXTENS,,CHAR,10,Telephone no.: Extension (내선번호) +37,SUPPLIER_MASTER,R3_USER,M,CHAR,1,Indicator: Telephone is a Mobile Telephone () : (0이면 일반전화 1이면 휴대폰) +38,SUPPLIER_MASTER,FAX_NUMBER,,CHAR,30,Fax number: (팩스번호) +39,SUPPLIER_MASTER,FAX_EXTENS,,CHAR,10,Fax no.: Extension: (팩스내선번호) +40,SUPPLIER_MASTER,URI_ADDR,,LCHR,2048,Universal Resource Identifier (URI): 홈페이지 주소 +41,SUPPLIER_MASTER,SMTP_ADDR,,CHAR,241,E-Mail Address: 대표자이메일 +42,SUPPLIER_MASTER,TAXTYPE,M,CHAR,4,Tax Number Category: 구분기준모름 김태후프로님은 항상 KR2 로 보내라고 하심 +43,SUPPLIER_MASTER,TAXNUM,,CHAR,20,Business Partner Tax Number (사업자번호 -없이숫자만입력) +44,SUPPLIER_MASTER,BP_TX_TYP,,VARCHAR2,6,Resident Registration Number (YYMMDD0000000) +45,SUPPLIER_MASTER,STCD3,,CHAR,18,법인등록번호: (법인등록번호 -없이 숫자만) +46,SUPPLIER_MASTER,ZZIND03,,CHAR,1,"기업규모: (A,B,C,D 값을 넣는걸로 아는데 기준을 알려주지 않음)" \ No newline at end of file -- cgit v1.2.3