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; +}