diff --git a/src/components/CreateNewCityForm.vue b/src/components/CreateNewCityForm.vue index ee842e86f..7326ea7a5 100644 --- a/src/components/CreateNewCityForm.vue +++ b/src/components/CreateNewCityForm.vue @@ -19,8 +19,8 @@ const cityFormData = reactive({ const provincesOptions = ref([]); -const onDataSaved = () => { - emit('onDataSaved'); +const onDataSaved = (dataSaved) => { + emit('onDataSaved', dataSaved); }; diff --git a/src/components/CreateNewPostcodeForm.vue b/src/components/CreateNewPostcodeForm.vue index 40efa0789..ccffb2ec2 100644 --- a/src/components/CreateNewPostcodeForm.vue +++ b/src/components/CreateNewPostcodeForm.vue @@ -32,12 +32,20 @@ const onDataSaved = (dataSaved) => { emit('onDataSaved', dataSaved); }; -const onCityCreated = async () => { +const onCityCreated = async ({ name, provinceFk }, formData) => { await townsFetchDataRef.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 () => { +const onProvinceCreated = async ({ name }, formData) => { await provincesFetchDataRef.value.fetch(); + formData.provinceFk = provincesOptions.value.find( + (province) => province.name === name + ).id; }; @@ -88,7 +96,9 @@ const onProvinceCreated = async () => { :roles-allowed-to-create="['deliveryAssistant']" > @@ -107,7 +117,7 @@ const onProvinceCreated = async () => { > diff --git a/src/components/CreateNewProvinceForm.vue b/src/components/CreateNewProvinceForm.vue index 0f88952ea..b972db2c9 100644 --- a/src/components/CreateNewProvinceForm.vue +++ b/src/components/CreateNewProvinceForm.vue @@ -19,8 +19,8 @@ const provinceFormData = reactive({ const autonomiesOptions = ref([]); -const onDataSaved = () => { - emit('onDataSaved'); +const onDataSaved = (dataSaved) => { + emit('onDataSaved', dataSaved); }; diff --git a/src/pages/Customer/Card/CustomerFiscalData.vue b/src/pages/Customer/Card/CustomerFiscalData.vue index ab778670a..0edcc3c07 100644 --- a/src/pages/Customer/Card/CustomerFiscalData.vue +++ b/src/pages/Customer/Card/CustomerFiscalData.vue @@ -14,16 +14,22 @@ import VnSelectCreate from 'src/components/common/VnSelectCreate.vue'; const { t } = useI18n(); const route = useRoute(); +const townsFetchDataRef = ref(null); +const postcodeFetchDataRef = ref(null); const typesTaxes = ref([]); const typesTransactions = ref([]); -const postcodeFetchDataRef = ref(null); const citiesLocationOptions = ref([]); const provincesLocationOptions = ref([]); const countriesOptions = ref([]); const postcodesOptions = ref([]); -const onPostcodeCreated = async () => { - postcodeFetchDataRef.value.fetch(); +const onPostcodeCreated = async ({ code, provinceFk, townFk, countryFk }, formData) => { + await postcodeFetchDataRef.value.fetch(); + await townsFetchDataRef.value.fetch(); + formData.postcode = code; + formData.provinceFk = provinceFk; + formData.city = citiesLocationOptions.value.find((town) => town.id === townFk).name; + formData.countryFk = countryFk; }; @@ -35,6 +41,7 @@ const onPostcodeCreated = async () => { url="SageTransactionTypes" /> { auto-load url="Countries" /> - + { >