260623_01_ENH: 엑셀 다운로드를 제외한 기능 완성
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import {useEffect, useMemo, useState} from "react";
|
||||
import {Send} from "lucide-react";
|
||||
import {Save, Send} from "lucide-react";
|
||||
import {Button} from "@/components/ui/button";
|
||||
import {Checkbox} from "@/components/ui/checkbox";
|
||||
import {Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle} from "@/components/ui/dialog";
|
||||
@@ -32,7 +32,7 @@ export function AssignMonitoringDialog({
|
||||
applyUsers: MonitoringApplyUser[];
|
||||
isSavingAssign?: boolean;
|
||||
onSaveAssign: (performanceId: number, userIds: string[]) => void;
|
||||
onOpenSms: (userIds: string[]) => void;
|
||||
onOpenSms: (assignUserIds: string[], smsUserIds: string[]) => void;
|
||||
}>) {
|
||||
const monitoringAssigns = useMemo(
|
||||
() => (selected?.performanceAssignList ?? []).filter((item) => item.assignType === MONITORING_ASSIGN_TYPE),
|
||||
@@ -68,7 +68,6 @@ export function AssignMonitoringDialog({
|
||||
|
||||
const next = Array.from(new Set([...checkedIds, applyUser.userId]));
|
||||
setCheckedIds(next);
|
||||
onSaveAssign(selected.id, next);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -80,7 +79,6 @@ export function AssignMonitoringDialog({
|
||||
|
||||
const next = checkedIds.filter((userId) => userId !== applyUser.userId);
|
||||
setCheckedIds(next);
|
||||
onSaveAssign(selected.id, next);
|
||||
};
|
||||
|
||||
const toggleApplyUser = (applyUser: MonitoringApplyUser) => {
|
||||
@@ -206,7 +204,11 @@ export function AssignMonitoringDialog({
|
||||
</div>
|
||||
|
||||
<DialogFooter>
|
||||
<Button type="button" variant="outline" disabled={smsTargetIds.length === 0} onClick={() => onOpenSms(smsTargetIds)}>
|
||||
<Button type="button" variant="outline" disabled={!selected || isSavingAssign} onClick={() => selected && onSaveAssign(selected.id, checkedIds)}>
|
||||
<Save className="h-4 w-4" />
|
||||
저장
|
||||
</Button>
|
||||
<Button type="button" variant="outline" disabled={smsTargetIds.length === 0 || isSavingAssign} onClick={() => onOpenSms(checkedIds, smsTargetIds)}>
|
||||
<Send className="h-4 w-4" />
|
||||
확정 문자 발송
|
||||
</Button>
|
||||
|
||||
268
src/components/dialog/MonitoringPerformanceDetailDialog.tsx
Normal file
268
src/components/dialog/MonitoringPerformanceDetailDialog.tsx
Normal 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>
|
||||
);
|
||||
}
|
||||
@@ -27,14 +27,14 @@ export function MonitoringVisitDialog({
|
||||
mode,
|
||||
onSubmit,
|
||||
isSubmitting,
|
||||
}: {
|
||||
}: Readonly<{
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
performance: PerformanceCompact | null;
|
||||
mode: "departure" | "arrival";
|
||||
onSubmit?: (files?: File[]) => void | Promise<void>;
|
||||
isSubmitting?: boolean;
|
||||
}) {
|
||||
}>) {
|
||||
const nowText = useMemo(() => new Date().toLocaleString("ko-KR"), [open]);
|
||||
const [files, setFiles] = useState<File[]>([]);
|
||||
|
||||
|
||||
@@ -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>
|
||||
)}
|
||||
|
||||
@@ -21,6 +21,7 @@ import {SaveTemplateRequest, Template} from "@/types/notification";
|
||||
import {UserCompact} from "@/types/gwcf";
|
||||
import {getDetailValue} from "@/lib/gwcf/view";
|
||||
import {useAuth} from "@/hooks/useAuth";
|
||||
import {buildUserMsgParam} from "@/lib/gwcf/notification";
|
||||
|
||||
type TemplateDraft = Pick<Template, "tmplatIdx" | "tmplatNm" | "tmplatTitle" | "tmplatBody" | "sendTel">;
|
||||
|
||||
@@ -34,19 +35,6 @@ const toDraft = (template: Template, emptyBody = false): TemplateDraft => ({
|
||||
sendTel: toText(template.sendTel),
|
||||
});
|
||||
|
||||
const toParamValue = (value: unknown) => value == null ? "" : String(value);
|
||||
|
||||
const buildUserMsgParam = (user: UserCompact): Record<string, string> => ({
|
||||
...Object.fromEntries(
|
||||
Object.entries(user.userDetail ?? {}).map(([key, value]) => [key, toParamValue(value)])
|
||||
),
|
||||
userId: toParamValue(user.userId),
|
||||
userCmpn: toParamValue(user.userCmpn),
|
||||
userTeam: toParamValue(user.userTeam),
|
||||
userName: toParamValue(user.userName),
|
||||
userRole: toParamValue(user.userRole),
|
||||
});
|
||||
|
||||
export function SmsSendDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
@@ -55,6 +43,8 @@ export function SmsSendDialog({
|
||||
newMessageTemplateIdx,
|
||||
selectedUsers,
|
||||
addParams = {},
|
||||
onBeforeDefaultTemplateSend,
|
||||
isBeforeSendPending = false,
|
||||
onSent,
|
||||
}: Readonly<{
|
||||
open: boolean;
|
||||
@@ -64,6 +54,8 @@ export function SmsSendDialog({
|
||||
newMessageTemplateIdx?: number;
|
||||
selectedUsers: UserCompact[];
|
||||
addParams?: Record<string, string>;
|
||||
onBeforeDefaultTemplateSend?: () => Promise<void>;
|
||||
isBeforeSendPending?: boolean;
|
||||
onSent?: () => void;
|
||||
}>) {
|
||||
const {auth} = useAuth();
|
||||
@@ -76,7 +68,7 @@ export function SmsSendDialog({
|
||||
const saveTemplateMutation = useSaveNotificationTemplateMutation();
|
||||
const sendSmsMutation = useSendSmsBulkMutation();
|
||||
|
||||
const isBusy = templateQuery.isLoading || saveTemplateMutation.isPending || sendSmsMutation.isPending;
|
||||
const isBusy = templateQuery.isLoading || saveTemplateMutation.isPending || sendSmsMutation.isPending || isBeforeSendPending;
|
||||
const canEdit = isNewMessage || isEditing;
|
||||
|
||||
const destinations = useMemo(() => {
|
||||
@@ -170,6 +162,8 @@ export function SmsSendDialog({
|
||||
|
||||
if (isNewMessage) {
|
||||
await saveTemplate();
|
||||
} else {
|
||||
await onBeforeDefaultTemplateSend?.();
|
||||
}
|
||||
|
||||
const result = await sendSmsMutation.mutateAsync({
|
||||
|
||||
Reference in New Issue
Block a user