From f048a1c820bf71410f446156b56b0e46e86c7989 Mon Sep 17 00:00:00 2001 From: wbuezas Date: Mon, 26 Feb 2024 13:22:25 -0300 Subject: [PATCH] Add reactivity to supplier descriptor icons --- src/components/FormModel.vue | 11 ++++++++++- src/components/ui/CardDescriptor.vue | 4 ++++ src/pages/Supplier/Card/SupplierBasicData.vue | 1 + src/pages/Supplier/Card/SupplierBillingData.vue | 1 + src/pages/Supplier/Card/SupplierDescriptor.vue | 14 +++++++++----- src/pages/Supplier/Card/SupplierFiscalData.vue | 1 + 6 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/components/FormModel.vue b/src/components/FormModel.vue index 9fd16088c..50cdf9ee3 100644 --- a/src/components/FormModel.vue +++ b/src/components/FormModel.vue @@ -59,6 +59,10 @@ const $props = defineProps({ type: Function, default: null, }, + clearStoreOnUnmount: { + type: Boolean, + default: true, + }, }); const emit = defineEmits(['onFetch', 'onDataSaved']); @@ -91,7 +95,12 @@ onMounted(async () => { }); onUnmounted(() => { - state.unset($props.model); + // Restauramos los datos originales en el store si se realizaron cambios en el formulario pero no se guardaron, evitando modificaciones errĂ³neas. + if (hasChanges.value) { + state.set($props.model, originalData.value); + return; + } + if ($props.clearStoreOnUnmount) state.unset($props.model); }); const isLoading = ref(false); diff --git a/src/components/ui/CardDescriptor.vue b/src/components/ui/CardDescriptor.vue index 345c8d088..92f95fd2c 100644 --- a/src/components/ui/CardDescriptor.vue +++ b/src/components/ui/CardDescriptor.vue @@ -4,6 +4,7 @@ import { useI18n } from 'vue-i18n'; import SkeletonDescriptor from 'components/ui/SkeletonDescriptor.vue'; import { useArrayData } from 'composables/useArrayData'; import { useSummaryDialog } from 'src/composables/useSummaryDialog'; +import { useState } from 'src/composables/useState'; const $props = defineProps({ url: { @@ -35,6 +36,8 @@ const $props = defineProps({ default: null, }, }); + +const state = useState(); const slots = useSlots(); const { t } = useI18n(); const { viewSummary } = useSummaryDialog(); @@ -64,6 +67,7 @@ async function getData() { isLoading.value = true; try { const { data } = await arrayData.fetch({ append: false, updateRouter: false }); + state.set($props.dataKey, data); emit('onFetch', data); } finally { isLoading.value = false; diff --git a/src/pages/Supplier/Card/SupplierBasicData.vue b/src/pages/Supplier/Card/SupplierBasicData.vue index bc50deb9b..01741dd77 100644 --- a/src/pages/Supplier/Card/SupplierBasicData.vue +++ b/src/pages/Supplier/Card/SupplierBasicData.vue @@ -26,6 +26,7 @@ const workersOptions = ref([]); :url-update="`Suppliers/${route.params.id}`" model="supplier" auto-load + :clear-store-on-unmount="false" >