-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProfile.vue
44 lines (43 loc) · 1.46 KB
/
Profile.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<template>
<div>
<media-upload
v-on:fileAdded="fileAdded"
:resource="profile.avatar.avatar.url">
</media-upload>
</div>
</template>
<script>
import MediaUpload from '@/MediaUpload';
import FileService from '@/FileService';
export default {
components: {
MediaUpload
},
methods: {
fileAdded(data) {
const vm = this;
if (data.file.size > 10 * 1024 * 1024) {
notificationService.warning(vm.$t('common.too_large'));
} else {
FileService.getBase64(data.file.file).then((encodedImage) => {
vm.uploadImage(encodedImage);
});
}
},
uploadImage(encodedImage) {
const vm = this;
const image = encodedImage.split(',')[1];
const payload = {
avatar: image,
};
vm.showSpinner = true;
vm.$store.dispatch('profile/addProfileAvatar', payload).then(() => {
notificationService.success(vm.$t('profile.image_updated_successfully'));
vm.showSpinner = false;
}, (error) => {
notificationService.error(error);
vm.showSpinner = false;
});
},
},
}