diff --git a/src/app/(pages)/(main)/performance/page.tsx b/src/app/(pages)/(main)/performance/page.tsx index e534d0f..fa86707 100644 --- a/src/app/(pages)/(main)/performance/page.tsx +++ b/src/app/(pages)/(main)/performance/page.tsx @@ -14,6 +14,7 @@ import {DataTable} from "@/components/data-table/DataTable"; import {DataTableColumn} from "@/components/data-table/DataTable.type"; import {useCodesQuery} from "@/query/code"; import { + useDeletePerformanceMutation, useDownloadAssignExcelTemplateMutation, useDownloadPerformanceExcelTemplateMutation, useExportPerformanceMutation, @@ -24,7 +25,13 @@ import { } from "@/query/performance"; import {useUploadWrittenAssignExcelMutation} from "@/query/assign"; import {useDownloadReviewOriginalByPerformanceMutation, useDownloadReviewOriginalMutation, useDownloadReviewPdfMutation} from "@/query/review"; -import {filterPerformance, getCodeLabel, isInternalRole, isWrittenReviewerRole} from "@/lib/gwcf/view"; +import { + filterPerformance, + getCodeLabel, + isInternalRole, + isResearcherRole, + isWrittenReviewerRole +} from "@/lib/gwcf/view"; import { getMonitoringDisplayRow, getMonitoringDisplayStatus, @@ -114,12 +121,14 @@ const PerformancePage = () => { const userRole = auth.user?.userRole; const userId = auth.user?.userId; const canEdit = isInternalRole(userRole); + const canDelete = isResearcherRole(userRole); const isWrittenReviewer = isWrittenReviewerRole(userRole); const {isDialogOpen, showDialog, hideDialog} = useDialog(); const {data: codes} = useCodesQuery(); const {data = [], refetch: refetchPerformanceList} = usePerformanceListQuery(); const updateMutation = useUpdatePerformanceMutation(); + const deleteMutation = useDeletePerformanceMutation(); const performanceUploadMutation = useUploadPerformanceExcelMutation(); const writtenAssignUploadMutation = useUploadWrittenAssignExcelMutation(); const performanceTemplateMutation = useDownloadPerformanceExcelTemplateMutation(); @@ -270,6 +279,14 @@ const PerformancePage = () => { showDialog("performanceDetailDialog"); }; + const deletePerformance = async (performanceId: number) => { + if (!performanceId) return; + await deleteMutation.mutateAsync(performanceId); + alert("삭제되었습니다."); + + window.location.replace("/performance"); + }; + const downloadReviewPdf = async (performanceId: number, review?: PerformanceReview) => { if (!review || !isReviewComplete(review)) return; if (!review.regUser) return; @@ -630,7 +647,9 @@ const PerformancePage = () => { performance={detailData ?? data.find((item) => item.id === selectedId) ?? null} codes={codes} canEdit={canEdit} + canDelete={canDelete} onSave={(draft) => updateMutation.mutate(draft)} + onDelete={deletePerformance} /> )} diff --git a/src/components/dialog/PerformanceDetailDialog.tsx b/src/components/dialog/PerformanceDetailDialog.tsx index e66d989..6a91935 100644 --- a/src/components/dialog/PerformanceDetailDialog.tsx +++ b/src/components/dialog/PerformanceDetailDialog.tsx @@ -426,14 +426,18 @@ export function PerformanceDetailDialog({ performance, codes, canEdit, + canDelete, onSave, + onDelete, }: Readonly<{ open: boolean; onOpenChange: (open: boolean) => void; performance: PerformanceFull | PerformanceCompact | null; codes: CodeMap; canEdit: boolean; + canDelete: boolean; onSave?: (performance: PerformanceCompact) => void; + onDelete?: (performanceId: number) => void; }>) { const [draft, setDraft] = useState(null); const [isEditing, setIsEditing] = useState(false); @@ -535,6 +539,14 @@ export function PerformanceDetailDialog({ setIsEditing(false); }; + const deletePerformance = () => { + if(!draft) return; + + if(confirm("삭제 되면 복구할 수 없습니다. 삭제를 진행 하시겠습니까?")){ + onDelete?.(draft.id); + } + } + const downloadTemplate = (reviewType: number, classification: number) => { downloadFromUrl(`/api/review/template/download/${reviewType}/${classification}`); }; @@ -633,6 +645,7 @@ export function PerformanceDetailDialog({ + {canDelete && draft && } {canEdit && draft && !isEditing && } {canEdit && draft && isEditing && ( <> diff --git a/src/lib/gwcf/view.ts b/src/lib/gwcf/view.ts index 9beb35a..8b8578e 100644 --- a/src/lib/gwcf/view.ts +++ b/src/lib/gwcf/view.ts @@ -16,6 +16,7 @@ export const getRoleGroup = (role?: number | null) => { return Math.floor(role / 1000) * 1000; }; +export const isResearcherRole = (role?: number | null) => !role ? false : role <= ROLE.RESEARCHER; export const isInternalRole = (role?: number | null) => getRoleGroup(role) === 1000; export const isExternalRole = (role?: number | null) => getRoleGroup(role) === 2000; export const isMonitoringRole = (role?: number | null) => getRoleGroup(role) === 9000;