diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/dolce/actions.ts | 24 | ||||
| -rw-r--r-- | lib/dolce/dialogs/add-and-modify-detail-drawing-dialog.tsx | 139 | ||||
| -rw-r--r-- | lib/dolce/table/file-list-columns.tsx | 4 | ||||
| -rw-r--r-- | lib/dolce/table/gtt-drawing-list-columns.tsx | 2 |
4 files changed, 148 insertions, 21 deletions
diff --git a/lib/dolce/actions.ts b/lib/dolce/actions.ts index 5590ce8c..501c6cb0 100644 --- a/lib/dolce/actions.ts +++ b/lib/dolce/actions.ts @@ -138,7 +138,7 @@ export interface FileInfoItem { } export interface DetailDwgEditRequest { - Mode: "ADD" | "MOD"; + Mode: "ADD" | "MOD" | "DEL"; Status: string; RegisterId: number; ProjectNo: string; @@ -471,6 +471,28 @@ export async function fetchVendorProjects(): Promise< } } +/** + * 6. 파일 삭제 (FileInfoDeleteEdit) + */ +export async function deleteFileInfo(params: { + fileId: string; + uploadId: string; +}): Promise<number> { + try { + const response = await dolceApiCall<{ + FileInfoDeleteEditResult: number; + }>("FileInfoDeleteEdit", { + FileId: params.fileId, + UploadId: params.uploadId, + }); + + return response.FileInfoDeleteEditResult; + } catch (error) { + console.error("파일 삭제 실패:", error); + throw error; + } +} + // ============================================================================ // B4 일괄 업로드 관련 // ============================================================================ diff --git a/lib/dolce/dialogs/add-and-modify-detail-drawing-dialog.tsx b/lib/dolce/dialogs/add-and-modify-detail-drawing-dialog.tsx index 0253228b..54ec79a7 100644 --- a/lib/dolce/dialogs/add-and-modify-detail-drawing-dialog.tsx +++ b/lib/dolce/dialogs/add-and-modify-detail-drawing-dialog.tsx @@ -1,6 +1,6 @@ "use client"; -import { useState, useEffect } from "react"; +import { useState, useEffect, useCallback } from "react"; import { Dialog, DialogContent, @@ -20,7 +20,7 @@ import { } from "@/components/ui/select"; import { Alert, AlertDescription } from "@/components/ui/alert"; import { Textarea } from "@/components/ui/textarea"; -import { Upload, X, FileIcon, Info } from "lucide-react"; +import { Upload, X, FileIcon, Info, Trash2 } from "lucide-react"; import { toast } from "sonner"; import { useTranslation } from "@/i18n/client"; import { UnifiedDwgReceiptItem, DetailDwgReceiptItem, editDetailDwgReceipt } from "../actions"; @@ -34,6 +34,16 @@ import { getB4DrawingUsageOptions, getB4RegisterKindOptions } from "../utils/code-translator"; +import { + AlertDialog, + AlertDialogAction, + AlertDialogCancel, + AlertDialogContent, + AlertDialogDescription, + AlertDialogFooter as AlertDialogFooterComponent, + AlertDialogHeader, + AlertDialogTitle, +} from "@/components/ui/alert-dialog"; interface AddAndModifyDetailDrawingDialogProps { open: boolean; @@ -73,6 +83,10 @@ export function AddAndModifyDetailDrawingDialog({ const [isSubmitting, setIsSubmitting] = useState(false); const [showConfirmation, setShowConfirmation] = useState(false); + + // 삭제 관련 상태 + const [showDeleteConfirmation, setShowDeleteConfirmation] = useState(false); + const [isDeleting, setIsDeleting] = useState(false); // Edit 모드일 때 초기값 설정 useEffect(() => { @@ -150,7 +164,7 @@ export function AddAndModifyDetailDrawingDialog({ }; // 폼 초기화 - const resetForm = () => { + const resetForm = useCallback(() => { setDrawingUsage(""); setRegisterKind(""); setRevision(""); @@ -158,7 +172,7 @@ export function AddAndModifyDetailDrawingDialog({ setComment(""); clearFiles(); setShowConfirmation(false); - }; + }, [clearFiles]); // 제출 (확인 단계 포함) const handleSubmit = async () => { @@ -346,6 +360,59 @@ export function AddAndModifyDetailDrawingDialog({ } }; + // 상세도면 삭제 핸들러 + const handleDelete = async () => { + if (!detailDrawing) return; + + try { + setIsDeleting(true); + + const result = await editDetailDwgReceipt({ + dwgList: [ + { + Mode: "DEL", + Status: detailDrawing.Status, + RegisterId: detailDrawing.RegisterId, + ProjectNo: detailDrawing.ProjectNo, + Discipline: detailDrawing.Discipline, + DrawingKind: detailDrawing.DrawingKind, + DrawingNo: detailDrawing.DrawingNo, + DrawingName: detailDrawing.DrawingName, + RegisterGroupId: detailDrawing.RegisterGroupId, + RegisterSerialNo: detailDrawing.RegisterSerialNo, + RegisterKind: detailDrawing.RegisterKind, // 기존 값 유지 + DrawingRevNo: detailDrawing.DrawingRevNo, // 기존 값 유지 + Category: detailDrawing.Category, + Receiver: detailDrawing.Receiver, + Manager: detailDrawing.Manager, + RegisterDesc: detailDrawing.RegisterDesc, + UploadId: detailDrawing.UploadId, + RegCompanyCode: detailDrawing.RegCompanyCode || vendorCode, + }, + ], + userId, + userNm: userName, + vendorCode, + email: userEmail, + }); + + if (result > 0) { + toast.success("Detail drawing deleted successfully"); + setShowDeleteConfirmation(false); + resetForm(); + onComplete(); + onOpenChange(false); + } else { + toast.error("Failed to delete detail drawing"); + } + } catch (error) { + console.error("상세도면 삭제 실패:", error); + toast.error("An error occurred while deleting"); + } finally { + setIsDeleting(false); + } + }; + // DrawingUsage가 변경되면 RegisterKind 초기화 const handleDrawingUsageChange = (value: string) => { setDrawingUsage(value); @@ -631,19 +698,59 @@ export function AddAndModifyDetailDrawingDialog({ </div> )} - <DialogFooter> - <Button variant="outline" onClick={handleCancel} disabled={isSubmitting}> - {showConfirmation ? t("addDetailDialog.backButton", "뒤로") : t("addDetailDialog.cancelButton")} - </Button> - <Button onClick={handleSubmit} disabled={isSubmitting || !isFormValid}> - {isSubmitting - ? t("addDetailDialog.processingButton") - : showConfirmation - ? t("addDetailDialog.confirmSubmit", "제출") - : t("addDetailDialog.nextButton", "다음") - } - </Button> + <DialogFooter className={mode === "edit" && !showConfirmation ? "sm:justify-between" : ""}> + {mode === "edit" && !showConfirmation && ( + <Button + type="button" + variant="destructive" + onClick={() => setShowDeleteConfirmation(true)} + disabled={isSubmitting} + > + <Trash2 className="h-4 w-4 mr-2" /> + {t("editDetailDialog.deleteButton", "Delete")} + </Button> + )} + <div className="flex gap-2 justify-end sm:w-auto w-full"> + <Button variant="outline" onClick={handleCancel} disabled={isSubmitting}> + {showConfirmation ? t("addDetailDialog.backButton", "뒤로") : t("addDetailDialog.cancelButton")} + </Button> + <Button onClick={handleSubmit} disabled={isSubmitting || !isFormValid}> + {isSubmitting + ? t("addDetailDialog.processingButton") + : showConfirmation + ? t("addDetailDialog.confirmSubmit", "제출") + : t("addDetailDialog.nextButton", "다음") + } + </Button> + </div> </DialogFooter> + + {/* Delete Confirmation Dialog */} + <AlertDialog open={showDeleteConfirmation} onOpenChange={setShowDeleteConfirmation}> + <AlertDialogContent> + <AlertDialogHeader> + <AlertDialogTitle>Delete Detail Drawing</AlertDialogTitle> + <AlertDialogDescription> + Are you sure you want to delete this detail drawing? This action cannot be undone. + {detailDrawing && ( + <span className="block mt-2 font-medium text-foreground"> + {detailDrawing.DrawingNo} (Rev. {detailDrawing.DrawingRevNo}) + </span> + )} + </AlertDialogDescription> + </AlertDialogHeader> + <AlertDialogFooterComponent> + <AlertDialogCancel disabled={isDeleting}>Cancel</AlertDialogCancel> + <AlertDialogAction + onClick={handleDelete} + disabled={isDeleting} + className="bg-destructive text-destructive-foreground hover:bg-destructive/90" + > + {isDeleting ? "Deleting..." : "Delete"} + </AlertDialogAction> + </AlertDialogFooterComponent> + </AlertDialogContent> + </AlertDialog> </DialogContent> </Dialog> ); diff --git a/lib/dolce/table/file-list-columns.tsx b/lib/dolce/table/file-list-columns.tsx index e21f4382..30349063 100644 --- a/lib/dolce/table/file-list-columns.tsx +++ b/lib/dolce/table/file-list-columns.tsx @@ -35,7 +35,6 @@ export const createFileListColumns = ({ header: "Action", minSize: 50, cell: ({ row }) => { - const isLocal = row.original.FileServerId === "LOCAL"; const isDownloading = downloadingFileId === row.original.FileId; return ( @@ -55,7 +54,7 @@ export const createFileListColumns = ({ <Download className="h-4 w-4 mr-2" /> )} </Button> - {isLocal && onDelete && ( + {onDelete && ( <Button variant="destructive" size="sm" @@ -104,4 +103,3 @@ export const createFileListColumns = ({ }, ]; - diff --git a/lib/dolce/table/gtt-drawing-list-columns.tsx b/lib/dolce/table/gtt-drawing-list-columns.tsx index a72e221d..94d4d7d1 100644 --- a/lib/dolce/table/gtt-drawing-list-columns.tsx +++ b/lib/dolce/table/gtt-drawing-list-columns.tsx @@ -168,7 +168,7 @@ export function createGttDrawingListColumns({ { accessorKey: "CreateDt", header: t("drawingList.columns.createDt"), - minSize: 200, + minSize: 280, cell: ({ row }) => { const date = row.getValue("CreateDt") as string; return <div className="text-sm text-muted-foreground">{formatDolceDateTime(date)}</div>; |
