From 2650b7c0bb0ea12b68a58c0439f72d61df04b2f1 Mon Sep 17 00:00:00 2001 From: dujinkim Date: Fri, 25 Jul 2025 07:51:15 +0000 Subject: (대표님) 정기평가 대상, 미들웨어 수정, nextauth 토큰 처리 개선, GTC 등 (최겸) 기술영업 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tech-vendors/contacts-table/contact-table.tsx | 55 ++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) (limited to 'lib/tech-vendors/contacts-table/contact-table.tsx') diff --git a/lib/tech-vendors/contacts-table/contact-table.tsx b/lib/tech-vendors/contacts-table/contact-table.tsx index 6029fe16..5a49cf8d 100644 --- a/lib/tech-vendors/contacts-table/contact-table.tsx +++ b/lib/tech-vendors/contacts-table/contact-table.tsx @@ -15,6 +15,9 @@ import { getTechVendorContacts } from "../service" import { TechVendorContact } from "@/db/schema/techVendors" import { TechVendorContactsTableToolbarActions } from "./contact-table-toolbar-actions" import { UpdateContactSheet } from "./update-contact-sheet" +import { toast } from "sonner" +import { AlertDialog, AlertDialogContent, AlertDialogHeader, AlertDialogTitle, AlertDialogDescription, AlertDialogFooter, AlertDialogCancel, AlertDialogAction } from "@/components/ui/alert-dialog" +import { deleteTechVendorContact } from "../service" interface TechVendorContactsTableProps { promises: Promise< @@ -31,6 +34,32 @@ export function TechVendorContactsTable({ promises , vendorId}: TechVendorContac const [{ data, pageCount }] = React.use(promises) const [rowAction, setRowAction] = React.useState | null>(null) + const [isDeleting, setIsDeleting] = React.useState(false) + const [showDeleteAlert, setShowDeleteAlert] = React.useState(false) + + React.useEffect(() => { + if (rowAction?.type === "delete") { + setShowDeleteAlert(true) + } + }, [rowAction]) + + async function handleDeleteContact() { + if (!rowAction || rowAction.type !== "delete") return + setIsDeleting(true) + try { + const contactId = rowAction.row.original.id + const vId = rowAction.row.original.vendorId + const { data, error } = await deleteTechVendorContact(contactId, vId) + if (error) throw new Error(error) + toast.success("연락처가 삭제되었습니다.") + setShowDeleteAlert(false) + setRowAction(null) + } catch (err) { + toast.error(err instanceof Error ? err.message : "삭제 중 오류가 발생했습니다.") + } finally { + setIsDeleting(false) + } + } // getColumns() 호출 시, router를 주입 const columns = React.useMemo( @@ -47,7 +76,7 @@ export function TechVendorContactsTable({ promises , vendorId}: TechVendorContac { id: "contactPosition", label: "Contact Position", type: "text" }, { id: "contactEmail", label: "Contact Email", type: "text" }, { id: "contactPhone", label: "Contact Phone", type: "text" }, - { id: "country", label: "Country", type: "text" }, + { id: "contactCountry", label: "Country", type: "text" }, { id: "createdAt", label: "Created at", type: "date" }, { id: "updatedAt", label: "Updated at", type: "date" }, ] @@ -88,6 +117,30 @@ export function TechVendorContactsTable({ promises , vendorId}: TechVendorContac contact={rowAction?.type === "update" ? rowAction.row.original : null} vendorId={vendorId} /> + + {/* Delete Confirmation Dialog */} + + + + 연락처 삭제 + + 이 연락처를 삭제하시겠습니까? 이 작업은 되돌릴 수 없습니다. + + + + setRowAction(null)}> + 취소 + + + {isDeleting ? "삭제 중..." : "삭제"} + + + + ) } \ No newline at end of file -- cgit v1.2.3