Skip to content

Commit 9da6393

Browse files
committed
492: Add success/error alert for file upload
1 parent 4c6c821 commit 9da6393

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

src/client/src/pages/Admin/Admin.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {makeStyles} from "@material-ui/styles";
1313
import UploadBox from './Components/UploadBox';
1414
import AnalysisBox from './Components/AnalysisBox';
1515
import Loading from './Components/Loading';
16+
import useAlert from '../../hooks/useAlert';
1617

1718
const useStyles = makeStyles({});
1819

@@ -23,6 +24,7 @@ export default function Admin(props) {
2324
const [lastExecution, setLastExecution] = React.useState(undefined);
2425
const [lastUploads, setLastUploads] = React.useState(undefined);
2526
const [loadingText, setLoadingText] = React.useState("");
27+
const { setAlert } = useAlert();
2628

2729
React.useEffect(() => {
2830
(async () => {
@@ -69,15 +71,26 @@ export default function Admin(props) {
6971
formData.append('file', element, element.name)
7072
})
7173

72-
await fetch("/api/file", {
73-
method: 'POST',
74-
body: formData,
75-
headers: {
76-
'Authorization': 'Bearer ' + props.access_token
77-
}
78-
})
74+
try {
75+
await fetch("/api/file", {
76+
method: "POST",
77+
body: formData,
78+
headers: {
79+
Authorization: "Bearer " + props.access_token,
80+
},
81+
});
82+
83+
setAlert({
84+
type: "success",
85+
text: `${files.length == 1 ? "1 file" : files.length + " files"} uploaded successfully`,
86+
});
87+
} catch (error) {
88+
console.warn(error);
89+
setAlert({ type: "error", text: error });
90+
} finally {
91+
setIsLoading(false);
92+
}
7993

80-
setIsLoading(false);
8194
setFilesInput(undefined);
8295

8396
await refreshPage();

0 commit comments

Comments
 (0)