260623_01_ENH: 엑셀 다운로드를 제외한 기능 완성
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
"use client";
|
||||
|
||||
import {ReactNode, useEffect, useMemo, useState} from "react";
|
||||
import {Download, ImageIcon, Upload} from "lucide-react";
|
||||
import {ReactNode, useEffect, useMemo, useRef, useState} from "react";
|
||||
import {Download, ImageIcon, ScanSearch, Upload} from "lucide-react";
|
||||
import {Button} from "@/components/ui/button";
|
||||
import {Input} from "@/components/ui/input";
|
||||
import {Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle} from "@/components/ui/dialog";
|
||||
@@ -12,27 +12,36 @@ import {Code, PerformanceCompact, PerformanceFull, PerformanceMonitoringSchedule
|
||||
import {CodeGroup} from "@/query/code";
|
||||
import {getCodeLabel, getDetailValue, ROLE} from "@/lib/gwcf/view";
|
||||
import {
|
||||
getMonitoringDisplayRow,
|
||||
getMonitoringDisplayStatus,
|
||||
getMonitoringRecordedAt,
|
||||
getMonitoringRecordedUser,
|
||||
getMonitoringSlots,
|
||||
getMonitoringStatusDisplay,
|
||||
getReviewByType,
|
||||
getReviewStatusDisplay,
|
||||
getWrittenReviewRows,
|
||||
isReviewComplete,
|
||||
LOCAL_GOVERNMENT_REVIEW_TYPE,
|
||||
} from "@/lib/gwcf/performance-status";
|
||||
import {buildWrittenReviewLink} from "@/config/gwcf.config";
|
||||
import {
|
||||
useDownloadReviewOriginalMutation,
|
||||
useDownloadReviewPdfMutation,
|
||||
useEndWrittenReviewMutation,
|
||||
useReviewFileQuery,
|
||||
useStartWrittenReviewMutation,
|
||||
useUploadReviewFileMutation,
|
||||
} from "@/query/review";
|
||||
import {useDownloadEvidenceZipMutation} from "@/query/monitoring";
|
||||
import {downloadFile} from "@/lib/utils";
|
||||
import {useDownloadEvidenceZipMutation, useMonitoringEvidenceQuery} from "@/query/monitoring";
|
||||
import {useUsersQuery} from "@/query/user";
|
||||
import {useLoading} from "@/hooks/useLoading";
|
||||
import {
|
||||
buildEvidenceImageSrc,
|
||||
buildImagePreviewUrl,
|
||||
buildReviewPdfPreviewUrl,
|
||||
downloadBlob,
|
||||
downloadFromUrl,
|
||||
getEvidenceZipDownloadName,
|
||||
getReviewOriginalDownloadName,
|
||||
getReviewPdfDownloadName,
|
||||
openPreviewWindow,
|
||||
openWrittenReviewWindow,
|
||||
} from "@/lib/gwcf/file";
|
||||
|
||||
type CodeMap = Partial<Record<CodeGroup, Code[]>>;
|
||||
|
||||
@@ -50,13 +59,13 @@ function FileActionButton({
|
||||
icon = "download",
|
||||
disabled = false,
|
||||
onClick,
|
||||
}: {
|
||||
}: Readonly<{
|
||||
children: ReactNode;
|
||||
icon?: "download" | "upload" | "image";
|
||||
icon?: "download" | "upload" | "image" | "preview";
|
||||
disabled?: boolean;
|
||||
onClick?: () => void;
|
||||
}) {
|
||||
const Icon = icon === "upload" ? Upload : icon === "image" ? ImageIcon : Download;
|
||||
}>) {
|
||||
const Icon = icon === "upload" ? Upload : icon === "image" ? ImageIcon : icon === "preview" ? ScanSearch : Download;
|
||||
return (
|
||||
<Button type="button" size="xs" variant="outline" disabled={disabled} onClick={onClick}>
|
||||
<Icon className="h-3 w-3" />
|
||||
@@ -70,12 +79,12 @@ function AssignedUserInfo({
|
||||
user,
|
||||
codes,
|
||||
type,
|
||||
}: {
|
||||
}: Readonly<{
|
||||
userId?: string;
|
||||
user?: UserFull;
|
||||
codes: CodeMap;
|
||||
type: "monitoring" | "written";
|
||||
}) {
|
||||
}>) {
|
||||
const detail = user?.userDetail;
|
||||
const tel = getDetailValue(detail, ["tel", "phone", "userTel"], "-");
|
||||
const email = getDetailValue(detail, ["email", "userEmail"], "-");
|
||||
@@ -98,66 +107,123 @@ function AssignedUserInfo({
|
||||
);
|
||||
}
|
||||
|
||||
const downloadBlob = (buffer: ArrayBuffer, fileName: string, type = "application/octet-stream") => {
|
||||
const blob = new Blob([buffer], {type});
|
||||
downloadFile(blob, fileName);
|
||||
};
|
||||
|
||||
function ReviewFileActions({
|
||||
performanceId,
|
||||
reviewType,
|
||||
userId,
|
||||
uploadFileName,
|
||||
pdfFileName,
|
||||
}: {
|
||||
canEdit,
|
||||
}: Readonly<{
|
||||
performanceId: number;
|
||||
reviewType: number;
|
||||
userId?: string;
|
||||
uploadFileName?: string;
|
||||
pdfFileName?: string;
|
||||
}) {
|
||||
canEdit: boolean;
|
||||
}>) {
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
const uploadMutation = useUploadReviewFileMutation();
|
||||
const originalMutation = useDownloadReviewOriginalMutation();
|
||||
const pdfMutation = useDownloadReviewPdfMutation();
|
||||
const {withLoadingAsync} = useLoading();
|
||||
const complete = Boolean(pdfFileName);
|
||||
|
||||
const upload = (file?: File) => {
|
||||
if (!file) return;
|
||||
uploadMutation.mutate({performanceId, reviewType, file});
|
||||
const upload = async (file?: File) => {
|
||||
try {
|
||||
if (!file) return;
|
||||
await withLoadingAsync(() => uploadMutation.mutateAsync({performanceId, reviewType, file}));
|
||||
alert("파일 업로드가 완료되었습니다.");
|
||||
} finally {
|
||||
if (fileInputRef.current) fileInputRef.current.value = "";
|
||||
}
|
||||
};
|
||||
|
||||
const downloadOriginal = async () => {
|
||||
const buffer = await originalMutation.mutateAsync({performanceId, reviewType});
|
||||
downloadBlob(buffer, uploadFileName || `review-original-${performanceId}-${reviewType}`);
|
||||
if (!userId) return;
|
||||
const buffer = await originalMutation.mutateAsync({ performanceId, reviewType, userId });
|
||||
downloadBlob(
|
||||
buffer,
|
||||
getReviewOriginalDownloadName(performanceId, reviewType, uploadFileName)
|
||||
);
|
||||
};
|
||||
|
||||
const downloadPdf = async () => {
|
||||
const buffer = await pdfMutation.mutateAsync({performanceId, reviewType});
|
||||
downloadBlob(buffer, pdfFileName || `review-pdf-${performanceId}-${reviewType}.pdf`, "application/pdf");
|
||||
if (!userId) return;
|
||||
const buffer = await pdfMutation.mutateAsync({ performanceId, reviewType, userId });
|
||||
downloadBlob(
|
||||
buffer,
|
||||
getReviewPdfDownloadName(performanceId, reviewType, pdfFileName),
|
||||
"application/pdf"
|
||||
);
|
||||
};
|
||||
|
||||
const previewPdf = () => {
|
||||
if (!pdfFileName || !userId) return;
|
||||
openPreviewWindow(buildReviewPdfPreviewUrl(performanceId, reviewType, userId, pdfFileName));
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-wrap gap-1">
|
||||
<label>
|
||||
<input type="file" className="hidden" onChange={(event) => upload(event.target.files?.[0])} />
|
||||
<FileActionButton icon="upload" disabled={uploadMutation.isPending}>파일 업로드</FileActionButton>
|
||||
</label>
|
||||
<FileActionButton icon="download" disabled={!uploadFileName || originalMutation.isPending} onClick={downloadOriginal}>원본</FileActionButton>
|
||||
<FileActionButton icon="download" disabled={!pdfFileName || pdfMutation.isPending} onClick={downloadPdf}>PDF</FileActionButton>
|
||||
{canEdit && (
|
||||
<>
|
||||
<input ref={fileInputRef} type="file" className="hidden" onChange={(event) => void upload(event.target.files?.[0])} />
|
||||
<FileActionButton icon="upload" disabled={uploadMutation.isPending || !complete} onClick={() => fileInputRef.current?.click()}>파일 업로드</FileActionButton>
|
||||
</>
|
||||
)}
|
||||
<FileActionButton icon="download" disabled={!userId || !uploadFileName || originalMutation.isPending} onClick={downloadOriginal}>원본</FileActionButton>
|
||||
<FileActionButton icon="download" disabled={!userId || !pdfFileName || pdfMutation.isPending} onClick={downloadPdf}>PDF</FileActionButton>
|
||||
<FileActionButton icon="preview" disabled={!userId || !pdfFileName} onClick={previewPdf}>미리보기</FileActionButton>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function EvidenceZipButton({performanceId, userId}: {performanceId: number; userId: string}) {
|
||||
const {data: evidenceList = []} = useMonitoringEvidenceQuery(performanceId, userId, performanceId > 0 && Boolean(userId));
|
||||
const zipMutation = useDownloadEvidenceZipMutation();
|
||||
const download = async () => {
|
||||
const buffer = await zipMutation.mutateAsync({performanceId, userId});
|
||||
downloadBlob(buffer, `monitoring-evidence-${performanceId}-${userId}.zip`, "application/zip");
|
||||
downloadBlob(buffer, getEvidenceZipDownloadName(performanceId, userId), "application/zip");
|
||||
};
|
||||
|
||||
return <FileActionButton icon="image" disabled={zipMutation.isPending} onClick={download}>증빙사진</FileActionButton>;
|
||||
const preview = () => {
|
||||
const images = evidenceList
|
||||
.flatMap((item) =>
|
||||
(item.evidenceImg ?? "")
|
||||
.split("|")
|
||||
.map((fileName) => fileName.trim())
|
||||
.filter(Boolean)
|
||||
)
|
||||
.map((fileName) => buildEvidenceImageSrc(performanceId, userId, fileName));
|
||||
|
||||
if (images.length === 0) {
|
||||
alert("미리보기할 증빙사진이 없습니다.");
|
||||
return;
|
||||
}
|
||||
|
||||
openPreviewWindow(buildImagePreviewUrl("증빙 미리보기", images));
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-wrap gap-1">
|
||||
<FileActionButton icon="image" disabled={zipMutation.isPending} onClick={download}>다운로드</FileActionButton>
|
||||
<FileActionButton icon="preview" disabled={evidenceList.length === 0} onClick={preview}>증빙 미리보기</FileActionButton>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function LocalGovernmentReviewRow({performanceId, codes}: {performanceId: number; codes: CodeMap}) {
|
||||
function LocalGovernmentReviewRow({
|
||||
performance,
|
||||
codes,
|
||||
}: {
|
||||
performance: PerformanceFull | PerformanceCompact;
|
||||
codes: CodeMap;
|
||||
}) {
|
||||
const reviewType = LOCAL_GOVERNMENT_REVIEW_TYPE;
|
||||
const {data: review} = useReviewFileQuery(performanceId, reviewType, performanceId > 0);
|
||||
const fallbackReviewRow = getReviewByType(performance as PerformanceFull, reviewType);
|
||||
const userId = fallbackReviewRow?.review.regUser || fallbackReviewRow?.userId;
|
||||
const {data: fetchedReview} = useReviewFileQuery(performance.id, reviewType, userId, performance.id > 0 && Boolean(userId));
|
||||
const review = fetchedReview ?? fallbackReviewRow?.review;
|
||||
const label = getCodeLabel(codes, "review_status", review?.reviewStatus);
|
||||
const display = getReviewStatusDisplay(label, review, true);
|
||||
|
||||
@@ -166,7 +232,7 @@ function LocalGovernmentReviewRow({performanceId, codes}: {performanceId: number
|
||||
<div className="font-semibold">지자체</div>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<StatusPill variant={display.variant}>{display.label}</StatusPill>
|
||||
<ReviewFileActions performanceId={performanceId} reviewType={reviewType} uploadFileName={review?.uploadFileName} pdfFileName={review?.pdfFileName} />
|
||||
<ReviewFileActions performanceId={performance.id} reviewType={reviewType} userId={review?.regUser || userId} uploadFileName={review?.uploadFileName} pdfFileName={review?.pdfFileName} canEdit={true} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
@@ -177,37 +243,48 @@ function MonitoringStatusRow({
|
||||
index,
|
||||
codes,
|
||||
userMap,
|
||||
}: {
|
||||
canEdit,
|
||||
}: Readonly<{
|
||||
performance: PerformanceFull | PerformanceCompact;
|
||||
index: 0 | 1;
|
||||
codes: CodeMap;
|
||||
userMap: Map<string, UserFull>;
|
||||
}) {
|
||||
const slot = getMonitoringSlots(performance as PerformanceFull)[index];
|
||||
const user = slot.assign?.assignUser ? userMap.get(slot.assign.assignUser) : undefined;
|
||||
const reviewType = index + 1;
|
||||
const {data: review} = useReviewFileQuery(performance.id, reviewType, performance.id > 0);
|
||||
const label = getCodeLabel(codes, "monitoring_visit_status", slot.visit?.monitoringVisitStatus);
|
||||
const display = getMonitoringStatusDisplay(label, slot);
|
||||
canEdit: boolean;
|
||||
}>) {
|
||||
const row = getMonitoringDisplayRow(performance as PerformanceFull, index);
|
||||
const user = row.userId ? userMap.get(row.userId) : undefined;
|
||||
const latestVisit = row.slot.visit?.[0];
|
||||
const display = getMonitoringDisplayStatus(
|
||||
row,
|
||||
getCodeLabel(codes, "monitoring_visit_status", latestVisit?.monitoringVisitStatus),
|
||||
getCodeLabel(codes, "review_status", row.review?.reviewStatus)
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="space-y-2 border-b p-3">
|
||||
<div className="font-semibold">모니터링 {index + 1}</div>
|
||||
<div className="grid gap-1 text-sm">
|
||||
<AssignedUserInfo userId={slot.assign?.assignUser} user={user} codes={codes} type="monitoring" />
|
||||
<div>기록 사용자: {getMonitoringRecordedUser(slot.visit)}</div>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<AssignedUserInfo userId={row.userId} user={user} codes={codes} type="monitoring" />
|
||||
<div className="flex flex-wrap items-center gap-2 mb-2">
|
||||
<StatusPill variant={display.variant}>{display.label}</StatusPill>
|
||||
<ReviewFileActions performanceId={performance.id} reviewType={reviewType} uploadFileName={review?.uploadFileName} pdfFileName={review?.pdfFileName} />
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<span>모니터링 출발/도착 기록: {getMonitoringRecordedAt(slot.visit)}</span>
|
||||
{slot.assign?.assignUser ? (
|
||||
<EvidenceZipButton performanceId={performance.id} userId={slot.assign.assignUser} />
|
||||
) : (
|
||||
<FileActionButton icon="image" disabled>증빙사진</FileActionButton>
|
||||
)}
|
||||
<ReviewFileActions performanceId={performance.id} reviewType={row.reviewType} userId={row.review?.regUser || row.userId} uploadFileName={row.review?.uploadFileName} pdfFileName={row.review?.pdfFileName} canEdit={canEdit} />
|
||||
</div>
|
||||
{row.slot.visit?.length ? (
|
||||
<>
|
||||
<div className="rounded-md border bg-muted/30 p-2 text-sm">
|
||||
<div className="grid gap-1 text-xs text-muted-foreground sm:grid-cols-1">
|
||||
<span>출발: {getMonitoringRecordedAt(row.slot.timeline.departure)}</span>
|
||||
<span>도착: {getMonitoringRecordedAt(row.slot.timeline.arrival)}</span>
|
||||
</div>
|
||||
</div>
|
||||
{row.slot.timeline.arrival && row.evidenceUserId && (
|
||||
<EvidenceZipButton
|
||||
performanceId={performance.id}
|
||||
userId={row.evidenceUserId}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
@@ -216,16 +293,14 @@ function MonitoringStatusRow({
|
||||
function WrittenReviewRows({
|
||||
performance,
|
||||
codes,
|
||||
isWrittenReviewer,
|
||||
userMap,
|
||||
}: {
|
||||
canEdit,
|
||||
}: Readonly<{
|
||||
performance: PerformanceFull | PerformanceCompact;
|
||||
codes: CodeMap;
|
||||
isWrittenReviewer: boolean;
|
||||
userMap: Map<string, UserFull>;
|
||||
}) {
|
||||
const startMutation = useStartWrittenReviewMutation();
|
||||
const endMutation = useEndWrittenReviewMutation();
|
||||
canEdit: boolean;
|
||||
}>) {
|
||||
const rows = getWrittenReviewRows(performance as PerformanceFull);
|
||||
|
||||
if(rows.length === 0){
|
||||
@@ -233,7 +308,7 @@ function WrittenReviewRows({
|
||||
}
|
||||
|
||||
const openWrittenReviewLink = (userId: string, complete: boolean) => {
|
||||
window.open(buildWrittenReviewLink({performanceId: performance.id, userId, complete}), "_blank", "noopener,noreferrer");
|
||||
openWrittenReviewWindow(performance.id, userId, complete);
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -250,20 +325,12 @@ function WrittenReviewRows({
|
||||
<div key={`${userId}-${reviewType}`} className="space-y-2 border-b p-3 last:border-b-0">
|
||||
<AssignedUserInfo userId={userId} user={user} codes={codes} type="written" />
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<StatusPill variant={display.variant} onClick={isWrittenReviewer ? () => openWrittenReviewLink(userId, complete) : undefined}>
|
||||
<StatusPill variant={display.variant} onClick={complete ? () => openWrittenReviewLink(userId, true) : undefined}>
|
||||
{display.label}
|
||||
</StatusPill>
|
||||
{isWrittenReviewer && (
|
||||
<Button type="button" size="xs" variant="outline" onClick={() => openWrittenReviewLink(userId, complete)}>
|
||||
평가 링크
|
||||
</Button>
|
||||
)}
|
||||
<Button type="button" size="xs" variant="outline" onClick={() => startMutation.mutate(performance.id)}>
|
||||
평가진행
|
||||
</Button>
|
||||
{complete && (
|
||||
<Button type="button" size="xs" variant="outline" onClick={() => endMutation.mutate({performanceId: performance.id, userId})}>
|
||||
평가완료
|
||||
{canEdit && (
|
||||
<Button type="button" size="xs" variant="outline" disabled={!complete} onClick={() => openWrittenReviewLink(userId, false)}>
|
||||
평가 수정
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
@@ -281,17 +348,15 @@ export function PerformanceDetailDialog({
|
||||
performance,
|
||||
codes,
|
||||
canEdit,
|
||||
isWrittenReviewer = false,
|
||||
onSave,
|
||||
}: {
|
||||
}: Readonly<{
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
performance: PerformanceFull | PerformanceCompact | null;
|
||||
codes: CodeMap;
|
||||
canEdit: boolean;
|
||||
isWrittenReviewer?: boolean;
|
||||
onSave?: (performance: PerformanceCompact) => void;
|
||||
}) {
|
||||
}>) {
|
||||
const [draft, setDraft] = useState<PerformanceCompact | null>(null);
|
||||
const [isEditing, setIsEditing] = useState(false);
|
||||
const {data: monitoringUsers = []} = useUsersQuery(ROLE.MONITORING, open);
|
||||
@@ -382,6 +447,10 @@ export function PerformanceDetailDialog({
|
||||
setIsEditing(false);
|
||||
};
|
||||
|
||||
const downloadTemplate = (reviewType: number) => {
|
||||
downloadFromUrl(`/api/review/template/download/${reviewType}`);
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="flex max-h-[90vh] flex-col overflow-hidden sm:max-w-6xl">
|
||||
@@ -445,11 +514,23 @@ export function PerformanceDetailDialog({
|
||||
</div>
|
||||
|
||||
<section className="rounded-md border">
|
||||
<div className="border-b bg-muted px-3 py-2 font-semibold">평가 및 모니터링 현황</div>
|
||||
<LocalGovernmentReviewRow performanceId={draft.id} codes={codes} />
|
||||
<MonitoringStatusRow performance={performance ?? draft} index={0} codes={codes} userMap={monitoringUserMap} />
|
||||
<MonitoringStatusRow performance={performance ?? draft} index={1} codes={codes} userMap={monitoringUserMap} />
|
||||
<WrittenReviewRows performance={performance ?? draft} codes={codes} isWrittenReviewer={isWrittenReviewer} userMap={writtenUserMap} />
|
||||
<div className="flex flex-wrap items-center justify-between gap-2 border-b bg-muted px-3 py-2">
|
||||
<div className="font-semibold">평가 및 모니터링 현황</div>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Button type="button" size="sm" variant="outline" onClick={() => downloadTemplate(1)}>
|
||||
<Download className="h-4 w-4" />
|
||||
모니터링 양식
|
||||
</Button>
|
||||
<Button type="button" size="sm" variant="outline" onClick={() => downloadTemplate(3)}>
|
||||
<Download className="h-4 w-4" />
|
||||
지자체 양식
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<LocalGovernmentReviewRow performance={performance ?? draft} codes={codes} />
|
||||
<MonitoringStatusRow performance={performance ?? draft} index={0} codes={codes} userMap={monitoringUserMap} canEdit={canEdit} />
|
||||
<MonitoringStatusRow performance={performance ?? draft} index={1} codes={codes} userMap={monitoringUserMap} canEdit={canEdit} />
|
||||
<WrittenReviewRows performance={performance ?? draft} codes={codes} userMap={writtenUserMap} canEdit={canEdit} />
|
||||
</section>
|
||||
</div>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user