forked from verdnatura/salix-front
Merge pull request '#8031 - Enable notify positive when user update self data' (!750) from 8031_notify_dataSaved into dev
Reviewed-on: verdnatura/salix-front#750 Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
commit
2d9dbbd23d
|
@ -13,12 +13,14 @@ import FetchData from 'components/FetchData.vue';
|
||||||
import { useClipboard } from 'src/composables/useClipboard';
|
import { useClipboard } from 'src/composables/useClipboard';
|
||||||
import { useRole } from 'src/composables/useRole';
|
import { useRole } from 'src/composables/useRole';
|
||||||
import VnAvatar from './ui/VnAvatar.vue';
|
import VnAvatar from './ui/VnAvatar.vue';
|
||||||
|
import useNotify from 'src/composables/useNotify';
|
||||||
|
|
||||||
const state = useState();
|
const state = useState();
|
||||||
const session = useSession();
|
const session = useSession();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { t, locale } = useI18n();
|
const { t, locale } = useI18n();
|
||||||
const { copyText } = useClipboard();
|
const { copyText } = useClipboard();
|
||||||
|
const { notify } = useNotify();
|
||||||
|
|
||||||
const userLocale = computed({
|
const userLocale = computed({
|
||||||
get() {
|
get() {
|
||||||
|
@ -53,6 +55,7 @@ const user = state.getUser();
|
||||||
const warehousesData = ref();
|
const warehousesData = ref();
|
||||||
const companiesData = ref();
|
const companiesData = ref();
|
||||||
const accountBankData = ref();
|
const accountBankData = ref();
|
||||||
|
const isEmployee = computed(() => useRole().isEmployee());
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
updatePreferences();
|
updatePreferences();
|
||||||
|
@ -70,18 +73,28 @@ function updatePreferences() {
|
||||||
|
|
||||||
async function saveDarkMode(value) {
|
async function saveDarkMode(value) {
|
||||||
const query = `/UserConfigs/${user.value.id}`;
|
const query = `/UserConfigs/${user.value.id}`;
|
||||||
|
try {
|
||||||
await axios.patch(query, {
|
await axios.patch(query, {
|
||||||
darkMode: value,
|
darkMode: value,
|
||||||
});
|
});
|
||||||
user.value.darkMode = value;
|
user.value.darkMode = value;
|
||||||
|
onDataSaved();
|
||||||
|
} catch (error) {
|
||||||
|
onDataError();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveLanguage(value) {
|
async function saveLanguage(value) {
|
||||||
const query = `/VnUsers/${user.value.id}`;
|
const query = `/VnUsers/${user.value.id}`;
|
||||||
|
try {
|
||||||
await axios.patch(query, {
|
await axios.patch(query, {
|
||||||
lang: value,
|
lang: value,
|
||||||
});
|
});
|
||||||
user.value.lang = value;
|
user.value.lang = value;
|
||||||
|
onDataSaved();
|
||||||
|
} catch (error) {
|
||||||
|
onDataError();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function logout() {
|
function logout() {
|
||||||
|
@ -97,11 +110,23 @@ function localUserData() {
|
||||||
state.setUser(user.value);
|
state.setUser(user.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveUserData(param, value) {
|
async function saveUserData(param, value) {
|
||||||
axios.post('UserConfigs/setUserConfig', { [param]: value });
|
try {
|
||||||
|
await axios.post('UserConfigs/setUserConfig', { [param]: value });
|
||||||
localUserData();
|
localUserData();
|
||||||
|
onDataSaved();
|
||||||
|
} catch (error) {
|
||||||
|
onDataError();
|
||||||
}
|
}
|
||||||
const isEmployee = computed(() => useRole().isEmployee());
|
}
|
||||||
|
|
||||||
|
const onDataSaved = () => {
|
||||||
|
notify('globals.dataSaved', 'positive');
|
||||||
|
};
|
||||||
|
|
||||||
|
const onDataError = () => {
|
||||||
|
notify('errors.updateUserConfig', 'negative');
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
|
@ -305,6 +305,7 @@ errors:
|
||||||
statusBadGateway: It seems that the server has fall down
|
statusBadGateway: It seems that the server has fall down
|
||||||
statusGatewayTimeout: Could not contact the server
|
statusGatewayTimeout: Could not contact the server
|
||||||
userConfig: Error fetching user config
|
userConfig: Error fetching user config
|
||||||
|
updateUserConfig: Error updating user config
|
||||||
tokenConfig: Error fetching token config
|
tokenConfig: Error fetching token config
|
||||||
writeRequest: The requested operation could not be completed
|
writeRequest: The requested operation could not be completed
|
||||||
login:
|
login:
|
||||||
|
|
|
@ -309,6 +309,7 @@ errors:
|
||||||
statusBadGateway: Parece ser que el servidor ha caído
|
statusBadGateway: Parece ser que el servidor ha caído
|
||||||
statusGatewayTimeout: No se ha podido contactar con el servidor
|
statusGatewayTimeout: No se ha podido contactar con el servidor
|
||||||
userConfig: Error al obtener configuración de usuario
|
userConfig: Error al obtener configuración de usuario
|
||||||
|
updateUserConfig: Error al actualizar la configuración de usuario
|
||||||
tokenConfig: Error al obtener configuración de token
|
tokenConfig: Error al obtener configuración de token
|
||||||
writeRequest: No se pudo completar la operación solicitada
|
writeRequest: No se pudo completar la operación solicitada
|
||||||
login:
|
login:
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
/// <reference types="cypress" />
|
||||||
|
describe('UserPanel', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
cy.viewport(1280, 720);
|
||||||
|
cy.login('developer');
|
||||||
|
cy.visit(`/#dashboard`);
|
||||||
|
cy.waitForElement('.q-page', 6000);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should notify when update user warehouse', () => {
|
||||||
|
const userWarehouse =
|
||||||
|
'.q-menu .q-gutter-xs > :nth-child(3) > .q-field > .q-field__inner > .q-field__control > .q-field__control-container > .q-field__native> .q-field__input';
|
||||||
|
|
||||||
|
// Abro el panel
|
||||||
|
cy.openUserPanel();
|
||||||
|
|
||||||
|
// Compruebo la opcion inicial
|
||||||
|
cy.get(userWarehouse).should('have.value', 'VNL').click();
|
||||||
|
|
||||||
|
// Actualizo la opción
|
||||||
|
getOption(3);
|
||||||
|
|
||||||
|
//Compruebo la notificación
|
||||||
|
cy.get('.q-notification').should('be.visible');
|
||||||
|
cy.get(userWarehouse).should('have.value', 'VNH');
|
||||||
|
|
||||||
|
//Restauro el valor
|
||||||
|
cy.get(userWarehouse).click();
|
||||||
|
getOption(2);
|
||||||
|
});
|
||||||
|
it('should notify when update user company', () => {
|
||||||
|
const userCompany =
|
||||||
|
'.q-menu .q-gutter-xs > :nth-child(2) > .q-field--float > .q-field__inner > .q-field__control > .q-field__control-container > .q-field__native> .q-field__input';
|
||||||
|
|
||||||
|
// Abro el panel
|
||||||
|
cy.openUserPanel();
|
||||||
|
|
||||||
|
// Compruebo la opcion inicial
|
||||||
|
cy.get(userCompany).should('have.value', 'Warehouse One').click();
|
||||||
|
|
||||||
|
//Actualizo la opción
|
||||||
|
getOption(2);
|
||||||
|
|
||||||
|
//Compruebo la notificación
|
||||||
|
cy.get('.q-notification').should('be.visible');
|
||||||
|
cy.get(userCompany).should('have.value', 'Warehouse Two');
|
||||||
|
|
||||||
|
//Restauro el valor
|
||||||
|
cy.get(userCompany).click();
|
||||||
|
getOption(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function getOption(index) {
|
||||||
|
cy.waitForElement('[role="listbox"]');
|
||||||
|
const option = `[role="listbox"] .q-item:nth-child(${index})`;
|
||||||
|
cy.get(option).click();
|
||||||
|
}
|
|
@ -248,3 +248,9 @@ Cypress.Commands.add('validateContent', (selector, expectedValue) => {
|
||||||
Cypress.Commands.add('openActionsDescriptor', () => {
|
Cypress.Commands.add('openActionsDescriptor', () => {
|
||||||
cy.get('.header > :nth-child(3) > .q-btn__content > .q-icon').click();
|
cy.get('.header > :nth-child(3) > .q-btn__content > .q-icon').click();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Cypress.Commands.add('openUserPanel', () => {
|
||||||
|
cy.get(
|
||||||
|
'.column > .q-avatar > .q-avatar__content > .q-img > .q-img__container > .q-img__image'
|
||||||
|
).click();
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in New Issue