678 lines
27 KiB
TypeScript
678 lines
27 KiB
TypeScript
"use client";
|
|
|
|
import {useCallback, useEffect, useMemo, useRef, useState} from "react";
|
|
import {Search, Upload} from "lucide-react";
|
|
import {Button} from "@/components/ui/button";
|
|
import {Input} from "@/components/ui/input";
|
|
import {DatePicker} from "@/components/common/DatePicker";
|
|
import {MultiFilterSelect} from "@/components/gwcf/MultiFilterSelect";
|
|
import {PagePanel} from "@/components/gwcf/PagePanel";
|
|
import {StatusPill} from "@/components/gwcf/StatusPill";
|
|
import {ExcelRegisterDialog} from "@/components/dialog/ExcelRegisterDialog";
|
|
import {PerformanceDetailDialog} from "@/components/dialog/PerformanceDetailDialog";
|
|
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,
|
|
usePerformanceDetailQuery,
|
|
usePerformanceListQuery,
|
|
useUpdatePerformanceMutation,
|
|
useUploadPerformanceExcelMutation,
|
|
} from "@/query/performance";
|
|
import {useUploadWrittenAssignExcelMutation} from "@/query/assign";
|
|
import {useDownloadReviewOriginalByPerformanceMutation, useDownloadReviewOriginalMutation, useDownloadReviewPdfMutation} from "@/query/review";
|
|
import {
|
|
filterPerformance,
|
|
getCodeLabel,
|
|
isInternalRole,
|
|
isResearcherRole,
|
|
isWrittenReviewerRole
|
|
} from "@/lib/gwcf/view";
|
|
import {
|
|
getMonitoringDisplayRow,
|
|
getMonitoringDisplayStatus,
|
|
getMonitoringFilterValue as getMonitoringStatusFilterValue,
|
|
getMonitoringRecordedAt,
|
|
getMonitoringRecordedUser,
|
|
getReviewByType,
|
|
getReviewFilterValue as getReviewStatusFilterValue,
|
|
getReviewStatusDisplay,
|
|
getWrittenReviewRows,
|
|
getWrittenReviewerSimpleReviewStatusDisplay,
|
|
isReviewComplete,
|
|
LOCAL_GOVERNMENT_REVIEW_TYPE,
|
|
statusFilterOptions, getCompleteRecordedAt, getReviewRecordedAt,
|
|
} from "@/lib/gwcf/performance-status";
|
|
import {useAuth} from "@/hooks/useAuth";
|
|
import {Code, PerformanceFull, PerformanceReview} from "@/types/gwcf";
|
|
import {useDialog} from "@/hooks/useDialog";
|
|
import {LoadingOverlay} from "@/components/common/LoadingOverlay";
|
|
import {useMounted} from "@/hooks/useMounted";
|
|
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
|
import {
|
|
downloadBlob,
|
|
downloadExcelBuffer, getReviewOriginalDownloadName,
|
|
getReviewPdfDownloadName,
|
|
openWrittenReviewWindow,
|
|
} from "@/lib/gwcf/file";
|
|
import ExcelDownloadButton from "@/components/common/ExcelDownloadButton";
|
|
import {PERFORMANCE_FIELD_LABELS} from "@/lib/gwcf/field-labels";
|
|
|
|
type PerformanceFilters = {
|
|
businessType: string[];
|
|
genre: string[];
|
|
area: string[];
|
|
startMonth: string[];
|
|
monitoringDate: string;
|
|
monitoringAdd: string[];
|
|
localReviewStatus: string[];
|
|
monitoring1Status: string[];
|
|
monitoring2Status: string[];
|
|
writtenReviewStatus: string[];
|
|
keyword: string;
|
|
};
|
|
|
|
const monthOptions: Code[] = [
|
|
{
|
|
codeGroup: "month",
|
|
codeValue: 0,
|
|
codeGroupLabel: PERFORMANCE_FIELD_LABELS.performanceStartMonth,
|
|
codeLabel: `미정`,
|
|
memo: "",
|
|
},
|
|
...Array.from({length: 12}, (_, index) => ({
|
|
codeGroup: "month",
|
|
codeValue: index + 1,
|
|
codeGroupLabel: PERFORMANCE_FIELD_LABELS.performanceStartMonth,
|
|
codeLabel: `${index + 1}월`,
|
|
memo: "",
|
|
}))
|
|
];
|
|
|
|
const monitoringAddOptions: Code[] = [
|
|
{
|
|
codeGroup: "monitoring_add",
|
|
codeValue: 0,
|
|
codeGroupLabel: PERFORMANCE_FIELD_LABELS.monitoringAdd,
|
|
codeLabel: "추가 X",
|
|
memo: "",
|
|
},
|
|
{
|
|
codeGroup: "monitoring_add",
|
|
codeValue: 1,
|
|
codeGroupLabel: PERFORMANCE_FIELD_LABELS.monitoringAdd,
|
|
codeLabel: "추가 O",
|
|
memo: "",
|
|
},
|
|
];
|
|
|
|
const getPerformanceGroupKey = (performanceId: number) => {
|
|
const id = String(performanceId);
|
|
return id.length > 2 ? id.slice(0, -2) : id;
|
|
};
|
|
|
|
const PerformancePage = () => {
|
|
const mounted = useMounted();
|
|
const {auth} = useAuth();
|
|
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();
|
|
const writtenAssignTemplateMutation = useDownloadAssignExcelTemplateMutation();
|
|
const exportMutation = useExportPerformanceMutation();
|
|
const reviewPdfMutation = useDownloadReviewPdfMutation();
|
|
const reviewOriginalMutation = useDownloadReviewOriginalMutation();
|
|
const reviewOriginalByPerformanceMutation = useDownloadReviewOriginalByPerformanceMutation();
|
|
|
|
const [filters, setFilters] = useState<PerformanceFilters>({
|
|
businessType: [],
|
|
genre: [],
|
|
area: [],
|
|
startMonth: [],
|
|
monitoringDate: "",
|
|
monitoringAdd: [],
|
|
localReviewStatus: [],
|
|
monitoring1Status: [],
|
|
monitoring2Status: [],
|
|
writtenReviewStatus: [],
|
|
keyword: "",
|
|
});
|
|
const debouncedFilters = useDebouncedValue(filters);
|
|
const [selectedId, setSelectedId] = useState<number | null>(null);
|
|
const lastSelectedRef = useRef<number | null>(null);
|
|
const filtersInitializedRef = useRef(false);
|
|
|
|
const detailOpen = isDialogOpen("performanceDetailDialog");
|
|
const performanceRegisterOpen = isDialogOpen("performanceExcelRegisterDialog");
|
|
const assignWrittenOpen = isDialogOpen("assignWrittenExcelDialog");
|
|
const {data: detailData} = usePerformanceDetailQuery(selectedId ?? 0, Boolean(selectedId && detailOpen && !isWrittenReviewer));
|
|
|
|
const refreshPerformanceList = () => {
|
|
void refetchPerformanceList();
|
|
};
|
|
|
|
const updateFilters = (updater: (prev: PerformanceFilters) => PerformanceFilters) => {
|
|
setFilters(updater);
|
|
};
|
|
|
|
useEffect(() => {
|
|
if (!filtersInitializedRef.current) {
|
|
filtersInitializedRef.current = true;
|
|
return;
|
|
}
|
|
|
|
void refetchPerformanceList();
|
|
}, [debouncedFilters, refetchPerformanceList]);
|
|
|
|
const handlePerformanceDetailOpenChange = (open: boolean) => {
|
|
if (open) {
|
|
showDialog("performanceDetailDialog");
|
|
return;
|
|
}
|
|
|
|
hideDialog("performanceDetailDialog");
|
|
refreshPerformanceList();
|
|
};
|
|
|
|
const handlePerformanceRegisterOpenChange = (open: boolean) => {
|
|
if (open) {
|
|
showDialog("performanceExcelRegisterDialog");
|
|
return;
|
|
}
|
|
|
|
hideDialog("performanceExcelRegisterDialog");
|
|
refreshPerformanceList();
|
|
};
|
|
|
|
const handleAssignWrittenOpenChange = (open: boolean) => {
|
|
if (open) {
|
|
showDialog("assignWrittenExcelDialog");
|
|
return;
|
|
}
|
|
|
|
hideDialog("assignWrittenExcelDialog");
|
|
refreshPerformanceList();
|
|
};
|
|
const matchesStatus = (filter: string[], value: string) => filter.length === 0 || filter.includes(value);
|
|
|
|
const localReviewStatusOptions = isWrittenReviewer
|
|
? [statusFilterOptions.incomplete, statusFilterOptions.done]
|
|
: [statusFilterOptions.pending, statusFilterOptions.done];
|
|
const monitoringStatusOptions = isWrittenReviewer
|
|
? [statusFilterOptions.incomplete, statusFilterOptions.done]
|
|
: [statusFilterOptions.pending, statusFilterOptions.departed, statusFilterOptions.arrived, statusFilterOptions.done];
|
|
const writtenReviewStatusOptions = isWrittenReviewer
|
|
? [statusFilterOptions.incomplete, statusFilterOptions.done]
|
|
: [statusFilterOptions.pending, statusFilterOptions.inProgress, statusFilterOptions.done];
|
|
|
|
const getVisibleWrittenReviewRow = useCallback((performance: PerformanceFull) => {
|
|
const rows = getWrittenReviewRows(performance);
|
|
if (!isWrittenReviewer) return rows[0];
|
|
return rows.find((row) => row.userId === userId && row.assign);
|
|
}, [isWrittenReviewer, userId]);
|
|
|
|
const filteredData = useMemo(() => {
|
|
return data.filter((item) => {
|
|
if (isWrittenReviewer && !getVisibleWrittenReviewRow(item)) return false;
|
|
|
|
const localReview = getReviewByType(item, LOCAL_GOVERNMENT_REVIEW_TYPE)?.review;
|
|
const writtenReviewRow = getVisibleWrittenReviewRow(item);
|
|
const monitoring1Row = getMonitoringDisplayRow(item, 0);
|
|
const monitoring1LatestVisit = monitoring1Row.slot.visit?.[0];
|
|
const monitoring2Row = getMonitoringDisplayRow(item, 1);
|
|
const monitoring2LatestVisit = monitoring2Row.slot.visit?.[0];
|
|
|
|
return (
|
|
filterPerformance(item, {
|
|
businessType: debouncedFilters.businessType,
|
|
genre: debouncedFilters.genre,
|
|
area: debouncedFilters.area,
|
|
monitoringDate: debouncedFilters.monitoringDate,
|
|
keyword: debouncedFilters.keyword,
|
|
}) &&
|
|
matchesStatus(debouncedFilters.startMonth, String(item.performanceStartMonth)) &&
|
|
matchesStatus(debouncedFilters.monitoringAdd, item.id % 100 === 1 ? "0" : "1") &&
|
|
matchesStatus(debouncedFilters.localReviewStatus, getReviewStatusFilterValue(
|
|
localReview,
|
|
getCodeLabel(codes, "review_status", localReview?.reviewStatus),
|
|
{isWrittenReviewer, alwaysAssigned: true}
|
|
)) &&
|
|
matchesStatus(debouncedFilters.monitoring1Status, getMonitoringStatusFilterValue(
|
|
monitoring1Row,
|
|
getCodeLabel(codes, "monitoring_visit_status", monitoring1LatestVisit?.monitoringVisitStatus),
|
|
getCodeLabel(codes, "review_status", monitoring1Row.review?.reviewStatus),
|
|
isWrittenReviewer
|
|
)) &&
|
|
matchesStatus(debouncedFilters.monitoring2Status, getMonitoringStatusFilterValue(
|
|
monitoring2Row,
|
|
getCodeLabel(codes, "monitoring_visit_status", monitoring2LatestVisit?.monitoringVisitStatus),
|
|
getCodeLabel(codes, "review_status", monitoring2Row.review?.reviewStatus),
|
|
isWrittenReviewer
|
|
)) &&
|
|
matchesStatus(debouncedFilters.writtenReviewStatus, getReviewStatusFilterValue(
|
|
writtenReviewRow?.review,
|
|
getCodeLabel(codes, "review_status", writtenReviewRow?.review?.reviewStatus),
|
|
{isWrittenReviewer, allowInProgress: true, assigned: Boolean(writtenReviewRow?.assign)}
|
|
))
|
|
);
|
|
});
|
|
}, [codes, data, debouncedFilters, getVisibleWrittenReviewRow, isWrittenReviewer]);
|
|
|
|
const openDetail = (performance: PerformanceFull) => {
|
|
if (isWrittenReviewer) return;
|
|
lastSelectedRef.current = performance.id;
|
|
setSelectedId(performance.id);
|
|
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;
|
|
const buffer = await reviewPdfMutation.mutateAsync({performanceId, reviewType: review.reviewType, userId: review.regUser});
|
|
downloadBlob(buffer, getReviewPdfDownloadName(performanceId, review.reviewType, review.pdfFileName), "application/pdf");
|
|
};
|
|
|
|
const downloadReviewOriginal = async (performanceId: number, review?: PerformanceReview) => {
|
|
if (!review || !isReviewComplete(review)) return;
|
|
if (!review.regUser) return;
|
|
const buffer = await reviewOriginalMutation.mutateAsync({performanceId, reviewType: review.reviewType, userId: review.regUser});
|
|
downloadBlob(buffer, getReviewOriginalDownloadName(performanceId, review.reviewType, review.uploadFileName));
|
|
};
|
|
|
|
const downloadMonitoringReviews = async (performanceId: number) => {
|
|
const reviewType = 1;
|
|
try {
|
|
const buffer = await reviewOriginalByPerformanceMutation.mutateAsync({performanceId, reviewType});
|
|
downloadBlob(buffer, `모니터링-${performanceId}-${reviewType}.zip`, "application/zip");
|
|
} catch {
|
|
alert("다운로드할 모니터링 파일을 찾을 수 없습니다.");
|
|
}
|
|
};
|
|
|
|
const openWrittenReviewLink = (performanceId: number, userId?: string, complete = false) => {
|
|
openWrittenReviewWindow(performanceId, userId, complete);
|
|
};
|
|
|
|
const renderReviewStatus = ({
|
|
performance,
|
|
review,
|
|
userId,
|
|
useWrittenLink = false,
|
|
alwaysAssigned = false,
|
|
noTooltip = false,
|
|
}: {
|
|
performance: PerformanceFull;
|
|
review?: PerformanceReview;
|
|
userId?: string;
|
|
useWrittenLink?: boolean;
|
|
alwaysAssigned?: boolean;
|
|
noTooltip?: boolean;
|
|
}) => {
|
|
const label = getCodeLabel(codes, "review_status", review?.reviewStatus);
|
|
const display = isWrittenReviewer
|
|
? getWrittenReviewerSimpleReviewStatusDisplay(review, false, label)
|
|
: getReviewStatusDisplay(label, review, alwaysAssigned || Boolean(review));
|
|
const complete = isReviewComplete(review);
|
|
const onClick = !useWrittenLink && isReviewComplete(review)
|
|
? () => downloadReviewOriginal(performance.id, review)
|
|
: useWrittenLink
|
|
? () => openWrittenReviewLink(performance.id, userId, complete)
|
|
: undefined;
|
|
|
|
return (
|
|
<div className="flex justify-center text-xs">
|
|
<StatusPill
|
|
variant={display.variant}
|
|
onClick={onClick}
|
|
tooltip={useWrittenLink || noTooltip ? undefined : (
|
|
<div className="space-y-1">
|
|
<div>사용자: {userId || "-"}</div>
|
|
<div>기록일시: {getReviewRecordedAt(review)}</div>
|
|
</div>
|
|
)}
|
|
>
|
|
{display.label}
|
|
</StatusPill>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
const renderMonitoringStatus = (performance: PerformanceFull, index: 0 | 1) => {
|
|
const row = getMonitoringDisplayRow(performance, index);
|
|
const latestVisit = row.slot.visit?.[0];
|
|
const display = getMonitoringDisplayStatus(
|
|
row,
|
|
getCodeLabel(codes, "monitoring_visit_status", latestVisit?.monitoringVisitStatus),
|
|
getCodeLabel(codes, "review_status", row.review?.reviewStatus),
|
|
isWrittenReviewer
|
|
);
|
|
const assignUser = row.slot.assign?.assignUser ?? "";
|
|
const visitUser = getMonitoringRecordedUser(latestVisit);
|
|
|
|
return (
|
|
<div className="flex justify-center text-xs">
|
|
<StatusPill
|
|
variant={display.variant}
|
|
onClick={isReviewComplete(row.review) ? () => downloadReviewOriginal(performance.id, row.review) : undefined}
|
|
tooltip={isWrittenReviewer ? undefined : (
|
|
<div className="space-y-1">
|
|
<div>사용자: {visitUser === "-" ? assignUser : visitUser}</div>
|
|
<div>출발: {getMonitoringRecordedAt(row.slot.timeline.departure)}</div>
|
|
<div>도착: {getMonitoringRecordedAt(row.slot.timeline.arrival)}</div>
|
|
<div>완료: {getCompleteRecordedAt(row.review)}</div>
|
|
</div>
|
|
)}
|
|
>
|
|
{display.label}
|
|
</StatusPill>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
const renderWrittenReviewerMonitoringStatus = (performance: PerformanceFull) => {
|
|
const groupKey = getPerformanceGroupKey(performance.id);
|
|
const monitoringRows = data
|
|
.filter((item) => getPerformanceGroupKey(item.id) === groupKey)
|
|
.flatMap((item) => ([0, 1] as const).map((index) => getMonitoringDisplayRow(item, index)));
|
|
|
|
const completeCount = monitoringRows.filter((item) => isReviewComplete(item.review)).length;
|
|
const totalCount = monitoringRows.length;
|
|
const display = completeCount === 0
|
|
? {label: "미완료", variant: "pending" as const}
|
|
: completeCount === totalCount
|
|
? {label: "완료", variant: "done" as const}
|
|
: {label: "일부 완료", variant: "inprogress" as const};
|
|
const onClick = completeCount > 0 ? () => downloadMonitoringReviews(performance.id) : undefined;
|
|
|
|
return (
|
|
<div className="flex justify-center text-xs">
|
|
<StatusPill
|
|
variant={display.variant}
|
|
onClick={onClick}
|
|
tooltip={(
|
|
<div className="space-y-1">
|
|
<div>완료: {completeCount}</div>
|
|
<div>전체: {totalCount}</div>
|
|
</div>
|
|
)}
|
|
>
|
|
{display.label}
|
|
</StatusPill>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
const columns = useMemo<DataTableColumn<PerformanceFull>[]>(() => [
|
|
{accessorKey: "no", header: PERFORMANCE_FIELD_LABELS.no,
|
|
accessorFn: (row) => row.performanceDetail["performanceNo"] ?? "",
|
|
cell: ({row}) => row.original.performanceDetail["performanceNo"] ?? "",
|
|
},
|
|
{accessorKey: "id", header: PERFORMANCE_FIELD_LABELS.id, cell: ({row}) => row.original.id},
|
|
...(!isWrittenReviewer ? [
|
|
{accessorKey: "monitoringAdd", header: PERFORMANCE_FIELD_LABELS.monitoringAdd,
|
|
accessorFn: (row) => row.id % 100 !== 1? "추가" : "",
|
|
cell: ({row}) => row.original.id % 100 !== 1? "추가" : "",
|
|
enableSorting: false
|
|
},
|
|
]: []) as DataTableColumn<PerformanceFull>[],
|
|
{
|
|
id: "businessType",
|
|
header: PERFORMANCE_FIELD_LABELS.businessType,
|
|
cell: ({row}) => {
|
|
const value = getCodeLabel(codes, "business_type", row.original.businessType);
|
|
return (
|
|
<div className="max-w-[130px] truncate" title={value}>
|
|
{value}
|
|
</div>
|
|
);
|
|
},
|
|
size: 130,
|
|
maxSize: 130,
|
|
},
|
|
{id: "genre", header: PERFORMANCE_FIELD_LABELS.performanceGenre, cell: ({row}) => getCodeLabel(codes, "genre", row.original.performanceGenre)},
|
|
{id: "area", header: PERFORMANCE_FIELD_LABELS.performanceArea, cell: ({row}) => getCodeLabel(codes, "area", row.original.performanceArea)},
|
|
{
|
|
accessorKey: "artistName",
|
|
header: PERFORMANCE_FIELD_LABELS.artistName,
|
|
cell: ({row}) => (
|
|
<div className="max-w-[120px] truncate" title={row.original.artistName}>
|
|
{row.original.artistName}
|
|
</div>
|
|
),
|
|
size: 120,
|
|
maxSize: 120,
|
|
},
|
|
{
|
|
accessorKey: "performanceName",
|
|
header: PERFORMANCE_FIELD_LABELS.performanceName,
|
|
cell: ({row}) => (
|
|
<div className="max-w-[300px] truncate" title={row.original.performanceName}>
|
|
{row.original.performanceName}
|
|
</div>
|
|
),
|
|
},
|
|
{id: "startMonth", header: PERFORMANCE_FIELD_LABELS.performanceStartMonth,
|
|
accessorFn: (row) => row.performanceStartMonth ?? 0,
|
|
cell: ({row}) => row.original.performanceStartMonth === 0? "미정":`${row.original.performanceStartMonth}월`},
|
|
{
|
|
accessorKey: "performanceDtInfo",
|
|
header: PERFORMANCE_FIELD_LABELS.performanceDtInfo,
|
|
cell: ({row}) => (
|
|
<div className="max-w-[65px] truncate" title={row.original.performanceDtInfo}>
|
|
{row.original.performanceDtInfo}
|
|
</div>
|
|
),
|
|
enableSorting: false
|
|
},
|
|
{
|
|
accessorKey: "performanceTimeInfo",
|
|
header: PERFORMANCE_FIELD_LABELS.performanceTimeInfo,
|
|
cell: ({row}) => (
|
|
<div className="max-w-[65px] truncate" title={row.original.performanceTimeInfo}>
|
|
{row.original.performanceTimeInfo}
|
|
</div>
|
|
),
|
|
enableSorting: false
|
|
},
|
|
...(!isWrittenReviewer ? [
|
|
{
|
|
id: "monitoringDate",
|
|
header: PERFORMANCE_FIELD_LABELS.monitoringDate,
|
|
accessorFn: (row) => row.performanceMonitoringSchedule?.monitoringDate ?? "",
|
|
cell: ({row}) => row.original.performanceMonitoringSchedule?.monitoringDate ?? "",
|
|
},
|
|
{
|
|
id: "timeTreeCheckDt",
|
|
header: PERFORMANCE_FIELD_LABELS.timeTreeCheckDt,
|
|
accessorFn: (row) => row.performanceDetail["timeTreeCheckDt"] ?? "",
|
|
cell: ({row}) => row.original.performanceDetail["timeTreeCheckDt"] ?? "",
|
|
}
|
|
]: []) as DataTableColumn<PerformanceFull>[],
|
|
{
|
|
id: "localReview",
|
|
header: "자체 보고서",
|
|
cell: ({row}) => {
|
|
if(row.original.id % 100 !== 1){
|
|
return "-";
|
|
}
|
|
|
|
const found = getReviewByType(row.original, LOCAL_GOVERNMENT_REVIEW_TYPE);
|
|
return renderReviewStatus({
|
|
performance: row.original,
|
|
review: found?.review,
|
|
userId: found?.userId,
|
|
alwaysAssigned: true,
|
|
noTooltip: isWrittenReviewer,
|
|
});
|
|
},
|
|
size:40,
|
|
},
|
|
...(!isWrittenReviewer ? [
|
|
{id: "monitoring1", header: "모니터링 1", cell: ({row}) => renderMonitoringStatus(row.original, 0), size:40,},
|
|
{id: "monitoring2", header: "모니터링 2", cell: ({row}) => renderMonitoringStatus(row.original, 1), size:40,},
|
|
] : [
|
|
{id: "monitoring", header: "모니터링", cell: ({row}) => renderWrittenReviewerMonitoringStatus(row.original), size:40,}
|
|
]) as DataTableColumn<PerformanceFull>[],
|
|
{
|
|
id: "writtenReview",
|
|
header: "서면 평가",
|
|
cell: ({row}) => {
|
|
if(row.original.id % 100 !== 1){
|
|
return "-";
|
|
}
|
|
|
|
const found = getVisibleWrittenReviewRow(row.original);
|
|
return renderReviewStatus({
|
|
performance: row.original,
|
|
review: found?.review,
|
|
userId: found?.userId,
|
|
useWrittenLink: isWrittenReviewer,
|
|
alwaysAssigned: Boolean(found?.assign),
|
|
});
|
|
},
|
|
size:40,
|
|
},
|
|
], [codes, data, getVisibleWrittenReviewRow, isWrittenReviewer]);
|
|
|
|
const downloadPerformanceTemplate = async () => {
|
|
const buffer = await performanceTemplateMutation.mutateAsync();
|
|
downloadExcelBuffer(buffer, "사업 등록 template.xlsx");
|
|
};
|
|
|
|
const downloadWrittenAssignTemplate = async () => {
|
|
const buffer = await writtenAssignTemplateMutation.mutateAsync();
|
|
downloadExcelBuffer(buffer, "서면 평가 배정 template.xlsx");
|
|
};
|
|
|
|
const downloadPerformance = async () => {
|
|
const performanceIds = filteredData.map((performance) => performance.id);
|
|
|
|
if (performanceIds.length === 0) {
|
|
alert("다운로드할 사업 정보가 없습니다.");
|
|
return;
|
|
}
|
|
|
|
const buffer = await exportMutation.mutateAsync({performanceIds});
|
|
downloadExcelBuffer(buffer, "사업 정보.xlsx");
|
|
};
|
|
|
|
if(!mounted) return <LoadingOverlay force={true} />
|
|
|
|
return (
|
|
<div className="space-y-4">
|
|
<PagePanel>
|
|
<div className="space-y-2">
|
|
<div className={isWrittenReviewer ? "grid gap-2 md:grid-cols-[280px_170px_140px_140px_1fr_auto]" : "grid gap-2 md:grid-cols-[280px_170px_140px_140px_140px_1fr_auto]"}>
|
|
<MultiFilterSelect value={filters.businessType} onChange={(value) => updateFilters((prev) => ({...prev, businessType: value}))} options={codes.business_type} placeholder={PERFORMANCE_FIELD_LABELS.businessType} />
|
|
<MultiFilterSelect value={filters.genre} onChange={(value) => updateFilters((prev) => ({...prev, genre: value}))} options={codes.genre} placeholder={PERFORMANCE_FIELD_LABELS.performanceGenre} />
|
|
<MultiFilterSelect value={filters.area} onChange={(value) => updateFilters((prev) => ({...prev, area: value}))} options={codes.area} placeholder={PERFORMANCE_FIELD_LABELS.performanceArea} />
|
|
<MultiFilterSelect value={filters.startMonth} onChange={(value) => updateFilters((prev) => ({...prev, startMonth: value}))} options={monthOptions} placeholder={PERFORMANCE_FIELD_LABELS.performanceStartMonth} />
|
|
{!isWrittenReviewer && (
|
|
<DatePicker value={filters.monitoringDate} onChange={(value) => updateFilters((prev) => ({...prev, monitoringDate: value}))} placeholder={PERFORMANCE_FIELD_LABELS.monitoringDate} />
|
|
)}
|
|
<Input value={filters.keyword} onChange={(event) => updateFilters((prev) => ({...prev, keyword: event.target.value}))} placeholder={`${PERFORMANCE_FIELD_LABELS.id} or ${PERFORMANCE_FIELD_LABELS.performanceName}`} />
|
|
<Button type="button" variant="outline" onClick={refreshPerformanceList}>
|
|
<Search className="h-4 w-4" />
|
|
검색
|
|
</Button>
|
|
</div>
|
|
<div className="grid gap-2 md:grid-cols-[183px_183px_183px_183px_183px]">
|
|
{!isWrittenReviewer && (
|
|
<MultiFilterSelect value={filters.monitoringAdd} onChange={(value) => updateFilters((prev) => ({...prev, monitoringAdd: value}))} options={monitoringAddOptions} placeholder={PERFORMANCE_FIELD_LABELS.monitoringAdd} />
|
|
)}
|
|
<MultiFilterSelect value={filters.localReviewStatus} onChange={(value) => updateFilters((prev) => ({...prev, localReviewStatus: value}))} options={localReviewStatusOptions} placeholder="자체 보고서 상태" />
|
|
<MultiFilterSelect value={filters.monitoring1Status} onChange={(value) => updateFilters((prev) => ({...prev, monitoring1Status: value}))} options={monitoringStatusOptions} placeholder="모니터링1 상태" />
|
|
<MultiFilterSelect value={filters.monitoring2Status} onChange={(value) => updateFilters((prev) => ({...prev, monitoring2Status: value}))} options={monitoringStatusOptions} placeholder="모니터링2 상태" />
|
|
<MultiFilterSelect value={filters.writtenReviewStatus} onChange={(value) => updateFilters((prev) => ({...prev, writtenReviewStatus: value}))} options={writtenReviewStatusOptions} placeholder="서면평가 상태" />
|
|
</div>
|
|
</div>
|
|
</PagePanel>
|
|
|
|
<PagePanel>
|
|
{!isWrittenReviewer && (
|
|
<div className="mb-3 flex justify-end gap-2">
|
|
{canEdit && (
|
|
<>
|
|
<Button type="button" onClick={() => showDialog("performanceExcelRegisterDialog")}>
|
|
<Upload className="h-4 w-4" />
|
|
사업 등록
|
|
</Button>
|
|
<Button type="button" variant="outline" onClick={() => showDialog("assignWrittenExcelDialog")}>
|
|
서면 평가 배정
|
|
</Button>
|
|
</>
|
|
)}
|
|
<ExcelDownloadButton requestExcelExport={downloadPerformance} />
|
|
</div>
|
|
)}
|
|
|
|
<DataTable
|
|
columns={columns}
|
|
data={filteredData}
|
|
getRowId={(row) => String(row.id)}
|
|
selectMode={isWrittenReviewer ? "none" : "click-event"}
|
|
onRowClick={isWrittenReviewer ? undefined : openDetail}
|
|
defaultPageSize={10}
|
|
headerFontClass="content-text-base"
|
|
cellFontClass="content-text-sm"
|
|
/>
|
|
</PagePanel>
|
|
|
|
{!isWrittenReviewer && (
|
|
<PerformanceDetailDialog
|
|
open={detailOpen}
|
|
onOpenChange={handlePerformanceDetailOpenChange}
|
|
performance={detailData ?? data.find((item) => item.id === selectedId) ?? null}
|
|
codes={codes}
|
|
canEdit={canEdit}
|
|
canDelete={canDelete}
|
|
onSave={(draft) => updateMutation.mutate(draft)}
|
|
onDelete={deletePerformance}
|
|
/>
|
|
)}
|
|
|
|
<ExcelRegisterDialog
|
|
open={performanceRegisterOpen}
|
|
onOpenChange={handlePerformanceRegisterOpenChange}
|
|
title="사업 등록"
|
|
onDownloadTemplate={downloadPerformanceTemplate}
|
|
onUpload={(file) => performanceUploadMutation.mutateAsync(file)}
|
|
isUploading={performanceUploadMutation.isPending}
|
|
/>
|
|
|
|
<ExcelRegisterDialog
|
|
open={assignWrittenOpen}
|
|
onOpenChange={handleAssignWrittenOpenChange}
|
|
title="서면 평가 위원 배정"
|
|
onDownloadTemplate={downloadWrittenAssignTemplate}
|
|
onUpload={(file) => writtenAssignUploadMutation.mutateAsync(file)}
|
|
isUploading={writtenAssignUploadMutation.isPending}
|
|
/>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default PerformancePage;
|