summaryrefslogtreecommitdiff
path: root/lib/tech-vendors/contacts-table/contact-table.tsx
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-07-25 07:51:15 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-07-25 07:51:15 +0000
commit2650b7c0bb0ea12b68a58c0439f72d61df04b2f1 (patch)
tree17156183fd74b69d78178065388ac61a18ac07b4 /lib/tech-vendors/contacts-table/contact-table.tsx
parentd32acea05915bd6c1ed4b95e56c41ef9204347bc (diff)
(대표님) 정기평가 대상, 미들웨어 수정, nextauth 토큰 처리 개선, GTC 등
(최겸) 기술영업
Diffstat (limited to 'lib/tech-vendors/contacts-table/contact-table.tsx')
-rw-r--r--lib/tech-vendors/contacts-table/contact-table.tsx55
1 files changed, 54 insertions, 1 deletions
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<DataTableRowAction<TechVendorContact> | 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 */}
+ <AlertDialog open={showDeleteAlert} onOpenChange={setShowDeleteAlert}>
+ <AlertDialogContent>
+ <AlertDialogHeader>
+ <AlertDialogTitle>연락처 삭제</AlertDialogTitle>
+ <AlertDialogDescription>
+ 이 연락처를 삭제하시겠습니까? 이 작업은 되돌릴 수 없습니다.
+ </AlertDialogDescription>
+ </AlertDialogHeader>
+ <AlertDialogFooter>
+ <AlertDialogCancel onClick={() => setRowAction(null)}>
+ 취소
+ </AlertDialogCancel>
+ <AlertDialogAction
+ onClick={handleDeleteContact}
+ disabled={isDeleting}
+ className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
+ >
+ {isDeleting ? "삭제 중..." : "삭제"}
+ </AlertDialogAction>
+ </AlertDialogFooter>
+ </AlertDialogContent>
+ </AlertDialog>
</>
)
} \ No newline at end of file