diff --git a/package-lock.json b/package-lock.json index e159517..8abdceb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5193,6 +5193,11 @@ "sha.js": "^2.4.8" } }, + "cropperjs": { + "version": "1.5.9", + "resolved": "https://registry.npmjs.org/cropperjs/-/cropperjs-1.5.9.tgz", + "integrity": "sha512-aPWlg43sLIcYN4GBXIdyvM09wNPgn1ug+vNVwV8jlb3dbgEX/B34Iw6hrjGSajkUDQBmaCi6uPOevFb7N0yUsw==" + }, "cross-spawn": { "version": "6.0.5", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", @@ -16377,6 +16382,14 @@ } } }, + "vue-cropperjs": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/vue-cropperjs/-/vue-cropperjs-4.1.0.tgz", + "integrity": "sha512-ORQTaxsygsFvz21Hyf5yNUwQXGRdLXYF4964ueLjR+VpKjHkoqV67oDT3gLCHyrq5HRKmwJPShUiHzdhIo3JTQ==", + "requires": { + "cropperjs": "^1.5.6" + } + }, "vue-hot-reload-api": { "version": "2.3.4", "resolved": "https://registry.npmjs.org/vue-hot-reload-api/-/vue-hot-reload-api-2.3.4.tgz", diff --git a/package.json b/package.json index b1cfdf7..2c109d3 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "leaflet": "^1.6.0", "register-service-worker": "^1.7.1", "vue": "^2.6.11", + "vue-cropperjs": "^4.1.0", "vue-izitoast": "^1.2.1", "vue-router": "^3.2.0", "vue2-leaflet": "^2.5.2", diff --git a/src/components/cpmCard.vue b/src/components/cpmCard.vue index 5748fd9..e31a1c4 100644 --- a/src/components/cpmCard.vue +++ b/src/components/cpmCard.vue @@ -5,8 +5,9 @@ - - + + mdi-account-circle + avatar
{{card.name}}
diff --git a/src/components/cpmDialogProfile.vue b/src/components/cpmDialogProfile.vue index 08c5442..5dd6b5b 100644 --- a/src/components/cpmDialogProfile.vue +++ b/src/components/cpmDialogProfile.vue @@ -66,7 +66,6 @@ - *indicates required field @@ -82,15 +81,17 @@ // import {mapActions} from 'vuex'; export default { - props: ["user_data", "updateUser"], + props: ["user_data", "updateUser", "updateAvatar"], data: () => ({ dialog: false, - + + newAvatar: '', + passwords: { - newPassword: '', - passwordConfirm: '' - } + newPassword: "", + passwordConfirm: "", + }, }), methods: { @@ -98,52 +99,92 @@ export default { // updateUser: 'ProfileVuex/updateUser' // }), + formValidation(){ + if(this.user_data.name == "" || this.user_data.email == "" || this.user_data.whatsapp == ""){ + return false; + }; + + return true; + }, + async pickAvatar() { this.$refs.fileInput.click(); }, - async onFilePicked(event) { + + onFilePicked(event) { const files = event.target.files; let fileName = files[0].filename; + this.imageData = event.target.files[0]; const fileReader = new FileReader(); fileReader.addEventListener("load", () => { this.user_data.avatar = fileReader.result; + this.newAvatar = fileReader.result; }); fileReader.readAsDataURL(files[0]); - this.image = files[0]; }, - //TODO fazer update no avatar do user - async update(){ - - let newUser = { - avatar: this.user_data.avatar, + async uploadPhoto() { + const fd = new FormData(); + fd.append("photo", this.imageData); + + const url = await this.updateAvatar(fd); + + return url; + }, + + async update() { + + if(!this.formValidation()){ + this.$toast.error("Verifique se existe algum campo vazio", "Atenção!", { + position: "topCenter", + }); + + return; + } + + let newUser = { + avatar: this.newAvatar, name: this.user_data.name, email: this.user_data.email, password: "", whatsapp: this.user_data.whatsapp }; - if(this.passwords.newPassword !== '' && this.passwords.passwordConfirm !== ''){ - if(this.passwords.newPassword === this.passwords.passwordConfirm){ + if(newUser.avatar != ""){ + const url = await this.uploadPhoto(); + console.log('a') + newUser.avatar = url; + } + + if ( + this.passwords.newPassword !== "" && + this.passwords.passwordConfirm !== "" + ) { + if (this.passwords.newPassword === this.passwords.passwordConfirm) { newUser.password = this.passwords.newPassword; - }else{ - this.$toast.error('Confirme a senha corretamente.', 'Atenção!', {position: 'topCenter'}) + } else { + this.$toast.error("Confirme a senha corretamente.", "Atenção!", { + position: "topCenter", + }); return; - }; - }; + } + } const retorno = await this.updateUser(newUser); - if(retorno){ - this.$toast.success('Informações atualizadas com sucesso!', 'Yeah', {position: 'topCenter'}); - this.dialog = false - }else{ - this.$toast.error('Aconteceu um erro.', 'Error!', {position: 'topCenter'}) + if (retorno) { + this.$toast.success("Informações atualizadas com sucesso!", "Yeah", { + position: "topCenter", + }); + this.dialog = false; + localStorage.token = retorno; + } else { + this.$toast.error("Aconteceu um erro.", "Error!", { + position: "topCenter", + }); } - - console.log(newUser) - } + }, }, }; \ No newline at end of file diff --git a/src/components/cpmToolBar.vue b/src/components/cpmToolBar.vue index 96f89de..7d88013 100644 --- a/src/components/cpmToolBar.vue +++ b/src/components/cpmToolBar.vue @@ -50,7 +50,7 @@ - mdi-account + mdi-book-plus Eventos @@ -64,7 +64,7 @@
- SAIR + SAIR
@@ -85,7 +85,9 @@ }), methods: { async logOff(){ - await localStorage.removeItem('token') + localStorage.removeItem('token') + + await this.$router.push('/') } } } diff --git a/src/store/modules/ProfileVuex.js b/src/store/modules/ProfileVuex.js index f2c5c85..de6f9f2 100644 --- a/src/store/modules/ProfileVuex.js +++ b/src/store/modules/ProfileVuex.js @@ -38,6 +38,12 @@ export default { const events = await axios.get(process.env.VUE_APP_BASE_URL+'/event/user'); return events.data; + }, + + async updateAvatar(context, newAvatar){ + const retorno = await axios.post(process.env.VUE_APP_UPLOAD_URL+'/upload/image', newAvatar); + + return retorno.data; } } diff --git a/src/views/private/Profile.vue b/src/views/private/Profile.vue index ddc13cd..7539abc 100644 --- a/src/views/private/Profile.vue +++ b/src/views/private/Profile.vue @@ -11,39 +11,47 @@ {{user_data.name}} -
+
{{user_data.email}} {{user_data.whatsapp}}
- - mdi-account-circle - avatar - + + mdi-account-circle + avatar - - - Mandar formulario - - - +

SEUS EVENTOS

-
- +
+
Você não tem eventos cadastrados
+ + + + Cadastre um evento + + + +
+ +
+
-
@@ -58,99 +66,68 @@ \ No newline at end of file