From 632f7bbdeb957b368e9dfa9ee238edca950ad798 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 10 Dec 2024 15:36:25 +0100 Subject: [PATCH 01/25] feat: refs #7308 remove warning --- src/boot/axios.js | 12 ++++++------ src/composables/useSession.js | 14 +------------- src/router/index.js | 14 +++++++------- src/utils/session.js | 23 +++++++++++++++++++++++ 4 files changed, 37 insertions(+), 26 deletions(-) create mode 100644 src/utils/session.js diff --git a/src/boot/axios.js b/src/boot/axios.js index aee38e887..d71928505 100644 --- a/src/boot/axios.js +++ b/src/boot/axios.js @@ -3,8 +3,8 @@ import { useSession } from 'src/composables/useSession'; import { Router } from 'src/router'; import useNotify from 'src/composables/useNotify.js'; import { useStateQueryStore } from 'src/stores/useStateQueryStore'; +import { getToken, isLoggedIn } from 'src/utils/session'; -const session = useSession(); const { notify } = useNotify(); const stateQuery = useStateQueryStore(); const baseUrl = '/api/'; @@ -13,7 +13,7 @@ axios.defaults.baseURL = baseUrl; const axiosNoError = axios.create({ baseURL: baseUrl }); const onRequest = (config) => { - const token = session.getToken(); + const token = getToken(); if (token.length && !config.headers.Authorization) { config.headers.Authorization = token; } @@ -36,15 +36,15 @@ const onResponse = (response) => { return response; }; -const onResponseError = (error) => { +const onResponseError = async (error) => { stateQuery.remove(error.config); - if (session.isLoggedIn() && error.response?.status === 401) { - session.destroy(false); + if (isLoggedIn() && error.response?.status === 401) { + await useSession().destroy(false); const hash = window.location.hash; const url = hash.slice(1); Router.push(`/login?redirect=${url}`); - } else if (!session.isLoggedIn()) { + } else if (!isLoggedIn()) { return Promise.reject(error); } diff --git a/src/composables/useSession.js b/src/composables/useSession.js index 633a30bb0..e69819a68 100644 --- a/src/composables/useSession.js +++ b/src/composables/useSession.js @@ -6,6 +6,7 @@ import axios from 'axios'; import { useRouter } from 'vue-router'; import useNotify from './useNotify'; import { useTokenConfig } from './useTokenConfig'; +import { getToken, getTokenMultimedia } from 'src/utils/session'; const TOKEN_MULTIMEDIA = 'tokenMultimedia'; const TOKEN = 'token'; @@ -15,19 +16,6 @@ export function useSession() { let isCheckingToken = false; let intervalId = null; - function getToken() { - const localToken = localStorage.getItem(TOKEN); - const sessionToken = sessionStorage.getItem(TOKEN); - - return localToken || sessionToken || ''; - } - function getTokenMultimedia() { - const localTokenMultimedia = localStorage.getItem(TOKEN_MULTIMEDIA); - const sessionTokenMultimedia = sessionStorage.getItem(TOKEN_MULTIMEDIA); - - return localTokenMultimedia || sessionTokenMultimedia || ''; - } - function setSession(data) { let keepLogin = data.keepLogin; const storage = keepLogin ? localStorage : sessionStorage; diff --git a/src/router/index.js b/src/router/index.js index 18541c0b2..f2817f64d 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -1,4 +1,4 @@ -import { route } from 'quasar/wrappers'; +import { route as defineRouter } from 'quasar/wrappers'; import { createRouter, createMemoryHistory, @@ -8,14 +8,13 @@ import { import routes from './routes'; import { i18n } from 'src/boot/i18n'; import { useState } from 'src/composables/useState'; -import { useSession } from 'src/composables/useSession'; import { useRole } from 'src/composables/useRole'; import { useUserConfig } from 'src/composables/useUserConfig'; import { useTokenConfig } from 'src/composables/useTokenConfig'; import { useAcl } from 'src/composables/useAcl'; +import { isLoggedIn } from 'src/utils/session'; +import { useSession } from 'src/composables/useSession'; -const state = useState(); -const session = useSession(); const { t, te } = i18n.global; const createHistory = process.env.SERVER @@ -43,11 +42,12 @@ const Router = createRouter({ * with the Router instance. */ export { Router }; -export default route(function (/* { store, ssrContext } */) { +export default defineRouter(function (/* { store, ssrContext } */) { + const state = useState(); Router.beforeEach(async (to, from, next) => { - const { isLoggedIn } = session; + const session = useSession(); const outLayout = Router.options.routes[0].children.map((r) => r.name); - if (!isLoggedIn() && !outLayout.includes(to.name)) { + if (!session.isLoggedIn() && !outLayout.includes(to.name)) { return next({ name: 'Login', query: { redirect: to.fullPath } }); } diff --git a/src/utils/session.js b/src/utils/session.js new file mode 100644 index 000000000..2a8c6a744 --- /dev/null +++ b/src/utils/session.js @@ -0,0 +1,23 @@ +const TOKEN_MULTIMEDIA = 'tokenMultimedia'; +const TOKEN = 'token'; + +function getToken() { + const localToken = localStorage.getItem(TOKEN); + const sessionToken = sessionStorage.getItem(TOKEN); + + return localToken || sessionToken || ''; +} +function getTokenMultimedia() { + const localTokenMultimedia = localStorage.getItem(TOKEN_MULTIMEDIA); + const sessionTokenMultimedia = sessionStorage.getItem(TOKEN_MULTIMEDIA); + + return localTokenMultimedia || sessionTokenMultimedia || ''; +} +function isLoggedIn() { + const localToken = localStorage.getItem(TOKEN); + const sessionToken = sessionStorage.getItem(TOKEN); + + return !!(localToken || sessionToken); +} + +export { getToken, getTokenMultimedia, isLoggedIn }; From 8b3076640d999df985992624ead8f3859439ed61 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 10 Dec 2024 15:36:35 +0100 Subject: [PATCH 02/25] test: refs #7308 fix axios.spec.js --- test/vitest/__tests__/boot/axios.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/vitest/__tests__/boot/axios.spec.js b/test/vitest/__tests__/boot/axios.spec.js index 19d396ec5..8818cb645 100644 --- a/test/vitest/__tests__/boot/axios.spec.js +++ b/test/vitest/__tests__/boot/axios.spec.js @@ -21,7 +21,7 @@ describe('Axios boot', () => { describe('onRequest()', async () => { it('should set the "Authorization" property on the headers', async () => { const config = { headers: {} }; - + localStorage.setItem('token', 'DEFAULT_TOKEN'); const resultConfig = onRequest(config); expect(resultConfig).toEqual( From 37a87fa8e1a54fa3d788f5194e2a9f3734e511b7 Mon Sep 17 00:00:00 2001 From: jtubau Date: Fri, 27 Dec 2024 13:45:01 +0100 Subject: [PATCH 03/25] refactor: refs #8316 used VnSection and VnCardBeta --- src/pages/Customer/Card/CustomerCard.vue | 19 +- src/pages/Customer/CustomerList.vue | 147 ++-- src/pages/Customer/locale/en.yml | 2 + src/pages/Customer/locale/es.yml | 4 +- src/router/modules/customer.js | 882 ++++++++++++----------- 5 files changed, 528 insertions(+), 526 deletions(-) diff --git a/src/pages/Customer/Card/CustomerCard.vue b/src/pages/Customer/Card/CustomerCard.vue index 139917d05..f46884834 100644 --- a/src/pages/Customer/Card/CustomerCard.vue +++ b/src/pages/Customer/Card/CustomerCard.vue @@ -1,25 +1,12 @@ + diff --git a/src/pages/Customer/CustomerList.vue b/src/pages/Customer/CustomerList.vue index fdfd7ff9c..d0f533bb1 100644 --- a/src/pages/Customer/CustomerList.vue +++ b/src/pages/Customer/CustomerList.vue @@ -5,18 +5,19 @@ import { useRouter } from 'vue-router'; import { useSummaryDialog } from 'src/composables/useSummaryDialog'; import { toDate } from 'src/filters'; -import RightMenu from 'src/components/common/RightMenu.vue'; import CustomerSummary from './Card/CustomerSummary.vue'; import CustomerFilter from './CustomerFilter.vue'; import VnTable from 'components/VnTable/VnTable.vue'; import VnLocation from 'src/components/common/VnLocation.vue'; -import VnSearchbar from 'components/ui/VnSearchbar.vue'; import VnLinkPhone from 'src/components/ui/VnLinkPhone.vue'; import VnSelectWorker from 'src/components/common/VnSelectWorker.vue'; +import VnSection from 'src/components/common/VnSection.vue'; const { t } = useI18n(); const router = useRouter(); const tableRef = ref(); +const dataKey = 'CustomerList'; + const columns = computed(() => [ { align: 'left', @@ -390,82 +391,86 @@ function handleLocation(data, location) {