From 271e33a999d54cf06788aa41dce6164658aaf6ab Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 20 Sep 2024 11:57:15 +0200 Subject: [PATCH 1/5] feat: formatLocation when field is null --- src/components/common/VnLocation.vue | 40 +++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/src/components/common/VnLocation.vue b/src/components/common/VnLocation.vue index b6cbfbafd3..c3b07c72c1 100644 --- a/src/components/common/VnLocation.vue +++ b/src/components/common/VnLocation.vue @@ -12,14 +12,46 @@ const props = defineProps({ default: null, }, }); +const formatLocation = (obj, properties) => { + // Crear un array con las propiedades del objeto + const parts = properties.map((prop) => { + if (typeof prop === 'string') { + return obj[prop]; + } else if (typeof prop === 'function') { + return prop(obj); + } + return null; + }); + + // Filtrar los valores que no son null o undefined + const filteredParts = parts.filter( + (part) => part !== null && part !== undefined && part !== '' + ); + + // Unir los valores filtrados con el formato deseado + return filteredParts.join(', '); +}; + +const locationProperties = [ + 'postcode', + (obj) => + obj.city + ? `${obj.city}${obj.province?.name ? `(${obj.province.name})` : ''}` + : null, + (obj) => obj.country?.name, +]; const modelValue = ref( - props.location - ? `${props.location?.postcode} - ${props.location?.city}(${props.location?.province?.name}), ${props.location?.country?.name}` - : null + props.location ? formatLocation(props.location, locationProperties) : null ); function showLabel(data) { - return `${data.code} - ${data.town}(${data.province}), ${data.country}`; + const dataProperties = [ + 'code', + (obj) => (obj.town ? `${obj.town}(${obj.province})` : null), + 'country', + ]; + return formatLocation(data, dataProperties); } + const handleModelValue = (data) => { emit('update:model-value', data); }; From f06723a9192a158bbdff8fb160e664d994692f68 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 23 Sep 2024 11:39:10 +0200 Subject: [PATCH 2/5] test: VnLocation --- .../integration/vnComponent/vnLocation.spec.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/test/cypress/integration/vnComponent/vnLocation.spec.js b/test/cypress/integration/vnComponent/vnLocation.spec.js index 3533a3c1f0..15ab53d178 100644 --- a/test/cypress/integration/vnComponent/vnLocation.spec.js +++ b/test/cypress/integration/vnComponent/vnLocation.spec.js @@ -36,20 +36,23 @@ describe('VnLocation', () => { }); it('Fin by postalCode', () => { const postCode = '46600'; + const postCodeLabel = '46600, Valencia(Province one), España'; const firstOption = '[role="listbox"] .q-item:nth-child(1)'; cy.get(inputLocation).click(); cy.get(inputLocation).clear(); cy.get(inputLocation).type(postCode); - cy.get(locationOptions).should('have.length.at.least', 2); + cy.get(locationOptions) + .get(':nth-child(1)') + .should('have.length.at.least', 2); + cy.get( + firstOption.concat(' > .q-item__section > .q-item__label--caption') + ).should('have.text', postCodeLabel); cy.get(firstOption).click(); cy.get('.q-btn-group > .q-btn--standard > .q-btn__content > .q-icon').click(); cy.reload(); cy.waitForElement('.q-form'); - cy.get(inputLocation).should( - 'have.value', - '46600 - Valencia(Province one), España' - ); + cy.get(inputLocation).should('have.value', postCodeLabel); }); it('Create postCode', () => { From 013a76cbce074ef727b371ce949bbf79b8f75f7e Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 23 Sep 2024 11:48:00 +0200 Subject: [PATCH 3/5] test: VnLocation --- src/components/common/VnLocation.vue | 3 --- test/cypress/integration/vnComponent/vnLocation.spec.js | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/components/common/VnLocation.vue b/src/components/common/VnLocation.vue index c3b07c72c1..633d32b85d 100644 --- a/src/components/common/VnLocation.vue +++ b/src/components/common/VnLocation.vue @@ -13,7 +13,6 @@ const props = defineProps({ }, }); const formatLocation = (obj, properties) => { - // Crear un array con las propiedades del objeto const parts = properties.map((prop) => { if (typeof prop === 'string') { return obj[prop]; @@ -23,12 +22,10 @@ const formatLocation = (obj, properties) => { return null; }); - // Filtrar los valores que no son null o undefined const filteredParts = parts.filter( (part) => part !== null && part !== undefined && part !== '' ); - // Unir los valores filtrados con el formato deseado return filteredParts.join(', '); }; diff --git a/test/cypress/integration/vnComponent/vnLocation.spec.js b/test/cypress/integration/vnComponent/vnLocation.spec.js index 15ab53d178..1872d3591c 100644 --- a/test/cypress/integration/vnComponent/vnLocation.spec.js +++ b/test/cypress/integration/vnComponent/vnLocation.spec.js @@ -34,7 +34,7 @@ describe('VnLocation', () => { cy.visit('/#/supplier/567/fiscal-data', { timeout: 7000 }); cy.waitForElement('.q-form'); }); - it('Fin by postalCode', () => { + it('Find by postalCode', () => { const postCode = '46600'; const postCodeLabel = '46600, Valencia(Province one), España'; const firstOption = '[role="listbox"] .q-item:nth-child(1)'; From a5c6d628ca9eb4378cd548e4a4d9b79bc554592e Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 23 Sep 2024 18:48:58 +0000 Subject: [PATCH 4/5] feat: enable notify positive when user update self data --- src/components/UserPanel.vue | 43 +++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/src/components/UserPanel.vue b/src/components/UserPanel.vue index 98334460a7..5276f9e20b 100644 --- a/src/components/UserPanel.vue +++ b/src/components/UserPanel.vue @@ -13,12 +13,14 @@ import FetchData from 'components/FetchData.vue'; import { useClipboard } from 'src/composables/useClipboard'; import { useRole } from 'src/composables/useRole'; import VnAvatar from './ui/VnAvatar.vue'; +import useNotify from 'src/composables/useNotify'; const state = useState(); const session = useSession(); const router = useRouter(); const { t, locale } = useI18n(); const { copyText } = useClipboard(); +const { notify } = useNotify(); const userLocale = computed({ get() { @@ -53,6 +55,7 @@ const user = state.getUser(); const warehousesData = ref(); const companiesData = ref(); const accountBankData = ref(); +const isEmployee = computed(() => useRole().isEmployee()); onMounted(async () => { updatePreferences(); @@ -70,18 +73,28 @@ function updatePreferences() { async function saveDarkMode(value) { const query = `/UserConfigs/${user.value.id}`; - await axios.patch(query, { - darkMode: value, - }); - user.value.darkMode = value; + try { + await axios.patch(query, { + darkMode: value, + }); + user.value.darkMode = value; + notify('globals.dataSaved', 'positive'); + } catch (error) { + console.error(error); + } } async function saveLanguage(value) { const query = `/VnUsers/${user.value.id}`; - await axios.patch(query, { - lang: value, - }); - user.value.lang = value; + try { + await axios.patch(query, { + lang: value, + }); + user.value.lang = value; + notify('globals.dataSaved', 'positive'); + } catch (error) { + console.error(error); + } } function logout() { @@ -98,10 +111,18 @@ function localUserData() { } function saveUserData(param, value) { - axios.post('UserConfigs/setUserConfig', { [param]: value }); - localUserData(); + try { + axios.post('UserConfigs/setUserConfig', { [param]: value }); + localUserData(); + notify('globals.dataSaved', 'positive'); + } catch (error) { + console.error(error); + } } -const isEmployee = computed(() => useRole().isEmployee()); + +const onDataSaved = () => { + notify('globals.dataSaved', 'positive'); +};