From bda4fe62af0b5a487ce96ab4425ed67451a08ae2 Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 18 Dec 2024 16:43:26 +0100 Subject: [PATCH 1/4] feat: refs #7189 add Accept-Language header to axios requests --- src/boot/axios.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/boot/axios.js b/src/boot/axios.js index aee38e887..3f9fadee5 100644 --- a/src/boot/axios.js +++ b/src/boot/axios.js @@ -3,12 +3,12 @@ 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 { i18n } from 'src/boot/i18n'; const session = useSession(); const { notify } = useNotify(); const stateQuery = useStateQueryStore(); const baseUrl = '/api/'; - axios.defaults.baseURL = baseUrl; const axiosNoError = axios.create({ baseURL: baseUrl }); @@ -16,6 +16,7 @@ const onRequest = (config) => { const token = session.getToken(); if (token.length && !config.headers.Authorization) { config.headers.Authorization = token; + config.headers['Accept-Language'] = i18n.global.locale.value; } stateQuery.add(config); return config; From 777bdec0c772def71c08e0f46025c4163adea427 Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 18 Dec 2024 16:49:06 +0100 Subject: [PATCH 2/4] test: refs #7189 enable skipped test --- test/cypress/integration/vnComponent/VnLog.spec.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/cypress/integration/vnComponent/VnLog.spec.js b/test/cypress/integration/vnComponent/VnLog.spec.js index 4db724e99..80b9d07df 100644 --- a/test/cypress/integration/vnComponent/VnLog.spec.js +++ b/test/cypress/integration/vnComponent/VnLog.spec.js @@ -9,15 +9,15 @@ describe('VnLog', () => { cy.visit(`/#/claim/${1}/log`); cy.openRightMenu(); }); - // Se tiene que cambiar el Accept-Language a 'en', ya hay una tarea para eso #7189. - xit('should filter by insert actions', () => { + + it('should filter by insert actions', () => { cy.checkOption(':nth-child(7) > .q-checkbox'); cy.get('.q-page').click(); cy.validateContent(chips[0], 'Document'); cy.validateContent(chips[1], 'Beginning'); }); - xit('should filter by entity', () => { + it('should filter by entity', () => { cy.selectOption('.q-drawer--right .q-item > .q-select', 'Claim'); cy.get('.q-page').click(); cy.validateContent(chips[0], 'Claim'); From 21ebc854057d6e34be33d20d63f9b73d93f66bd2 Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 18 Dec 2024 17:15:43 +0100 Subject: [PATCH 3/4] test: refs #7189 add Accept-Language header to axios request tests --- 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..b3b6f98c6 100644 --- a/test/vitest/__tests__/boot/axios.spec.js +++ b/test/vitest/__tests__/boot/axios.spec.js @@ -1,4 +1,3 @@ -import { Notify } from 'quasar'; import { onRequest, onResponseError } from 'src/boot/axios'; import { describe, expect, it, vi } from 'vitest'; @@ -27,6 +26,7 @@ describe('Axios boot', () => { expect(resultConfig).toEqual( expect.objectContaining({ headers: { + 'Accept-Language': 'en-US', Authorization: 'DEFAULT_TOKEN', }, }) From adbb574025c2905c274fbd5fa857dd73fc3ac04a Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 18 Dec 2024 17:53:41 +0100 Subject: [PATCH 4/4] fix: refs #7189 update user language on sessionStorage --- src/boot/i18n.js | 4 +++- src/components/UserPanel.vue | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/boot/i18n.js b/src/boot/i18n.js index b23b6d5fd..85d0772a3 100644 --- a/src/boot/i18n.js +++ b/src/boot/i18n.js @@ -1,9 +1,11 @@ import { boot } from 'quasar/wrappers'; import { createI18n } from 'vue-i18n'; import messages from 'src/i18n'; +import { useState } from 'src/composables/useState'; +const user = useState().getUser(); const i18n = createI18n({ - locale: navigator.language || navigator.userLanguage, + locale: user.value.lang || navigator.language || navigator.userLanguage, fallbackLocale: 'en', globalInjection: true, messages, diff --git a/src/components/UserPanel.vue b/src/components/UserPanel.vue index 810f63044..a0ef73a1f 100644 --- a/src/components/UserPanel.vue +++ b/src/components/UserPanel.vue @@ -87,10 +87,10 @@ async function saveDarkMode(value) { async function saveLanguage(value) { const query = `/VnUsers/${user.value.id}`; try { - await axios.patch(query, { - lang: value, - }); + await axios.patch(query, { lang: value }); + user.value.lang = value; + useState().setUser(user.value); onDataSaved(); } catch (error) { onDataError();