@@ -13,6 +13,7 @@ import {makeStyles} from "@material-ui/styles";
13
13
import UploadBox from './Components/UploadBox' ;
14
14
import AnalysisBox from './Components/AnalysisBox' ;
15
15
import Loading from './Components/Loading' ;
16
+ import useAlert from '../../hooks/useAlert' ;
16
17
17
18
const useStyles = makeStyles ( { } ) ;
18
19
@@ -23,6 +24,7 @@ export default function Admin(props) {
23
24
const [ lastExecution , setLastExecution ] = React . useState ( undefined ) ;
24
25
const [ lastUploads , setLastUploads ] = React . useState ( undefined ) ;
25
26
const [ loadingText , setLoadingText ] = React . useState ( "" ) ;
27
+ const { setAlert } = useAlert ( ) ;
26
28
27
29
React . useEffect ( ( ) => {
28
30
( async ( ) => {
@@ -69,15 +71,26 @@ export default function Admin(props) {
69
71
formData . append ( 'file' , element , element . name )
70
72
} )
71
73
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
+ }
79
93
80
- setIsLoading ( false ) ;
81
94
setFilesInput ( undefined ) ;
82
95
83
96
await refreshPage ( ) ;
0 commit comments