260617_01_ENH: 배정 테스트를 위해 개발 중도 커밋

This commit is contained in:
2026-06-17 15:56:38 +09:00
parent fcb2c7a270
commit 28da30b865
61 changed files with 5136 additions and 510 deletions

View File

@@ -0,0 +1,471 @@
"use client";
import {ReactNode, useEffect, useMemo, useState} from "react";
import {Download, ImageIcon, 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";
import {DatePicker} from "@/components/common/DatePicker";
import {FilterSelect} from "@/components/gwcf/FilterSelect";
import {StatusPill} from "@/components/gwcf/StatusPill";
import {Code, PerformanceCompact, PerformanceFull, PerformanceMonitoringSchedule, PerformanceStaff, UserFull} from "@/types/gwcf";
import {CodeGroup} from "@/query/code";
import {getCodeLabel, getDetailValue, ROLE} from "@/lib/gwcf/view";
import {
getMonitoringRecordedAt,
getMonitoringRecordedUser,
getMonitoringSlots,
getMonitoringStatusDisplay,
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 {useUsersQuery} from "@/query/user";
type CodeMap = Partial<Record<CodeGroup, Code[]>>;
function DetailRow({label, children}: {label: string; children: ReactNode}) {
return (
<div className="grid grid-cols-[130px_1fr] border-b last:border-b-0">
<div className="bg-muted px-3 py-2 text-sm font-semibold">{label}</div>
<div className="min-h-9 px-3 py-2 text-sm">{children || "-"}</div>
</div>
);
}
function FileActionButton({
children,
icon = "download",
disabled = false,
onClick,
}: {
children: ReactNode;
icon?: "download" | "upload" | "image";
disabled?: boolean;
onClick?: () => void;
}) {
const Icon = icon === "upload" ? Upload : icon === "image" ? ImageIcon : Download;
return (
<Button type="button" size="xs" variant="outline" disabled={disabled} onClick={onClick}>
<Icon className="h-3 w-3" />
{children}
</Button>
);
}
function AssignedUserInfo({
userId,
user,
codes,
type,
}: {
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"], "-");
const metaValue = type === "monitoring"
? getCodeLabel(codes, "area", getDetailValue(detail, ["area", "userArea", "region"]))
: getCodeLabel(codes, "genre", getDetailValue(detail, ["userGenre", "genre", "reviewGenre"]));
const metaLabel = type === "monitoring" ? "지역" : "장르";
const hasCar = getCodeLabel(codes, "has_car", getDetailValue(detail, ["userHasCar", "has_car", "hasCar"])) || "-";
return (
<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-2">
<span>ID: {userId || "-"}</span>
<span>{metaLabel}: {metaValue || "-"}</span>
<span>연락처: {tel}</span>
<span>이메일: {email}</span>
{type === "monitoring" && <span>자차유무: {hasCar}</span>}
</div>
</div>
);
}
const downloadBlob = (buffer: ArrayBuffer, fileName: string, type = "application/octet-stream") => {
const blob = new Blob([buffer], {type});
downloadFile(blob, fileName);
};
function ReviewFileActions({
performanceId,
reviewType,
uploadFileName,
pdfFileName,
}: {
performanceId: number;
reviewType: number;
uploadFileName?: string;
pdfFileName?: string;
}) {
const uploadMutation = useUploadReviewFileMutation();
const originalMutation = useDownloadReviewOriginalMutation();
const pdfMutation = useDownloadReviewPdfMutation();
const upload = (file?: File) => {
if (!file) return;
uploadMutation.mutate({performanceId, reviewType, file});
};
const downloadOriginal = async () => {
const buffer = await originalMutation.mutateAsync({performanceId, reviewType});
downloadBlob(buffer, uploadFileName || `review-original-${performanceId}-${reviewType}`);
};
const downloadPdf = async () => {
const buffer = await pdfMutation.mutateAsync({performanceId, reviewType});
downloadBlob(buffer, pdfFileName || `review-pdf-${performanceId}-${reviewType}.pdf`, "application/pdf");
};
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>
</div>
);
}
function EvidenceZipButton({performanceId, userId}: {performanceId: number; userId: string}) {
const zipMutation = useDownloadEvidenceZipMutation();
const download = async () => {
const buffer = await zipMutation.mutateAsync({performanceId, userId});
downloadBlob(buffer, `monitoring-evidence-${performanceId}-${userId}.zip`, "application/zip");
};
return <FileActionButton icon="image" disabled={zipMutation.isPending} onClick={download}>증빙사진</FileActionButton>;
}
function LocalGovernmentReviewRow({performanceId, codes}: {performanceId: number; codes: CodeMap}) {
const reviewType = LOCAL_GOVERNMENT_REVIEW_TYPE;
const {data: review} = useReviewFileQuery(performanceId, reviewType, performanceId > 0);
const label = getCodeLabel(codes, "review_status", review?.reviewStatus);
const display = getReviewStatusDisplay(label, review, true);
return (
<div className="space-y-2 border-b p-3">
<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} />
</div>
</div>
);
}
function MonitoringStatusRow({
performance,
index,
codes,
userMap,
}: {
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);
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">
<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>
)}
</div>
</div>
</div>
);
}
function WrittenReviewRows({
performance,
codes,
isWrittenReviewer,
userMap,
}: {
performance: PerformanceFull | PerformanceCompact;
codes: CodeMap;
isWrittenReviewer: boolean;
userMap: Map<string, UserFull>;
}) {
const startMutation = useStartWrittenReviewMutation();
const endMutation = useEndWrittenReviewMutation();
const rows = getWrittenReviewRows(performance as PerformanceFull);
if(rows.length === 0){
rows.push({userId: "", assign: undefined, review: undefined});
}
const openWrittenReviewLink = (userId: string, complete: boolean) => {
window.open(buildWrittenReviewLink({performanceId: performance.id, userId, complete}), "_blank", "noopener,noreferrer");
};
return (
<div className="space-y-2 border-b p-3">
<div className="font-semibold">서면평가</div>
<div className="grid gap-1 text-sm">
{rows.map(({userId, assign, review}) => {
const user = userMap.get(userId);
const complete = isReviewComplete(review);
const reviewType = review?.reviewType ?? assign?.assignType ?? 2;
const label = getCodeLabel(codes, "review_status", review?.reviewStatus);
const display = getReviewStatusDisplay(label, review, Boolean(assign));
return (
<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}>
{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})}>
평가완료
</Button>
)}
</div>
</div>
);
})}
</div>
</div>
);
}
export function PerformanceDetailDialog({
open,
onOpenChange,
performance,
codes,
canEdit,
isWrittenReviewer = false,
onSave,
}: {
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);
const {data: writtenUsers = []} = useUsersQuery(ROLE.WRITTEN_REVIEWER, open);
const monitoringUserMap = useMemo(
() => new Map(monitoringUsers.map((user) => [user.userId, user])),
[monitoringUsers]
);
const writtenUserMap = useMemo(
() => new Map(writtenUsers.map((user) => [user.userId, user])),
[writtenUsers]
);
useEffect(() => {
if (!performance) {
setDraft(null);
setIsEditing(false);
return;
}
setDraft({
id: performance.id,
businessType: performance.businessType,
performanceGenre: performance.performanceGenre,
performanceArea: performance.performanceArea,
artistName: performance.artistName,
performanceName: performance.performanceName,
performanceStartMonth: performance.performanceStartMonth,
performanceDtInfo: performance.performanceDtInfo,
performanceTimeInfo: performance.performanceTimeInfo,
ticketReservationStatus: performance.ticketReservationStatus,
ticketReservationMemo: performance.ticketReservationMemo,
performanceMemo: performance.performanceMemo,
performanceDetail: performance.performanceDetail,
performanceStaff: performance.performanceStaff,
performanceMonitoringSchedule: performance.performanceMonitoringSchedule,
});
setIsEditing(false);
}, [performance]);
const updateDraft = <K extends keyof PerformanceCompact>(key: K, value: PerformanceCompact[K]) => {
setDraft((prev) => prev ? {...prev, [key]: value} : prev);
};
const updateSchedule = <K extends keyof PerformanceMonitoringSchedule>(key: K, value: PerformanceMonitoringSchedule[K]) => {
setDraft((prev) => prev ? {
...prev,
performanceMonitoringSchedule: {
...prev.performanceMonitoringSchedule,
[key]: value,
},
} : prev);
};
const updateStaff = (index: number, key: keyof PerformanceStaff, value: string | number) => {
setDraft((prev) => {
if (!prev) return prev;
const next = [...(prev.performanceStaff ?? [])];
next[index] = {...next[index], [key]: value};
return {...prev, performanceStaff: next};
});
};
const resetDraft = () => {
if (!performance) return;
setDraft({
id: performance.id,
businessType: performance.businessType,
performanceGenre: performance.performanceGenre,
performanceArea: performance.performanceArea,
artistName: performance.artistName,
performanceName: performance.performanceName,
performanceStartMonth: performance.performanceStartMonth,
performanceDtInfo: performance.performanceDtInfo,
performanceTimeInfo: performance.performanceTimeInfo,
ticketReservationStatus: performance.ticketReservationStatus,
ticketReservationMemo: performance.ticketReservationMemo,
performanceMemo: performance.performanceMemo,
performanceDetail: performance.performanceDetail,
performanceStaff: performance.performanceStaff,
performanceMonitoringSchedule: performance.performanceMonitoringSchedule,
});
};
const save = () => {
if (!draft) return;
onSave?.(draft);
setIsEditing(false);
};
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="flex max-h-[90vh] flex-col overflow-hidden sm:max-w-6xl">
<DialogHeader>
<DialogTitle>사업 상세 정보</DialogTitle>
</DialogHeader>
<div className="min-h-0 flex-1 overflow-y-auto pr-1">
{draft && (
<div className="grid gap-4 lg:grid-cols-[1.1fr_0.9fr]">
<div className="space-y-4">
<section className="rounded-md border">
<DetailRow label="연번">{draft.id}</DetailRow>
<DetailRow label="사업유형">{getCodeLabel(codes, "business_type", draft.businessType)}</DetailRow>
<DetailRow label="분야(장르)">{getCodeLabel(codes, "genre", draft.performanceGenre)}</DetailRow>
<DetailRow label="지역">{getCodeLabel(codes, "area", draft.performanceArea)}</DetailRow>
<DetailRow label="단체(인)명">{draft.artistName}</DetailRow>
<DetailRow label="사업명">{isEditing ? <Input value={draft.performanceName} onChange={(event) => updateDraft("performanceName", event.target.value)} /> : draft.performanceName}</DetailRow>
<DetailRow label="사업 수행 월">{isEditing ? <Input type="number" value={draft.performanceStartMonth} onChange={(event) => updateDraft("performanceStartMonth", Number(event.target.value))} /> : `${draft.performanceStartMonth}월`}</DetailRow>
<DetailRow label="사업 일정">{isEditing ? <Input value={draft.performanceDtInfo} onChange={(event) => updateDraft("performanceDtInfo", event.target.value)} /> : draft.performanceDtInfo}</DetailRow>
<DetailRow label="운영 시간">{isEditing ? <Input value={draft.performanceTimeInfo} onChange={(event) => updateDraft("performanceTimeInfo", event.target.value)} /> : draft.performanceTimeInfo}</DetailRow>
<DetailRow label="예매 예약">
{isEditing ? (
<FilterSelect value={String(draft.ticketReservationStatus ?? "")} onChange={(value) => updateDraft("ticketReservationStatus", Number(value))} options={codes.ticket_reservation_status ?? []} placeholder="예매 예약" />
) : getCodeLabel(codes, "ticket_reservation_status", draft.ticketReservationStatus)}
</DetailRow>
<DetailRow label="예매 비고">{isEditing ? <Input value={draft.ticketReservationMemo} onChange={(event) => updateDraft("ticketReservationMemo", event.target.value)} /> : draft.ticketReservationMemo}</DetailRow>
<DetailRow label="모니터링 일정">{isEditing ? <DatePicker value={draft.performanceMonitoringSchedule?.monitoringDate ?? ""} onChange={(value) => updateSchedule("monitoringDate", value)} /> : draft.performanceMonitoringSchedule?.monitoringDate}</DetailRow>
<DetailRow label="모니터링 시간">{isEditing ? <Input value={draft.performanceMonitoringSchedule?.monitoringTimeInfo ?? ""} onChange={(event) => updateSchedule("monitoringTimeInfo", event.target.value)} /> : draft.performanceMonitoringSchedule?.monitoringTimeInfo}</DetailRow>
<DetailRow label="방문 장소">{isEditing ? <Input value={draft.performanceMonitoringSchedule?.monitoringAddress ?? ""} onChange={(event) => updateSchedule("monitoringAddress", event.target.value)} /> : draft.performanceMonitoringSchedule?.monitoringAddress}</DetailRow>
<DetailRow label="메모">{isEditing ? <Input value={draft.performanceMemo} onChange={(event) => updateDraft("performanceMemo", event.target.value)} /> : draft.performanceMemo}</DetailRow>
</section>
<section className="rounded-md border">
<div className="border-b bg-muted px-3 py-2 font-semibold">관계자 정보</div>
<div className="overflow-auto">
<table className="w-full min-w-[620px] border-collapse text-sm">
<thead>
<tr className="bg-muted">
<th className="border p-2">유형</th>
<th className="border p-2">이름</th>
<th className="border p-2">연락처1</th>
<th className="border p-2">연락처2</th>
<th className="border p-2">이메일</th>
</tr>
</thead>
<tbody>
{draft.performanceStaff?.map((staff, index) => (
<tr key={staff.id}>
<td className="border p-2">{getCodeLabel(codes, "staff_type", staff.staffType)}</td>
<td className="border p-2">{isEditing ? <Input value={staff.staffName} onChange={(event) => updateStaff(index, "staffName", event.target.value)} /> : staff.staffName}</td>
<td className="border p-2">{isEditing ? <Input value={staff.staffTel1} onChange={(event) => updateStaff(index, "staffTel1", event.target.value)} /> : staff.staffTel1}</td>
<td className="border p-2">{isEditing ? <Input value={staff.staffTel2} onChange={(event) => updateStaff(index, "staffTel2", event.target.value)} /> : staff.staffTel2}</td>
<td className="border p-2">{isEditing ? <Input value={staff.staffEmail} onChange={(event) => updateStaff(index, "staffEmail", event.target.value)} /> : staff.staffEmail}</td>
</tr>
))}
</tbody>
</table>
</div>
</section>
</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} />
</section>
</div>
)}
</div>
<DialogFooter className="shrink-0 border-t pt-4">
{canEdit && draft && !isEditing && <Button type="button" onClick={() => setIsEditing(true)}>수정</Button>}
{canEdit && draft && isEditing && (
<>
<Button type="button" onClick={save}>저장</Button>
<Button type="button" variant="outline" onClick={() => { resetDraft(); setIsEditing(false); }}>취소</Button>
</>
)}
<Button type="button" variant="outline" onClick={() => onOpenChange(false)}>닫기</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}