260728_01_ENH: 연구원 계정에 사업 삭제 기능 부여
This commit is contained in:
@@ -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}
|
||||
/>
|
||||
)}
|
||||
|
||||
|
||||
@@ -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<PerformanceCompact | null>(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({
|
||||
</div>
|
||||
|
||||
<DialogFooter className="shrink-0 border-t pt-4">
|
||||
{canDelete && draft && <Button type="button" variant="destructive" onClick={deletePerformance}>삭제</Button>}
|
||||
{canEdit && draft && !isEditing && <Button type="button" onClick={() => setIsEditing(true)}>수정</Button>}
|
||||
{canEdit && draft && isEditing && (
|
||||
<>
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user