diff --git a/src/components/FormChangeEmail.vue b/src/components/FormChangeEmail.vue
index 912c15f..82ee994 100644
--- a/src/components/FormChangeEmail.vue
+++ b/src/components/FormChangeEmail.vue
@@ -5,6 +5,10 @@
import NotificationBadge from './ui/NotificationBadge.vue';
import { validateEmail } from '../helpers/validations';
import Swal from 'sweetalert2';
+ import { useAuthStore } from '../stores/auth';
+import { useNotificationsStore } from '../stores/notifications';
+import { useRouter } from 'vue-router';
+
const emailForm = reactive({
email: '',
email2: '',
@@ -13,6 +17,9 @@
const loading = ref(false)
const msgError = ref('');
const msgSuccess = ref('');
+ const auth = useAuthStore();
+ const notifications = useNotificationsStore();
+ const router = useRouter();
const hangleSave = () => {
msgError.value = '';
@@ -32,7 +39,7 @@
cancelButtonColor: "#d33",
confirmButtonText: 'Confirmar',
cancelButtonText: 'Cancelar',
- }).then(async(result) => {
+ }).then( async(result) => {
if(result.isConfirmed) {
Swal.fire({
title: 'Por favor espere!',
@@ -42,8 +49,27 @@
Swal.showLoading()
},
});
- // const resp = await companyStore.deleteUserCompany(props.user._id)
+ const userData = {
+ "email" : emailForm.email,
+ };
+ console.log(userData);
+ loading.value = true;
+ const response = await auth.updateProfile(userData)
+ loading.value = false;
+ if (response.msg !== 'success') {
+ msgError.value = response.msg;
+ clearMessages();
+ } else {
+ clearMessages();
+ notifications.$patch({
+ text : 'Correo electrónico se ha cambiando exitosamente!',
+ show : true,
+ error: false
+ });
+ auth.logout();
+ router.push({name: 'login'});
+ }
Swal.close()
}
diff --git a/src/components/FormChangePassword.vue b/src/components/FormChangePassword.vue
index 55893f7..66e06b4 100644
--- a/src/components/FormChangePassword.vue
+++ b/src/components/FormChangePassword.vue
@@ -85,6 +85,7 @@
show : true,
error: false
});
+ auth.logout();
router.push({name: 'login'});
} else {
msgError.value = result.msg;
diff --git a/src/components/FormLoadModal.vue b/src/components/FormLoadModal.vue
index 4ee14d2..4262b24 100644
--- a/src/components/FormLoadModal.vue
+++ b/src/components/FormLoadModal.vue
@@ -79,6 +79,7 @@
formLoad.owner = auth.user?.first_name + ' ' + auth.user?.last_name;
//origin_formatted_address
if(loadStore.currentLoad){
+ console.log(loadStore.currentLoad);
formLoad.price = loadStore.currentLoad.actual_cost;
formLoad.segment = loadStore.currentLoad.categories?.length <= 0 ? [] : loadStore.currentLoad.categories.map(m =>{
return m;
@@ -130,7 +131,7 @@
watch([originCoords, destinationCoords], async() => {
if(originCoords.value && destinationCoords.value) {
- console.log('Se llama api direcciones ')
+ // console.log('Se llama api direcciones ')
polylines.value = await getDirections(originCoords.value, destinationCoords.value);
}
})
@@ -160,12 +161,26 @@
}
const getCoordsMap = async() => {
- if(loadStore.currentLoad.origin_formatted_address) {
- originCoords.value = await geocodeAddress(loadStore.currentLoad.origin_formatted_address);
+ const destinationLat = loadStore.currentLoad.destination?.lat;
+ const destinationLng = loadStore.currentLoad.destination?.lng;
+ const originLat = loadStore.currentLoad.origin?.lat;
+ const originLng = loadStore.currentLoad.origin?.lng;
+ if(destinationLat && destinationLng) {
+ destinationCoords.value = {lat: Number.parseFloat(destinationLat), lng: Number.parseFloat(destinationLng)}
}
- if(loadStore.currentLoad.destination_formatted_address){
- destinationCoords.value = await geocodeAddress(loadStore.currentLoad.destination_formatted_address);
+ if(originLat && originLng) {
+ originCoords.value = {lat: Number.parseFloat(originLat), lng: Number.parseFloat(originLng)}
}
+
+ if(originCoords.value && destinationCoords.value) {
+ polylines.value = await getDirections(originCoords.value, destinationCoords.value);
+ }
+ // if(loadStore.currentLoad.origin_formatted_address) {
+ // originCoords.value = await geocodeAddress(loadStore.currentLoad.origin_formatted_address);
+ // }
+ // if(loadStore.currentLoad.destination_formatted_address){
+ // destinationCoords.value = await geocodeAddress(loadStore.currentLoad.destination_formatted_address);
+ // }
}
diff --git a/src/services/company.js b/src/services/company.js
index 2e1bbc9..2d23903 100644
--- a/src/services/company.js
+++ b/src/services/company.js
@@ -60,10 +60,16 @@ export const updateMyUserProfile = async(formData) => {
try {
const endpoint = `/v1/users/profile`;
const {data} = await api.patch(endpoint, formData);
- return data;
+ return {
+ msg: "success",
+ data: data
+ };
} catch (error) {
console.log(error);
- return null;
+ return {
+ msg: error.response.data.error,
+ data: null
+ };
}
}
diff --git a/src/stores/auth.js b/src/stores/auth.js
index 70fcbef..7b72efc 100644
--- a/src/stores/auth.js
+++ b/src/stores/auth.js
@@ -59,12 +59,12 @@ export const useAuthStore = defineStore('auth', () => {
const updateProfile = async(data) => {
const response = await updateMyUserProfile(data);
- console.log(response);
- if( response !== null) {
- user.value = response;
+ // console.log(response);
+ if( response.msg === 'success') {
+ user.value = response.data;
return response;
} else {
- return null;
+ return response;
}
}
diff --git a/src/views/CompleteRegisterView.vue b/src/views/CompleteRegisterView.vue
index 6cdfebb..612c688 100644
--- a/src/views/CompleteRegisterView.vue
+++ b/src/views/CompleteRegisterView.vue
@@ -107,11 +107,11 @@
"phone2" : user.phone2,
};
let respUser = await updateMyUserProfile( userData );
- console.log('User create: ', respUser);
- if(respUser === null) {
- auth.user = userData;
+ // console.log('User create: ', respUser);
+ if(respUser.msg === 'success') {
+ auth.user = respUser.data;
} else {
- auth.user = respUser;
+ auth.user = userData;
}
/////// Datos debug ///////
notifications.show = true;
diff --git a/src/views/EditProfileView.vue b/src/views/EditProfileView.vue
index ca04cdd..170381a 100644
--- a/src/views/EditProfileView.vue
+++ b/src/views/EditProfileView.vue
@@ -57,11 +57,11 @@
loading.value = true;
const result = await auth.updateProfile(userData)
loading.value = false;
- if(result === null) {
- msgError.value = 'Algo salio mal, intente más tarde';
+ if(result.msg === 'success') {
+ msgSuccess.value = 'Usuario actualizado';
clearMessages();
} else {
- msgSuccess.value = 'Usuario actualizado';
+ msgError.value = 'Algo salio mal, intente más tarde';
clearMessages();
}
}
diff --git a/src/views/TrackingLoadView.vue b/src/views/TrackingLoadView.vue
index 9768bfb..9765573 100644
--- a/src/views/TrackingLoadView.vue
+++ b/src/views/TrackingLoadView.vue
@@ -35,15 +35,17 @@
const id = route.params['code'];
await getLoadTracking(id)
if(load.value !== null) {
- const addressOrigin = load.value.origin_geo?.coordinates;
- const addressDestination = load.value.destination_geo?.coordinates;
- if(addressOrigin !== null) {
+ console.log(load.value)
+ const addressOrigin = load.value?.origin_geo?.coordinates;
+ const addressDestination = load.value?.destination_geo?.coordinates;
+ if(addressOrigin && addressDestination) {
originCoords.value = {lat: Number.parseFloat(addressOrigin[0]), lng: Number.parseFloat(addressOrigin[1])};
+ destinationCoords.value = {lat: Number.parseFloat(addressDestination[0]), lng: Number.parseFloat(addressDestination[1])};
+
+ polylines.value = await getDirections(originCoords.value, destinationCoords.value);
+
}
- if(addressDestination !== null) {
- destinationCoords.value = {lat: Number.parseFloat(addressDestination[0]), lng: Number.parseFloat(addressDestination[1])};
- }
if(load.value.vehicle) {
vehicleLastLocation.value = {
lat: parseFloat(load.value.vehicle.last_location_lat),
@@ -52,7 +54,6 @@
console.log(vehicleLastLocation);
}
- polylines.value = await getDirections(originCoords.value, destinationCoords.value);
console.log(load.value.load_status);
switch (load.value.load_status) {
@@ -109,8 +110,8 @@
fullscreenControl: true
}"
>
-
-
+
+