(event: React.ChangeEvent<HTMLInputElement>)
| 45 | }; |
| 46 | |
| 47 | const onAvatarChange = async (event: React.ChangeEvent<HTMLInputElement>) => { |
| 48 | const file = event.target.files?.[0]; |
| 49 | if (file) { |
| 50 | if (file.size > FILE_SIZE_LIMIT_IN_BYTES) { |
| 51 | event.target.value = ''; |
| 52 | return Toast.error(getFileSizeErrorMessage(file.name)); |
| 53 | } |
| 54 | const formData = new FormData(); |
| 55 | formData.set('file', file, file.name); |
| 56 | try { |
| 57 | setUploading(true); |
| 58 | await onUpload(formData, { |
| 59 | onUploadProgress: (progressEvent: ProgressEvent) => { |
| 60 | const percentCompleted = Math.round( |
| 61 | (progressEvent.loaded * 100) / progressEvent.total |
| 62 | ); |
| 63 | setProgress(percentCompleted); |
| 64 | }, |
| 65 | }); |
| 66 | } catch (exception) { |
| 67 | event.target.value = ''; |
| 68 | Toast.error('Something went wrong. Please try again.'); |
| 69 | } finally { |
| 70 | setUploading(false); |
| 71 | } |
| 72 | } |
| 73 | }; |
| 74 | |
| 75 | return ( |
| 76 | <> |
nothing calls this directly
no test coverage detected