fixes: Tracking load & load edit

This commit is contained in:
Alexandro Uc Santos
2024-04-13 16:15:59 -06:00
parent f026e568f6
commit 189a815a57
8 changed files with 78 additions and 29 deletions

View File

@@ -5,6 +5,10 @@
import NotificationBadge from './ui/NotificationBadge.vue'; import NotificationBadge from './ui/NotificationBadge.vue';
import { validateEmail } from '../helpers/validations'; import { validateEmail } from '../helpers/validations';
import Swal from 'sweetalert2'; import Swal from 'sweetalert2';
import { useAuthStore } from '../stores/auth';
import { useNotificationsStore } from '../stores/notifications';
import { useRouter } from 'vue-router';
const emailForm = reactive({ const emailForm = reactive({
email: '', email: '',
email2: '', email2: '',
@@ -13,6 +17,9 @@
const loading = ref(false) const loading = ref(false)
const msgError = ref(''); const msgError = ref('');
const msgSuccess = ref(''); const msgSuccess = ref('');
const auth = useAuthStore();
const notifications = useNotificationsStore();
const router = useRouter();
const hangleSave = () => { const hangleSave = () => {
msgError.value = ''; msgError.value = '';
@@ -32,7 +39,7 @@
cancelButtonColor: "#d33", cancelButtonColor: "#d33",
confirmButtonText: 'Confirmar', confirmButtonText: 'Confirmar',
cancelButtonText: 'Cancelar', cancelButtonText: 'Cancelar',
}).then(async(result) => { }).then( async(result) => {
if(result.isConfirmed) { if(result.isConfirmed) {
Swal.fire({ Swal.fire({
title: 'Por favor espere!', title: 'Por favor espere!',
@@ -42,8 +49,27 @@
Swal.showLoading() 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() Swal.close()
} }

View File

@@ -85,6 +85,7 @@
show : true, show : true,
error: false error: false
}); });
auth.logout();
router.push({name: 'login'}); router.push({name: 'login'});
} else { } else {
msgError.value = result.msg; msgError.value = result.msg;

View File

@@ -79,6 +79,7 @@
formLoad.owner = auth.user?.first_name + ' ' + auth.user?.last_name; formLoad.owner = auth.user?.first_name + ' ' + auth.user?.last_name;
//origin_formatted_address //origin_formatted_address
if(loadStore.currentLoad){ if(loadStore.currentLoad){
console.log(loadStore.currentLoad);
formLoad.price = loadStore.currentLoad.actual_cost; formLoad.price = loadStore.currentLoad.actual_cost;
formLoad.segment = loadStore.currentLoad.categories?.length <= 0 ? [] : loadStore.currentLoad.categories.map(m =>{ formLoad.segment = loadStore.currentLoad.categories?.length <= 0 ? [] : loadStore.currentLoad.categories.map(m =>{
return m; return m;
@@ -130,7 +131,7 @@
watch([originCoords, destinationCoords], async() => { watch([originCoords, destinationCoords], async() => {
if(originCoords.value && destinationCoords.value) { 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); polylines.value = await getDirections(originCoords.value, destinationCoords.value);
} }
}) })
@@ -160,12 +161,26 @@
} }
const getCoordsMap = async() => { const getCoordsMap = async() => {
if(loadStore.currentLoad.origin_formatted_address) { const destinationLat = loadStore.currentLoad.destination?.lat;
originCoords.value = await geocodeAddress(loadStore.currentLoad.origin_formatted_address); 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){ if(originLat && originLng) {
destinationCoords.value = await geocodeAddress(loadStore.currentLoad.destination_formatted_address); 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);
// }
} }

View File

@@ -60,10 +60,16 @@ export const updateMyUserProfile = async(formData) => {
try { try {
const endpoint = `/v1/users/profile`; const endpoint = `/v1/users/profile`;
const {data} = await api.patch(endpoint, formData); const {data} = await api.patch(endpoint, formData);
return data; return {
msg: "success",
data: data
};
} catch (error) { } catch (error) {
console.log(error); console.log(error);
return null; return {
msg: error.response.data.error,
data: null
};
} }
} }

View File

@@ -59,12 +59,12 @@ export const useAuthStore = defineStore('auth', () => {
const updateProfile = async(data) => { const updateProfile = async(data) => {
const response = await updateMyUserProfile(data); const response = await updateMyUserProfile(data);
console.log(response); // console.log(response);
if( response !== null) { if( response.msg === 'success') {
user.value = response; user.value = response.data;
return response; return response;
} else { } else {
return null; return response;
} }
} }

View File

@@ -107,11 +107,11 @@
"phone2" : user.phone2, "phone2" : user.phone2,
}; };
let respUser = await updateMyUserProfile( userData ); let respUser = await updateMyUserProfile( userData );
console.log('User create: ', respUser); // console.log('User create: ', respUser);
if(respUser === null) { if(respUser.msg === 'success') {
auth.user = userData; auth.user = respUser.data;
} else { } else {
auth.user = respUser; auth.user = userData;
} }
/////// Datos debug /////// /////// Datos debug ///////
notifications.show = true; notifications.show = true;

View File

@@ -57,11 +57,11 @@
loading.value = true; loading.value = true;
const result = await auth.updateProfile(userData) const result = await auth.updateProfile(userData)
loading.value = false; loading.value = false;
if(result === null) { if(result.msg === 'success') {
msgError.value = 'Algo salio mal, intente más tarde'; msgSuccess.value = 'Usuario actualizado';
clearMessages(); clearMessages();
} else { } else {
msgSuccess.value = 'Usuario actualizado'; msgError.value = 'Algo salio mal, intente más tarde';
clearMessages(); clearMessages();
} }
} }

View File

@@ -35,15 +35,17 @@
const id = route.params['code']; const id = route.params['code'];
await getLoadTracking(id) await getLoadTracking(id)
if(load.value !== null) { if(load.value !== null) {
const addressOrigin = load.value.origin_geo?.coordinates; console.log(load.value)
const addressDestination = load.value.destination_geo?.coordinates; const addressOrigin = load.value?.origin_geo?.coordinates;
if(addressOrigin !== null) { const addressDestination = load.value?.destination_geo?.coordinates;
if(addressOrigin && addressDestination) {
originCoords.value = {lat: Number.parseFloat(addressOrigin[0]), lng: Number.parseFloat(addressOrigin[1])}; 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) { if(load.value.vehicle) {
vehicleLastLocation.value = { vehicleLastLocation.value = {
lat: parseFloat(load.value.vehicle.last_location_lat), lat: parseFloat(load.value.vehicle.last_location_lat),
@@ -52,7 +54,6 @@
console.log(vehicleLastLocation); console.log(vehicleLastLocation);
} }
polylines.value = await getDirections(originCoords.value, destinationCoords.value);
console.log(load.value.load_status); console.log(load.value.load_status);
switch (load.value.load_status) { switch (load.value.load_status) {
@@ -109,8 +110,8 @@
fullscreenControl: true fullscreenControl: true
}" }"
> >
<Marker :options="{position: originCoords, label: 'O', title: 'Destino'}" /> <Marker v-if="originCoords" :options="{position: originCoords, label: 'O', title: 'Destino'}" />
<Marker :options="{position: destinationCoords, label: 'D', title: 'Origen'}" /> <Marker v-if="destinationCoords" :options="{position: destinationCoords, label: 'D', title: 'Origen'}" />
<CustomMarker <CustomMarker
v-if="vehicleLastLocation && load.vehicle.background_tracking && isLoadActive" v-if="vehicleLastLocation && load.vehicle.background_tracking && isLoadActive"
:options="{position: vehicleLastLocation}" :options="{position: vehicleLastLocation}"