Skip to content

Commit

Permalink
Do not allow big files to be uploaded in the form of the expense.
Browse files Browse the repository at this point in the history
  • Loading branch information
slavcho committed Sep 5, 2023
1 parent 94750d4 commit 18daf90
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion public/locales/bg/expenses.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
"success": "Разходите са изтрити успешно!"
},
"delete": "Изтрит разход",
"no-files-uploaded": "Няма прикачени файлове!"
"no-files-uploaded": "Няма прикачени файлове!",
"file-too-big": "Файлът е твърде голям"
},
"btns": {
"add": "Добави",
Expand Down
3 changes: 2 additions & 1 deletion public/locales/en/expenses.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
"success": "Expenses were deleted successfully!!"
},
"delete": "Deleted expense",
"no-files-uploaded": "No files uploaded"
"no-files-uploaded": "No files uploaded",
"file-too-big": "File too big"
},
"btns": {
"add": "Add",
Expand Down
17 changes: 17 additions & 0 deletions src/components/client/campaign-expenses/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,23 @@ export default function Form() {
<FileUpload
buttonLabel={t('expenses:add-documents')}
onUpload={(newFiles) => {
newFiles = newFiles.filter((file) => {
const maxFileSize = 20 * 1000000
if (file.size > maxFileSize) {
const alert =
t('expenses:alerts.file-too-big') +
': ' +
Math.ceil(file.size / 1000000) +
'M' +
'(max:' +
maxFileSize / 1000000 +
'M)!'
AlertStore.show(alert, 'error')
return false
}
return true
})

setFilesToUpload((prevFiles) => [...prevFiles, ...newFiles])
}}
/>
Expand Down

0 comments on commit 18daf90

Please sign in to comment.