From 18920ac2fc594c4dcceafc579c28dc9347c61b6c Mon Sep 17 00:00:00 2001 From: Alexandro Uc Santos Date: Fri, 19 Apr 2024 20:19:25 -0600 Subject: [PATCH 1/2] fix: close sesion in public page --- src/components/FormLoadModal.vue | 2 +- src/router/index.js | 4 ++-- src/services/public.js | 2 +- src/stores/auth.js | 18 +++++++++++++++--- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/components/FormLoadModal.vue b/src/components/FormLoadModal.vue index 4262b24..4e0b148 100644 --- a/src/components/FormLoadModal.vue +++ b/src/components/FormLoadModal.vue @@ -417,7 +417,7 @@
- + diff --git a/src/router/index.js b/src/router/index.js index 81046d1..c481ba3 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -155,8 +155,8 @@ const router = createRouter({ router.beforeEach( async(to, from, next) => { const requiresAuth = to.matched.some(url => url.meta.requiresAuth) - const session = localStorage.getItem('session'); - if(requiresAuth) { + if(requiresAuth === true) { + const session = localStorage.getItem('session'); //Comprobamos si el usuario esta authenticado if(session) { // if(!authStore.user) { diff --git a/src/services/public.js b/src/services/public.js index 669adfe..b033d24 100644 --- a/src/services/public.js +++ b/src/services/public.js @@ -64,7 +64,7 @@ export const getCompanies = async(filter) => { export const getLoadPublic = async(id) => { try { const endpoint = `/v1/public-load-tracking/${id}`; - console.log(endpoint); + // console.log(endpoint); const {data} = await api.get(endpoint); return data; } catch (error) { diff --git a/src/stores/auth.js b/src/stores/auth.js index 7b72efc..11670b6 100644 --- a/src/stores/auth.js +++ b/src/stores/auth.js @@ -1,6 +1,6 @@ import { defineStore } from "pinia"; import { ref, onMounted } from "vue"; -import { useRouter } from 'vue-router'; +import { useRoute, useRouter } from 'vue-router'; import { renewToken } from '../services/auth'; import {useNotificationsStore} from './notifications'; import {useCompanyStore} from './company'; @@ -11,6 +11,7 @@ import { updateMyUserProfile } from "../services/company"; export const useAuthStore = defineStore('auth', () => { const router = useRouter(); + const route = useRoute(); const noty = useNotificationsStore(); const company = useCompanyStore(); const loadStore = useLoadsStore(); @@ -19,16 +20,27 @@ export const useAuthStore = defineStore('auth', () => { const checking = ref(false); const authStatus = ref('checking'); const token = ref('') - const user = ref(null) + const user = ref(null); + const publicNames = [ + 'terms-conditions', + 'notice-privacy', + 'tracking-load', + 'faqs', + 'login', + 'register', + 'recovery', + 'register-company', + ] onMounted( async() => { checkSession(); }); + const checkSession = async() => { const session = localStorage.getItem('session'); authStatus.value = 'checking'; - if(session) { + if(session && !publicNames.includes(route.name)) { checking.value = true; const resp = await renewToken(); if(resp.msg === 'success') { From 2ce0fd01a43da98990f162f9eaa25d8305e2aa46 Mon Sep 17 00:00:00 2001 From: Alexandro Uc Santos Date: Sat, 20 Apr 2024 16:59:12 -0600 Subject: [PATCH 2/2] fixes: directions api change --- index.html | 3 ++ src/components/LoadDetailModal.vue | 69 +++++++++++++++++---------- src/components/MakeProposalModal.vue | 7 ++- src/components/Sidebar.vue | 4 +- src/composables/useDirectionRender.js | 48 +++++++++++++++++-- src/views/TrackingLoadView.vue | 2 +- 6 files changed, 95 insertions(+), 38 deletions(-) diff --git a/index.html b/index.html index 22591d9..d132df6 100644 --- a/index.html +++ b/index.html @@ -15,6 +15,9 @@
+ + + diff --git a/src/components/LoadDetailModal.vue b/src/components/LoadDetailModal.vue index de38eca..1ad96ec 100644 --- a/src/components/LoadDetailModal.vue +++ b/src/components/LoadDetailModal.vue @@ -6,6 +6,7 @@ import useDirectionsRender from '../composables/useDirectionRender'; import Cardload from './CardLoad.vue'; import { useLoadsStore } from '../stores/loads'; +import { useNotificationsStore } from '../stores/notifications'; const mapKey = import.meta.env.VITE_MAP_KEY; @@ -20,7 +21,7 @@ const vehicleLastLocation = ref(null); const isLoadActive = ref(false); - const { geocodeAddress, getDirections } = useDirectionsRender() + const { getDirections } = useDirectionsRender() const props = defineProps({ proposal: { @@ -32,6 +33,7 @@ defineEmits(['reset-proposal']) const loadStore = useLoadsStore(); + const notyStore = useNotificationsStore(); onMounted(() => { window.addEventListener('resize', handleResize); @@ -44,36 +46,53 @@ }); const initData = async() => { + console.log(props.proposal) isLoading.value = true; const code = props.proposal.load.shipment_code; const filter = "?shipment_code[$in]=" + code; const resp = await loadStore.getLoad(filter); + console.log(resp); if(resp.total > 0) { load.value = resp.data[0]; - originCoords.value = await geocodeAddress(load.value.origin_formatted_address); - destinationCoords.value = await geocodeAddress(load.value.destination_formatted_address); - polylines.value = await getDirections(originCoords.value, destinationCoords.value); - if(load.value.vehicle) { - vehicleLastLocation.value = { - lat: parseFloat(load.value.vehicle.last_location_lat), - lng: parseFloat(load.value.vehicle.last_location_lng) + try { + const addressOrigin = load.value?.origin; + const addressDestination = load.value?.destination; + if(addressOrigin && addressDestination) { + originCoords.value = {lat: Number.parseFloat(addressOrigin.lat), lng: Number.parseFloat(addressOrigin.lng)}; + destinationCoords.value = {lat: Number.parseFloat(addressDestination.lat), lng: Number.parseFloat(addressDestination.lng)}; + + polylines.value = await getDirections(originCoords.value, destinationCoords.value); + } - } - - switch (load.value.load_status) { - case 'Loading': - isLoadActive.value = true; - break; - case 'Transit': - isLoadActive.value = true; - break; - case 'Downloading': - isLoadActive.value = true; - break; - - default: - isLoadActive.value = false; - break; + + if(load.value.vehicle) { + vehicleLastLocation.value = { + lat: parseFloat(load.value.vehicle.last_location_lat), + lng: parseFloat(load.value.vehicle.last_location_lng) + } + } + + switch (load.value.load_status) { + case 'Loading': + isLoadActive.value = true; + break; + case 'Transit': + isLoadActive.value = true; + break; + case 'Downloading': + isLoadActive.value = true; + break; + + default: + isLoadActive.value = false; + break; + } + } catch (error) { + notyStore.$patch({ + text : 'No se pudo cargar mapa', + show : true, + error: true + }); } } @@ -140,7 +159,6 @@ :draggable="false" >
-
@@ -148,7 +166,6 @@ v-if="polylines" :options="{ path: polylines, - // geodesic: true, strokeColor: '#2D90BB', strokeOpacity: 0.7, strokeWeight: 5, diff --git a/src/components/MakeProposalModal.vue b/src/components/MakeProposalModal.vue index 9131293..eba1fa1 100644 --- a/src/components/MakeProposalModal.vue +++ b/src/components/MakeProposalModal.vue @@ -8,7 +8,7 @@ import { useAuthStore } from '../stores/auth'; import { useCompanyStore } from '../stores/company'; import { useVehiclesStore } from '../stores/vehicles'; - import { saveProposal } from '../services/vehicles' + // import { saveProposal } from '../services/vehicles' import Swal from 'sweetalert2'; const mapKey = import.meta.env.VITE_MAP_KEY; @@ -57,7 +57,6 @@ }); const initData = async() => { - console.log('load: ', props.load); isLoading.value = true; let filterQuery = []; filterQuery.company = "company="+ authStore.user.company @@ -66,7 +65,7 @@ destinationCoords.value = {lat: Number.parseFloat(props.load.destination.lat), lng: Number.parseFloat(props.load.destination.lng)};; polylines.value = await getDirections(originCoords.value, destinationCoords.value); isLoading.value = false; - console.log(props.proposal); + // console.log(props.proposal); if(props.proposal) { form.vehicle = props.proposal.vehicle._id; form.comments = props.proposal.comment; @@ -121,7 +120,7 @@ } const index = vehiclesStore.vehicles.findIndex((prop) => prop._id === form.vehicle); const vehicleSelected = vehiclesStore.vehicles[index]; - console.log(vehicleSelected); + // console.log(vehicleSelected); const localData = { vehicle: vehicleSelected, load: props.load, diff --git a/src/components/Sidebar.vue b/src/components/Sidebar.vue index 338995a..4ef20d9 100644 --- a/src/components/Sidebar.vue +++ b/src/components/Sidebar.vue @@ -113,7 +113,7 @@ class="nav-link" :to="{name: 'calculator'}">Calculadora
-
  • @@ -122,7 +122,7 @@ active-class="router-link-active" class="nav-link" :to="{name: 'carriers'}">Transportistas
    -
  • + -->