fix: Check uploaded file size in widget and dashboard (#1975)

* File size check logic in widget

* set maxium file size

* update locale texts

* file size check in dashboard

* dynamincally set file size limit error message

* code climate review fixes

* add alert mixin

* move attahcment bus event to constants

* Move file size check logic to helper

* add specs for file size limit check helper

* changes as per review
This commit is contained in:
Muhsin Keloth 2021-04-15 22:28:19 +05:30 committed by GitHub
parent 45e43b0b89
commit ce4ce3c86c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 143 additions and 56 deletions

View file

@ -4,7 +4,7 @@
accept="image/*, application/pdf, audio/mpeg, video/mp4, audio/ogg, text/csv"
@input-file="onFileUpload"
>
<span class="attachment-button ">
<span class="attachment-button">
<i v-if="!isUploading.image" class="ion-android-attach" />
<spinner v-if="isUploading" size="small" />
</span>
@ -14,6 +14,9 @@
<script>
import FileUpload from 'vue-upload-component';
import Spinner from 'shared/components/Spinner.vue';
import { checkFileSizeLimit } from 'shared/helpers/FileHelper';
import { MAXIMUM_FILE_UPLOAD_SIZE } from 'shared/constants/messages';
import { BUS_EVENTS } from 'shared/constants/busEvents';
export default {
components: { FileUpload, Spinner },
@ -31,14 +34,21 @@ export default {
return fileType.includes('image') ? 'image' : 'file';
},
async onFileUpload(file) {
if (!file) {
return;
}
this.isUploading = true;
try {
const thumbUrl = window.URL.createObjectURL(file.file);
await this.onAttach({
fileType: this.getFileType(file.type),
file: file.file,
thumbUrl,
});
if (checkFileSizeLimit(file, MAXIMUM_FILE_UPLOAD_SIZE)) {
const thumbUrl = window.URL.createObjectURL(file.file);
await this.onAttach({
fileType: this.getFileType(file.type),
file: file.file,
thumbUrl,
});
} else {
window.bus.$emit(BUS_EVENTS.ATTACHMENT_SIZE_CHECK_ERROR);
}
} catch (error) {
// Error
}