260928_01_ENH: 신청서 파일 업로드/다운로드 추가

This commit is contained in:
2026-09-28 15:40:08 +09:00
parent 17c34d76b9
commit 2647b88daf
5 changed files with 168 additions and 2 deletions

View File

@@ -15,15 +15,18 @@ import type {
PerformanceReview,
PerformanceReviewSlot,
PerformanceStaff,
RequestFormType,
} from "@/types/kmusical";
import {PDF_CONVERT_STATUS} from "@/types/kmusical";
import {PDF_CONVERT_STATUS, REQUEST_FORM_DETAIL_KEY, REQUEST_FORM_LABEL, REQUEST_FORM_TYPE} from "@/types/kmusical";
import type {CodeGroup} from "@/query/code";
import {HttpError} from "@kri/common/http";
import {
useDownloadReviewOriginalMutation,
useDownloadReviewPdfMutation,
useDownloadReviewTemplateMutation,
useUploadReviewFileMutation,
} from "@/query/review";
import {useDownloadRequestFormMutation, useUploadRequestFormMutation} from "@/query/performance";
import {useUserQuery} from "@/query/user";
import {downloadBlob, downloadFromUrl} from "@/lib/kmusical/file";
import {toLocalDateString} from "@/lib/kmusical/date";
@@ -147,6 +150,70 @@ function ReviewSlotCard({
);
}
function RequestFormRow({
performanceId,
formType,
fileName,
canEdit,
onUploaded,
}: Readonly<{
performanceId: string;
formType: RequestFormType;
fileName?: string;
canEdit: boolean;
onUploaded?: (formType: RequestFormType, savedFileName: string) => void;
}>) {
const fileInputRef = useRef<HTMLInputElement | null>(null);
const uploadMutation = useUploadRequestFormMutation();
const downloadMutation = useDownloadRequestFormMutation();
const upload = async (file?: File) => {
try {
if (!file) return;
const formData = new FormData();
formData.append("file", file, file.name);
const savedFileName = await uploadMutation.mutateAsync({performanceId, formType, formData});
alert(`${REQUEST_FORM_LABEL[formType]} 파일이 등록되었습니다.`);
onUploaded?.(formType, savedFileName);
} finally {
if (fileInputRef.current) fileInputRef.current.value = "";
}
};
const download = async () => {
try {
await downloadMutation.mutateAsync({performanceId, formType});
} catch (error) {
if (error instanceof HttpError && error.status === 404) {
alert("등록된 파일이 없습니다.");
return;
}
throw error;
}
};
return (
<DetailRow label={REQUEST_FORM_LABEL[formType]}>
<div className="flex flex-wrap items-center gap-2">
<span className="min-w-0 flex-1 break-all">{fileName || "등록된 파일 없음"}</span>
<div className="flex flex-wrap gap-1">
{canEdit && (
<>
<input ref={fileInputRef} type="file" className="hidden" onChange={(event) => void upload(event.target.files?.[0])} />
<Button type="button" size="xs" variant="outline" className="rounded-full" onClick={() => fileInputRef.current?.click()} disabled={uploadMutation.isPending}>
<Upload className="size-3" /> {fileName ? "교체" : "등록"}
</Button>
</>
)}
<Button type="button" size="xs" variant="outline" className="rounded-full" onClick={download} disabled={!fileName || downloadMutation.isPending}>
<Download className="size-3" /> 다운로드
</Button>
</div>
</div>
</DetailRow>
);
}
const clonePerformance = (performance: PerformanceCompact): PerformanceCompact => ({
...performance,
performanceDetail: {...performance.performanceDetail},
@@ -279,6 +346,23 @@ export function PerformanceDetailDialog({
<DetailRow label={PERFORMANCE_FIELD_LABELS.clientManagerName}>{isEditing ? <Input value={draft.performanceDetail.clientManagerName ?? ""} onChange={(event) => updateDetail("clientManagerName", event.target.value)} /> : draft.performanceDetail.clientManagerName}</DetailRow>
</section>
<section className="rounded-md border">
<div className="border-b bg-muted px-3 py-2 font-semibold">신청서 파일</div>
{[REQUEST_FORM_TYPE.PUBLIC_OFFERING, REQUEST_FORM_TYPE.ISSUANCE].map((formType) => (
<RequestFormRow
key={formType}
performanceId={draft.performanceId}
formType={formType}
fileName={draft.performanceDetail[REQUEST_FORM_DETAIL_KEY[formType]] || undefined}
canEdit={canEdit}
onUploaded={(uploadedType, savedFileName) => {
updateDetail(REQUEST_FORM_DETAIL_KEY[uploadedType], savedFileName);
onRefresh?.();
}}
/>
))}
</section>
<section className="rounded-md border">
<div className="border-b bg-muted px-3 py-2 font-semibold">관계자 정보</div>
<div className="overflow-auto">