From 9179e13dcda0eeaeb5ac17243f58576bb882c04b Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 29 Jul 2024 15:03:21 +0200 Subject: [PATCH 1/2] fix: vnLocation --- src/boot/axios.js | 9 ++ src/components/CreateNewCityForm.vue | 14 +-- src/components/CreateNewPostcodeForm.vue | 71 +++++++----- src/components/CreateNewProvinceForm.vue | 6 +- src/components/VnSelectProvince.vue | 57 ++++++++++ src/components/common/VnLocation.vue | 106 ++---------------- src/components/common/VnSelect.vue | 25 ++++- src/components/common/VnSelectDialog.vue | 28 ++--- .../Customer/Card/CustomerFiscalData.vue | 2 - src/pages/Customer/CustomerCreate.vue | 2 - src/pages/Customer/CustomerList.vue | 2 - .../components/CustomerAddressCreate.vue | 2 - .../components/CustomerAddressEdit.vue | 2 - .../Supplier/Card/SupplierAddressesCreate.vue | 2 - .../Supplier/Card/SupplierFiscalData.vue | 2 - src/pages/Worker/WorkerCreate.vue | 2 - .../vnComponent/vnLocation.spec.js | 82 ++++++++------ 17 files changed, 192 insertions(+), 222 deletions(-) create mode 100644 src/components/VnSelectProvince.vue diff --git a/src/boot/axios.js b/src/boot/axios.js index fa8a08003..9b32275bd 100644 --- a/src/boot/axios.js +++ b/src/boot/axios.js @@ -43,6 +43,15 @@ const onResponseError = (error) => { } switch (response?.status) { + case 422: + if (error.name == 'ValidationError') + message += + ' "' + + responseError.details.context + + '.' + + Object.keys(responseError.details.codes).join(',') + + '"'; + break; case 500: message = 'errors.statusInternalServerError'; break; diff --git a/src/components/CreateNewCityForm.vue b/src/components/CreateNewCityForm.vue index 45fa61dff..3861e3253 100644 --- a/src/components/CreateNewCityForm.vue +++ b/src/components/CreateNewCityForm.vue @@ -4,8 +4,8 @@ import { useI18n } from 'vue-i18n'; import FetchData from 'components/FetchData.vue'; import VnRow from 'components/ui/VnRow.vue'; -import VnSelect from 'src/components/common/VnSelect.vue'; -import VnInput from 'src/components/common/VnInput.vue'; +import VnSelectProvince from 'components/VnSelectProvince.vue'; +import VnInput from 'components/common/VnInput.vue'; import FormModelPopup from './FormModelPopup.vue'; const emit = defineEmits(['onDataSaved']); @@ -45,15 +45,7 @@ const onDataSaved = (dataSaved) => { v-model="data.name" :rules="validate('city.name')" /> - + diff --git a/src/components/CreateNewPostcodeForm.vue b/src/components/CreateNewPostcodeForm.vue index 25a61a0ca..b1b8852d3 100644 --- a/src/components/CreateNewPostcodeForm.vue +++ b/src/components/CreateNewPostcodeForm.vue @@ -5,9 +5,9 @@ import { useI18n } from 'vue-i18n'; import FetchData from 'components/FetchData.vue'; import VnRow from 'components/ui/VnRow.vue'; import VnSelect from 'src/components/common/VnSelect.vue'; +import VnSelectProvince from 'src/components/VnSelectProvince.vue'; import VnInput from 'src/components/common/VnInput.vue'; import CreateNewCityForm from './CreateNewCityForm.vue'; -import CreateNewProvinceForm from './CreateNewProvinceForm.vue'; import VnSelectDialog from 'components/common/VnSelectDialog.vue'; import FormModelPopup from './FormModelPopup.vue'; @@ -28,7 +28,7 @@ const countriesOptions = ref([]); const provincesOptions = ref([]); const townsLocationOptions = ref([]); -const onDataSaved = (formData) => { +function onDataSaved(formData) { const newPostcode = { ...formData, }; @@ -43,25 +43,34 @@ const onDataSaved = (formData) => { const countryObject = countriesOptions.value.find( ({ id }) => id === formData.countryFk ); - newPostcode.country = countryObject?.country; + newPostcode.country = countryObject?.name; emit('onDataSaved', newPostcode); -}; +} -const onCityCreated = async ({ name, provinceFk }, formData) => { +async function onCityCreated({ name, provinceFk }, formData) { await townsFetchDataRef.value.fetch(); + await provincesFetchDataRef.value.fetch(); formData.townFk = townsLocationOptions.value.find((town) => town.name === name).id; formData.provinceFk = provinceFk; formData.countryFk = provincesOptions.value.find( (province) => province.id === provinceFk ).countryFk; -}; +} -const onProvinceCreated = async ({ name }, formData) => { - await provincesFetchDataRef.value.fetch(); - formData.provinceFk = provincesOptions.value.find( - (province) => province.name === name - ).id; -}; +function setTown(id, data) { + const newTown = townsLocationOptions.value.find((town) => town.id == id); + if (!newTown) return; + + data.provinceFk = newTown.provinceFk; + data.countryFk = newTown.province.countryFk; +} + +function setProvince(id, data) { + const newProvince = provincesOptions.value.find((province) => province.id == id); + if (!newProvince) return; + + data.countryFk = newProvince.countryFk; +}