File tree 2 files changed +24
-3
lines changed
2 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -117,7 +117,7 @@ const AddForm = () => {
117
117
const closeModalHandler = ( ) => {
118
118
setPreview ( ! preview ) ;
119
119
}
120
-
120
+
121
121
// reset the form
122
122
const handleReset = ( ) => {
123
123
setName ( '' ) ;
@@ -132,6 +132,23 @@ const AddForm = () => {
132
132
setCheck6 ( false ) ;
133
133
}
134
134
135
+ // profile image upload handler
136
+ const uploadedImage = React . useRef ( null ) ;
137
+ const imageUploader = React . useRef ( null ) ;
138
+
139
+ const handleImageUpload = ( e : ChangeEvent < HTMLInputElement > ) => {
140
+ const file = e . target . files [ 0 ] ;
141
+ setProfileImage ( file . name ) ;
142
+ if ( file ) {
143
+ const reader = new FileReader ( ) ;
144
+ const { current } = uploadedImage ;
145
+ current . file = file ;
146
+ reader . onload = e => {
147
+ current . src = e . target . result ;
148
+ } ;
149
+ reader . readAsDataURL ( file ) ;
150
+ }
151
+ } ;
135
152
return (
136
153
< div className = { classes . root } >
137
154
< div className = { classes . subdiv } >
@@ -263,7 +280,9 @@ const AddForm = () => {
263
280
accept = "image/*"
264
281
className = { classes . input }
265
282
id = "icon-button-file"
266
- type = "file"
283
+ type = "file"
284
+ ref = { imageUploader }
285
+ onChange = { handleImageUpload }
267
286
/>
268
287
269
288
< label htmlFor = "icon-button-file" >
@@ -279,7 +298,8 @@ const AddForm = () => {
279
298
</ Grid >
280
299
281
300
< Grid item xs = { 12 } sm = { 7 } >
282
- < img
301
+ < img
302
+ ref = { uploadedImage }
283
303
hidden
284
304
style = { {
285
305
width : "100%" ,
Original file line number Diff line number Diff line change 11
11
"esModuleInterop" : true ,
12
12
"allowSyntheticDefaultImports" : true ,
13
13
"strict" : true ,
14
+ "strictNullChecks" : false ,
14
15
"forceConsistentCasingInFileNames" : true ,
15
16
"noFallthroughCasesInSwitch" : true ,
16
17
"module" : " esnext" ,
You can’t perform that action at this time.
0 commit comments