Merge pull request 'feat: refs #7189 add Accept-Language header to axios requests' (!1111) from 7189-setAcceptLanguage into dev
gitea/salix-front/pipeline/head This commit looks good
Details
gitea/salix-front/pipeline/head This commit looks good
Details
Reviewed-on: #1111 Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
commit
9e686f6a25
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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',
|
||||
},
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue