@@ -104,7 +104,8 @@ class Settings extends React.Component {
104
104
constructor ( props ) {
105
105
super ( props ) ;
106
106
this . state = {
107
- passwordChangeModal : false
107
+ fileList : [ ] ,
108
+ disableUpload : false
108
109
}
109
110
}
110
111
@@ -117,15 +118,41 @@ class Settings extends React.Component {
117
118
< Layout className = "layout-style" >
118
119
< Divider />
119
120
< div style = { { display : "flex" , marginRight : "5ch" , alignItems : "center" , justifyItems : "center" } } >
120
- < div style = { { display : "flex" , flexDirection : "column" , alignItems : "center " , justifyContent : "center " } } >
121
- < Avatar style = { { backgroundColor : "Red" , width : "10ch " , height : "10ch " } } size = 'large' src = { require ( "./assets /profile.webp" ) . default } />
121
+ < div style = { { display : "flex" , flexDirection : "column" , justifyContent : "initial " , width : "15ch" , overflow : "hidden " } } >
122
+ < Avatar style = { { backgroundColor : "Red" , width : "12ch " , height : "12ch " } } size = 'large' src = { "https://api.irscybersec.tk/uploads /profile/" + this . props . username } />
122
123
< div style = { { marginTop : "2ch" } } >
123
- < Upload beforeUpload = { file => {
124
- if ( file . type !== 'image/png' ) {
125
- message . error ( `${ file . name } is not a png file` ) ;
126
- }
127
- return file . type === 'image/png' ? true : Upload . LIST_IGNORE ;
128
- } } >
124
+ < Upload
125
+ fileList = { this . state . fileList }
126
+ disabled = { this . state . disableUpload }
127
+ accept = ".png, .jpg, .jpeg, .webp"
128
+ action = { window . ipAddress + "/v1/profile/upload" }
129
+ maxCount = { 1 }
130
+ onChange = { ( file ) => {
131
+ this . setState ( { fileList : file . fileList } )
132
+ if ( file . file . status === "uploading" ) {
133
+ this . setState ( { disableUpload : true } )
134
+ }
135
+ else if ( "response" in file . file ) {
136
+ if ( file . file . response . success ) message . success ( "Uploaded profile picture" )
137
+ else message . error ( "Failed to upload profile picture" )
138
+ this . setState ( { fileList : [ ] , disableUpload : false } )
139
+ }
140
+ } }
141
+ headers = { { "Authorization" : localStorage . getItem ( "IRSCTF-token" ) } }
142
+ name = "profile_pic"
143
+ beforeUpload = { file => {
144
+ const exts = [ "image/png" , "image/jpg" , "image/jpeg" , "image/webp" ]
145
+ if ( ! exts . includes ( file . type ) ) {
146
+ message . error ( `${ file . name } is not an image file.` ) ;
147
+ return Upload . LIST_IGNORE
148
+ }
149
+ if ( file . size > 102400 ) {
150
+ message . error ( `${ file . name } is larger than 100KB.` ) ;
151
+ message . info ( 'Please upload a smaller file' )
152
+ return Upload . LIST_IGNORE
153
+ }
154
+ return true
155
+ } } >
129
156
< Button type = "primary" icon = { < UploadOutlined /> } > Upload</ Button >
130
157
</ Upload >
131
158
</ div >
0 commit comments