| 37 | const [uploading, setUploading] = useState(false); |
| 38 | |
| 39 | const onFileChange = async (event: React.ChangeEvent<HTMLInputElement>) => { |
| 40 | const files = Array.from(event.target.files || []); |
| 41 | setProgress(0); |
| 42 | setUploading(true); |
| 43 | const data = new FormData(); |
| 44 | files.forEach((file, index) => { |
| 45 | data.append(`file-${index}`, file, file.name); |
| 46 | }); |
| 47 | try { |
| 48 | const { files: files_1 } = await api.upload( |
| 49 | { communityId: currentCommunity.id, data, type: 'logos' }, |
| 50 | { |
| 51 | onUploadProgress: (progressEvent_1: ProgressEvent) => { |
| 52 | const percentCompleted = Math.round( |
| 53 | (progressEvent_1.loaded * 100) / progressEvent_1.total |
| 54 | ); |
| 55 | setProgress(percentCompleted); |
| 56 | }, |
| 57 | } |
| 58 | ); |
| 59 | setUploading(false); |
| 60 | onChange(files_1[0].url); |
| 61 | } catch (response) { |
| 62 | setUploading(false); |
| 63 | return response; |
| 64 | } |
| 65 | }; |
| 66 | |
| 67 | return ( |
| 68 | <> |