fix(striker-ui): prepare handle error in add file form

main
Tsu-ba-me 1 year ago
parent a32bbb838e
commit 45ea421724
  1. 24
      striker-ui/components/Files/AddFileForm.tsx

@ -60,14 +60,15 @@ const AddFileForm: FC<AddFileFormProps> = (props) => {
}, {}), }, {}),
); );
files.forEach(({ file, name, uuid }) => { const promises = files.reduce<Promise<void>[]>(
if (!file) return; (chain, { file, name, uuid }) => {
if (!file) return chain;
const data = new FormData(); const data = new FormData();
data.append('file', new File([file], name, { ...file })); data.append('file', new File([file], name, { ...file }));
api const promise = api
.post('/file', data, { .post('/file', data, {
headers: { headers: {
'Content-Type': 'multipart/form-data', 'Content-Type': 'multipart/form-data',
@ -93,10 +94,19 @@ const AddFileForm: FC<AddFileFormProps> = (props) => {
setUploadProgress(previous, fileUuid, 100), setUploadProgress(previous, fileUuid, 100),
); );
})(uuid), })(uuid),
) );
.catch((error) => {
handleAPIError(error); chain.push(promise);
});
return chain;
},
[],
);
Promise.all(promises).catch((error) => {
const emsg = handleAPIError(error);
emsg.children = <>Failed to add file. {emsg.children}</>;
}); });
}, },
validationSchema: fileListSchema, validationSchema: fileListSchema,

Loading…
Cancel
Save