From 87fbf15e2b44db1c97adb56938dd69c78354a0c5 Mon Sep 17 00:00:00 2001 From: bicochan Date: Tue, 22 Sep 2026 10:23:10 +0900 Subject: [PATCH] =?UTF-8?q?[as]=20feat:=20=EC=9E=AC=EC=9B=90=ED=98=91?= =?UTF-8?q?=EC=9D=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pages/fnrs-cnsltn/lib/button-config.ts | 1 - .../pages/fnrs-cnsltn/ui/fnrs-form-page.tsx | 5 + .../pbadms-sprt/ui/fnrs-shar-form-section.tsx | 98 ++++++++++++------- 3 files changed, 67 insertions(+), 37 deletions(-) diff --git a/apps/as/src/pages/fnrs-cnsltn/lib/button-config.ts b/apps/as/src/pages/fnrs-cnsltn/lib/button-config.ts index 3b0aca199..2c52dfa9d 100644 --- a/apps/as/src/pages/fnrs-cnsltn/lib/button-config.ts +++ b/apps/as/src/pages/fnrs-cnsltn/lib/button-config.ts @@ -51,7 +51,6 @@ const ROLE_STATUS_BUTTON_ACTIONS: Record(); const fnrsSharList = useWatch({ control, name: "fnrsSharList" }) ?? []; - const [uploadedFileName, setUploadedFileName] = useState( - () => initialSharAtchFiles?.[0]?.orgnlFileNm ?? "", + const [uploadedFile, setUploadedFile] = useState(() => + toInitialSharFile(initialSharAtchFiles?.[0]), ); + const { mutate: downloadByAtflId } = useDownloadAttachmentByAtflId(); const { data: masterTree = [], isLoading: isMasterLoading } = useFnrsSharSeMngTree(); const { data: acntgTree = [] } = useAcntgSeMngTree(); @@ -78,9 +95,13 @@ function FnrsSharFormSection({ initialSharTree, initialSharAtchFiles }: FnrsShar const isLoading = initialSharTree?.length ? false : isMasterLoading; const { uploadFileAsync, isUploading } = useTus({ - onSuccess: (atflCd) => { + onSuccess: (atflCd, atflId, _file, fileKey) => { if (!atflCd) return; setValue("fnrsCnsltnMng.sharAtchFileGroupId", atflCd, { shouldDirty: true }); + setUploadedFile((prev) => (prev?.fileKey === fileKey ? { ...prev, atflId } : prev)); + }, + onError: (_error, _file, fileKey) => { + setUploadedFile((prev) => (prev?.fileKey === fileKey ? null : prev)); }, }); const isSharUploading = Object.values(isUploading).some(Boolean); @@ -120,16 +141,32 @@ function FnrsSharFormSection({ initialSharTree, initialSharAtchFiles }: FnrsShar applySharList(draft); } - async function handleSharFileChange(event: React.ChangeEvent) { - const file = event.target.files?.[0]; + async function handleSharFileAdd(files: FileList | null) { + const file = files?.[0]; if (!file) return; const fileKey = createSharUploadKey(file); - setUploadedFileName(file.name); - await uploadFileAsync(file, { fileKey }); - event.target.value = ""; + setUploadedFile({ fileName: file.name, fileKey }); + + try { + await uploadFileAsync(file, { fileKey }); + } catch { + // onError callback handles cleanup + } } + const sharAtchFiles = uploadedFile + ? [ + { + fileKey: uploadedFile.fileKey, + fileName: uploadedFile.fileName, + onDownload: uploadedFile.atflId + ? () => downloadByAtflId(uploadedFile.atflId!) + : undefined, + }, + ] + : []; + if (isLoading) { return ( @@ -257,31 +294,20 @@ function FnrsSharFormSection({ initialSharTree, initialSharAtchFiles }: FnrsShar

첨부파일

-
- {isSharUploading && uploadedFileName ? ( - - {uploadedFileName} - - ) : ( - - )} - -
+ {!uploadedFile ? ( +

+ 총사업비 신청서(.hwp) 파일을 등록해주세요. +

+ ) : null} + void handleSharFileAdd(fileList)} + />
);