260623_01_ENH: 엑셀 다운로드를 제외한 기능 완성

This commit is contained in:
2026-06-23 09:54:25 +09:00
parent 28da30b865
commit 08ea4d5420
23 changed files with 1202 additions and 349 deletions

View File

@@ -0,0 +1,268 @@
"use client";
import {ReactNode, useMemo, useRef} from "react";
import {Download, ImageIcon, ScanSearch, Upload} from "lucide-react";
import {Button} from "@/components/ui/button";
import {Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle} from "@/components/ui/dialog";
import {StatusPill} from "@/components/gwcf/StatusPill";
import {Code, PerformanceFull} from "@/types/gwcf";
import {CodeGroup} from "@/query/code";
import {getCodeLabel} from "@/lib/gwcf/view";
import {
getMonitoringDisplayRow,
getMonitoringDisplayStatus,
getMonitoringRecordedAt,
} from "@/lib/gwcf/performance-status";
import {
useDownloadReviewOriginalMutation,
useDownloadReviewPdfMutation,
useUploadReviewFileMutation,
} from "@/query/review";
import {useDownloadEvidenceZipMutation, useMonitoringEvidenceQuery} from "@/query/monitoring";
import {useLoading} from "@/hooks/useLoading";
import {
buildEvidenceImageSrc,
buildImagePreviewUrl,
buildReviewPdfPreviewUrl,
downloadBlob,
downloadFromUrl,
getEvidenceZipDownloadName,
getReviewOriginalDownloadName,
getReviewPdfDownloadName,
openPreviewWindow,
} from "@/lib/gwcf/file";
type CodeMap = Partial<Record<CodeGroup, Code[]>>;
function MobileDetailRow({label, children}: {label: string; children: ReactNode}) {
return (
<div className="space-y-1 border-b px-3 py-2 last:border-b-0">
<div className="text-xs font-semibold text-muted-foreground">{label}</div>
<div className="break-words text-sm">{children || "-"}</div>
</div>
);
}
function ActionButton({
children,
icon = "download",
disabled = false,
onClick,
}: Readonly<{
children: ReactNode;
icon?: "download" | "upload" | "image" | "preview";
disabled?: boolean;
onClick?: () => void;
}>) {
const Icon = icon === "upload" ? Upload : icon === "image" ? ImageIcon : icon === "preview" ? ScanSearch : Download;
return (
<Button type="button" size="sm" variant="outline" disabled={disabled} onClick={onClick} className="min-h-10 flex-1">
<Icon className="h-4 w-4" />
{children}
</Button>
);
}
function MonitoringReviewActions({
performanceId,
reviewType,
userId,
uploadFileName,
pdfFileName,
}: Readonly<{
performanceId: number;
reviewType: number;
userId?: string;
uploadFileName?: string;
pdfFileName?: string;
}>) {
const fileInputRef = useRef<HTMLInputElement>(null);
const uploadMutation = useUploadReviewFileMutation();
const originalMutation = useDownloadReviewOriginalMutation();
const pdfMutation = useDownloadReviewPdfMutation();
const {withLoadingAsync} = useLoading();
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 () => {
if (!userId) return;
const buffer = await originalMutation.mutateAsync({performanceId, reviewType, userId});
downloadBlob(buffer, getReviewOriginalDownloadName(performanceId, reviewType, uploadFileName));
};
const downloadPdf = async () => {
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="grid grid-cols-2 gap-2">
<input ref={fileInputRef} type="file" className="hidden" onChange={(event) => void upload(event.target.files?.[0])} />
<ActionButton icon="upload" disabled={uploadMutation.isPending} onClick={() => fileInputRef.current?.click()}>파일 업로드</ActionButton>
<ActionButton disabled={!userId || !uploadFileName || originalMutation.isPending} onClick={downloadOriginal}>원본</ActionButton>
<ActionButton disabled={!userId || !pdfFileName || pdfMutation.isPending} onClick={downloadPdf}>PDF</ActionButton>
<ActionButton icon="preview" disabled={!userId || !pdfFileName} onClick={previewPdf}>미리보기</ActionButton>
</div>
);
}
function EvidenceActions({performanceId, userId}: {performanceId: number; userId?: string}) {
const enabled = performanceId > 0 && Boolean(userId);
const {data: evidenceList = []} = useMonitoringEvidenceQuery(performanceId, userId ?? "", enabled);
const zipMutation = useDownloadEvidenceZipMutation();
const download = async () => {
if (!userId) return;
const buffer = await zipMutation.mutateAsync({performanceId, userId});
downloadBlob(buffer, getEvidenceZipDownloadName(performanceId, userId), "application/zip");
};
const preview = () => {
if (!userId) return;
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="grid grid-cols-2 gap-2">
<ActionButton icon="image" disabled={!userId || zipMutation.isPending} onClick={download}>증빙사진</ActionButton>
<ActionButton icon="preview" disabled={!userId || evidenceList.length === 0} onClick={preview}>증빙 미리보기</ActionButton>
</div>
);
}
export function MonitoringPerformanceDetailDialog({
open,
onOpenChange,
performance,
codes,
userId,
}: Readonly<{
open: boolean;
onOpenChange: (open: boolean) => void;
performance: PerformanceFull | null;
codes: CodeMap;
userId?: string;
}>) {
const row = useMemo(() => {
if (!performance || !userId) return undefined;
return ([0, 1] as const)
.map((index) => getMonitoringDisplayRow(performance, index))
.find((item) => item.userId === userId);
}, [performance, userId]);
const latestVisit = row?.slot.visit?.[0];
const status = row
? getMonitoringDisplayStatus(
row,
getCodeLabel(codes, "monitoring_visit_status", latestVisit?.monitoringVisitStatus),
getCodeLabel(codes, "review_status", row.review?.reviewStatus)
)
: {label: "미배치", variant: "danger" as const};
const downloadTemplate = () => downloadFromUrl("/api/review/template/download/1");
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="flex max-h-[92vh] w-[calc(100vw-24px)] max-w-[430px] flex-col overflow-hidden p-0">
<DialogHeader className="border-b px-4 py-3">
<DialogTitle className="text-base">모니터링 상세</DialogTitle>
</DialogHeader>
<div className="min-h-0 flex-1 space-y-3 overflow-y-auto p-3">
{performance ? (
<>
<section className="overflow-hidden rounded-md border">
<MobileDetailRow label="연번">{performance.id}</MobileDetailRow>
<MobileDetailRow label="사업유형">{getCodeLabel(codes, "business_type", performance.businessType)}</MobileDetailRow>
<MobileDetailRow label="분야(장르)">{getCodeLabel(codes, "genre", performance.performanceGenre)}</MobileDetailRow>
<MobileDetailRow label="지역">{getCodeLabel(codes, "area", performance.performanceArea)}</MobileDetailRow>
<MobileDetailRow label="단체(인)명">{performance.artistName}</MobileDetailRow>
<MobileDetailRow label="사업명">{performance.performanceName}</MobileDetailRow>
<MobileDetailRow label="사업 수행 월">{performance.performanceStartMonth}월</MobileDetailRow>
<MobileDetailRow label="사업 일정">{performance.performanceDtInfo}</MobileDetailRow>
<MobileDetailRow label="운영 시간">{performance.performanceTimeInfo}</MobileDetailRow>
<MobileDetailRow label="예매 예약">{getCodeLabel(codes, "ticket_reservation_status", performance.ticketReservationStatus)}</MobileDetailRow>
<MobileDetailRow label="예매 비고">{performance.ticketReservationMemo}</MobileDetailRow>
<MobileDetailRow label="모니터링 일정">{performance.performanceMonitoringSchedule?.monitoringDate}</MobileDetailRow>
<MobileDetailRow label="모니터링 시간">{performance.performanceMonitoringSchedule?.monitoringTimeInfo}</MobileDetailRow>
<MobileDetailRow label="방문 장소">{performance.performanceMonitoringSchedule?.monitoringAddress}</MobileDetailRow>
<MobileDetailRow label="메모">{performance.performanceMemo}</MobileDetailRow>
</section>
<section className="space-y-3 rounded-md border p-3">
<div className="flex items-center justify-between gap-2">
<div className="font-semibold">나의 진행 상태</div>
<div className="flex items-center gap-2">
<Button type="button" size="sm" variant="outline" onClick={downloadTemplate}>
<Download className="h-4 w-4" />
양식
</Button>
<StatusPill variant={status.variant}>{status.label}</StatusPill>
</div>
</div>
{row ? (
<MonitoringReviewActions
performanceId={performance.id}
reviewType={row.reviewType}
userId={row.review?.regUser || row.userId}
uploadFileName={row.review?.uploadFileName}
pdfFileName={row.review?.pdfFileName}
/>
) : (
<div className="rounded-md bg-muted p-3 text-sm text-muted-foreground">나의 모니터링 배정 정보를 찾을 수 없습니다.</div>
)}
</section>
{row?.slot.visit?.length ? (
<section className="space-y-3 rounded-md border p-3">
<div className="font-semibold">모니터링 방문 기록</div>
<div className="grid gap-1 text-sm text-muted-foreground">
<div>출발: {getMonitoringRecordedAt(row.slot.timeline.departure)}</div>
<div>도착: {getMonitoringRecordedAt(row.slot.timeline.arrival)}</div>
</div>
{row.slot.timeline.arrival && (
<EvidenceActions performanceId={performance.id} userId={row.evidenceUserId} />
)}
</section>
) : null}
</>
) : (
<div className="rounded-md border p-4 text-sm text-muted-foreground">공연 정보를 불러오는 중입니다.</div>
)}
</div>
<DialogFooter className="border-t px-4 py-3">
<Button type="button" variant="outline" className="w-full" onClick={() => onOpenChange(false)}>닫기</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}