summaryrefslogtreecommitdiff
path: root/lib/tech-vendors/contacts-table
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-10-23 03:30:01 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-10-23 03:30:01 +0000
commitc8cccaf1198ae48754ac036b579732018f5b448a (patch)
tree9c64024818c2be1c7b6699b4e141729432719d86 /lib/tech-vendors/contacts-table
parent835010104c25c370c1def1f2de52f518058f8b46 (diff)
(최겸) 기술영업 조선 rfq 수정(벤더, 담당자 임시삭제기능 추가)
Diffstat (limited to 'lib/tech-vendors/contacts-table')
-rw-r--r--lib/tech-vendors/contacts-table/add-contact-dialog.tsx9
-rw-r--r--lib/tech-vendors/contacts-table/delete-contact-dialog.tsx81
-rw-r--r--lib/tech-vendors/contacts-table/update-contact-sheet.tsx13
3 files changed, 99 insertions, 4 deletions
diff --git a/lib/tech-vendors/contacts-table/add-contact-dialog.tsx b/lib/tech-vendors/contacts-table/add-contact-dialog.tsx
index 90ba4e04..447c44d7 100644
--- a/lib/tech-vendors/contacts-table/add-contact-dialog.tsx
+++ b/lib/tech-vendors/contacts-table/add-contact-dialog.tsx
@@ -21,6 +21,7 @@ import {
type CreateTechVendorContactSchema,
} from "@/lib/tech-vendors/validations"
import { createTechVendorContact } from "@/lib/tech-vendors/service"
+import { normalizeEmail } from "@/lib/tech-vendors/utils"
interface AddContactDialogProps {
vendorId: number
@@ -46,8 +47,14 @@ export function AddContactDialog({ vendorId }: AddContactDialogProps) {
})
async function onSubmit(data: CreateTechVendorContactSchema) {
+ // 이메일을 소문자로 변환
+ const normalizedData = {
+ ...data,
+ contactEmail: normalizeEmail(data.contactEmail),
+ }
+
// 혹은 여기서 data.vendorId = vendorId; 해줘도 됨
- const result = await createTechVendorContact(data)
+ const result = await createTechVendorContact(normalizedData)
if (result.error) {
alert(`에러: ${result.error}`)
return
diff --git a/lib/tech-vendors/contacts-table/delete-contact-dialog.tsx b/lib/tech-vendors/contacts-table/delete-contact-dialog.tsx
new file mode 100644
index 00000000..6c8b14d7
--- /dev/null
+++ b/lib/tech-vendors/contacts-table/delete-contact-dialog.tsx
@@ -0,0 +1,81 @@
+"use client"
+
+import * as React from "react"
+import { toast } from "sonner"
+import { Trash2 } from "lucide-react"
+
+import { Button } from "@/components/ui/button"
+import {
+ AlertDialog,
+ AlertDialogAction,
+ AlertDialogCancel,
+ AlertDialogContent,
+ AlertDialogDescription,
+ AlertDialogFooter,
+ AlertDialogHeader,
+ AlertDialogTitle,
+ AlertDialogTrigger,
+} from "@/components/ui/alert-dialog"
+
+import { deleteTechVendorContact } from "../service"
+import type { TechVendorContact } from "@/db/schema/techVendors"
+
+interface DeleteContactDialogProps {
+ contact: TechVendorContact
+ vendorId: number
+ onSuccess?: () => void
+}
+
+export function DeleteContactDialog({ contact, vendorId, onSuccess }: DeleteContactDialogProps) {
+ const [isDeleting, setIsDeleting] = React.useState(false)
+
+ const handleDelete = async () => {
+ setIsDeleting(true)
+ try {
+ const result = await deleteTechVendorContact(contact.id, vendorId)
+
+ if (result.success) {
+ toast.success("담당자가 성공적으로 삭제되었습니다.")
+ onSuccess?.()
+ } else {
+ toast.error(result.error || "담당자 삭제 중 오류가 발생했습니다.")
+ }
+ } catch (error) {
+ console.error("담당자 삭제 오류:", error)
+ toast.error("담당자 삭제 중 오류가 발생했습니다.")
+ } finally {
+ setIsDeleting(false)
+ }
+ }
+
+ return (
+ <AlertDialog>
+ <AlertDialogTrigger asChild>
+ <Button variant="ghost" size="sm" className="text-red-600 hover:text-red-700 hover:bg-red-50">
+ <Trash2 className="size-4 mr-2" />
+ 삭제
+ </Button>
+ </AlertDialogTrigger>
+ <AlertDialogContent>
+ <AlertDialogHeader>
+ <AlertDialogTitle>담당자 삭제</AlertDialogTitle>
+ <AlertDialogDescription>
+ <strong>{contact.contactName}</strong> 담당자를 정말 삭제하시겠습니까?
+ <br />
+ 이 작업은 되돌릴 수 없으며, 관련된 모든 데이터(아이템 매핑 등)가 함께 삭제됩니다.
+ </AlertDialogDescription>
+ </AlertDialogHeader>
+ <AlertDialogFooter>
+ <AlertDialogCancel>취소</AlertDialogCancel>
+ <AlertDialogAction
+ onClick={handleDelete}
+ disabled={isDeleting}
+ className="bg-red-600 hover:bg-red-700"
+ >
+ {isDeleting ? "삭제 중..." : "삭제"}
+ </AlertDialogAction>
+ </AlertDialogFooter>
+ </AlertDialogContent>
+ </AlertDialog>
+ )
+}
diff --git a/lib/tech-vendors/contacts-table/update-contact-sheet.tsx b/lib/tech-vendors/contacts-table/update-contact-sheet.tsx
index 4713790c..877e8b4f 100644
--- a/lib/tech-vendors/contacts-table/update-contact-sheet.tsx
+++ b/lib/tech-vendors/contacts-table/update-contact-sheet.tsx
@@ -28,6 +28,7 @@ import { Loader2 } from "lucide-react"
import type { TechVendorContact } from "@/db/schema/techVendors"
import { updateTechVendorContactSchema, type UpdateTechVendorContactSchema } from "../validations"
import { updateTechVendorContact } from "../service"
+import { normalizeEmail } from "../utils"
interface UpdateContactSheetProps
extends React.ComponentPropsWithoutRef<typeof Sheet> {
@@ -67,13 +68,19 @@ export function UpdateContactSheet({ contact, vendorId, ...props }: UpdateContac
async function onSubmit(data: UpdateTechVendorContactSchema) {
if (!contact) return
-
+
startTransition(async () => {
try {
- const { error } = await updateTechVendorContact({
+ // 이메일을 소문자로 변환
+ const normalizedData = {
+ ...data,
+ contactEmail: normalizeEmail(data.contactEmail) || undefined,
+ }
+
+ const { error } = await updateTechVendorContact({
id: contact.id,
vendorId: vendorId,
- ...data
+ ...normalizedData,
})
if (error) throw new Error(error)