@@ -32,6 +32,8 @@ export default function Upload() {
32
32
const state = store . getState ( ) ;
33
33
const [ files , setFiles ] = React . useState < File [ ] > ( [ ] ) ;
34
34
const [ alertOpen , setAlertOpen ] = React . useState < boolean > ( false ) ;
35
+ const [ alertSev , setAlertSev ] = React . useState ( 'success' ) ;
36
+ const [ alertMsg , setAlertMsg ] = React . useState ( 'Uploaded Image!' ) ;
35
37
36
38
const handleFileUpload = async ( ) => {
37
39
const file = files [ 0 ] ;
@@ -46,7 +48,16 @@ export default function Upload() {
46
48
body
47
49
} ) ;
48
50
49
- if ( res . ok ) setAlertOpen ( true ) ;
51
+ if ( res . ok ) {
52
+ setAlertOpen ( true ) ;
53
+ setAlertMsg ( 'Uploaded Image!' ) ;
54
+ setAlertSev ( 'success' ) ;
55
+ } else {
56
+ const d = await res . json ( ) ;
57
+ setAlertOpen ( true ) ;
58
+ setAlertMsg ( `Couldn't upload: ${ d . error } ` ) ;
59
+ setAlertSev ( 'error' ) ;
60
+ }
50
61
} ;
51
62
52
63
if ( typeof window === 'undefined' ) return < UIPlaceholder /> ;
@@ -63,8 +74,10 @@ export default function Upload() {
63
74
autoHideDuration = { 6000 }
64
75
onClose = { ( ) => setAlertOpen ( false ) }
65
76
>
66
- < Alert severity = 'success' variant = 'filled' >
67
- Uploaded image!
77
+ { /* eslint-disable-next-line @typescript-eslint/ban-ts-comment */ }
78
+ { /* @ts -ignore */ }
79
+ < Alert severity = { alertSev } variant = 'filled' >
80
+ { alertMsg }
68
81
</ Alert >
69
82
</ Snackbar >
70
83
< Paper elevation = { 3 } className = { classes . padding } >
@@ -76,10 +89,11 @@ export default function Upload() {
76
89
acceptedFiles = { [ 'image/*' ] }
77
90
dropzoneText = { 'Drag an image or click to upload an image.' }
78
91
onChange = { f => setFiles ( f ) }
92
+ filesLimit = { 1 }
79
93
maxFileSize = { 1073741824 } // 1gb in byte
80
94
/>
81
95
</ Box >
82
- < Button onClick = { handleFileUpload } > Submit </ Button >
96
+ < Button onClick = { handleFileUpload } > Upload </ Button >
83
97
</ Paper >
84
98
</ UI >
85
99
) ;
0 commit comments