"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, PDF_CONVERT_STATUS, PdfConvertStatus, 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, buildReviewTemplatePdfPreviewUrl, downloadBlob, downloadFromUrl, getEvidenceZipDownloadName, getReviewOriginalDownloadName, getReviewPdfDisabled, getReviewPdfDownloadName, getReviewPdfStatusLabel, openPreviewWindow, } from "@/lib/gwcf/file"; import {PERFORMANCE_FIELD_LABELS} from "@/lib/gwcf/field-labels"; type CodeMap = Partial>; function MobileDetailRow({label, children}: {label: string; children: ReactNode}) { return (
{label}
{children ?? "-"}
); } function ActionButton({ children, className, icon = "download", disabled = false, onClick, }: Readonly<{ children: ReactNode; className?: string; icon?: "download" | "upload" | "image" | "preview"; disabled?: boolean; onClick?: () => void; }>) { const Icon = icon === "upload" ? Upload : icon === "image" ? ImageIcon : icon === "preview" ? ScanSearch : Download; return ( ); } function MonitoringReviewActions({ canUpload, performanceId, reviewType, userId, uploadFileName, pdfConvert, pdfFileName, }: Readonly<{ canUpload: boolean; performanceId: number; reviewType: number; userId?: string; uploadFileName?: string; pdfConvert?: PdfConvertStatus; pdfFileName?: string; }>) { const fileInputRef = useRef(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 (
void upload(event.target.files?.[0])} /> fileInputRef.current?.click()}>파일 업로드 원본 {getReviewPdfStatusLabel(pdfConvert)} 미리보기
* 파일 크기 및 형식에 따라 PDF 변환이 최대 5분까지 소요됩니다.
); } 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 (
증빙사진 증빙 미리보기
); } 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 reviewType = row?.reviewType ?? 1; const templateClassification = Number(String(performance?.id ?? 0).charAt(0)); const buildTemplateDownloadUrl = (classification: number) => `/api/review/template/download/${reviewType}/${classification}`; const downloadTemplate = () => downloadFromUrl(buildTemplateDownloadUrl(templateClassification)); const previewTemplateFile = async (classification: number, title: string) => { const previewWindow = window.open("about:blank", "_blank"); if (previewWindow) previewWindow.opener = null; const previewUrl = buildReviewTemplatePdfPreviewUrl(reviewType, classification, title); if (previewWindow) { previewWindow.location.href = previewUrl; return; } openPreviewWindow(previewUrl); }; const previewTemplate = () => void previewTemplateFile(templateClassification, "모니터링 현장 점검표.pdf"); const previewEduFile = () => void previewTemplateFile(99, "도민 모니터링단 매뉴얼.pdf"); return ( 모니터링 상세
{performance ? ( <>
{performance.id} {getCodeLabel(codes, "business_type", performance.businessType)} {getCodeLabel(codes, "genre", performance.performanceGenre)} {getCodeLabel(codes, "area", performance.performanceArea)} {performance.artistName} {performance.performanceName} {performance.performanceStartMonth}월 {performance.performanceDtInfo} {performance.performanceTimeInfo} {getCodeLabel(codes, "ticket_reservation_status", performance.ticketReservationStatus)} {performance.ticketReservationMemo} {performance.performanceMonitoringSchedule?.monitoringDate ?? ""} {performance.performanceMonitoringSchedule?.monitoringTimeInfo} {performance.performanceMonitoringSchedule?.monitoringAddress} {/*{performance.performanceMemo}*/}
나의 진행 상태
{status.label}
교육자료 양식 양식 다운로드
{row ? ( ) : (
나의 모니터링 배정 정보를 찾을 수 없습니다.
)}
{row?.slot.visit?.length ? (
모니터링 방문 기록
출발: {getMonitoringRecordedAt(row.slot.timeline.departure)}
도착: {getMonitoringRecordedAt(row.slot.timeline.arrival)}
{row.slot.timeline.arrival && ( )}
) : null} ) : (
공연 정보를 불러오는 중입니다.
)}
); }