From 1e67a0feca408375ecf591a734ff33912971c88f Mon Sep 17 00:00:00 2001 From: wbuezas Date: Fri, 7 Jun 2024 09:35:36 -0300 Subject: [PATCH] Make AccountLdap work again --- src/pages/Account/AccountLdap.vue | 37 +++++++++++++++++++------------ 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/pages/Account/AccountLdap.vue b/src/pages/Account/AccountLdap.vue index 637788314..411c1e702 100644 --- a/src/pages/Account/AccountLdap.vue +++ b/src/pages/Account/AccountLdap.vue @@ -7,12 +7,17 @@ import VnRow from 'components/ui/VnRow.vue'; import VnInput from 'src/components/common/VnInput.vue'; import VnSubToolbar from 'src/components/ui/VnSubToolbar.vue'; +import { useArrayData } from 'src/composables/useArrayData'; import useNotify from 'src/composables/useNotify.js'; import axios from 'axios'; const { t } = useI18n(); const { notify } = useNotify(); +const arrayData = useArrayData('AccountLdap'); + +const URL_UPDATE = `LdapConfigs/${1}`; +const URL_CREATE = `LdapConfigs`; const DEFAULT_DATA = { id: 1, hasData: false, @@ -31,15 +36,15 @@ const hasData = computed({ get: () => initialData.value.hasData, set: (val) => { initialData.value.hasData = val; - if (!val) customFn.value = deleteMailForward; - else customFn.value = null; + if (!val) formCustomFn.value = deleteMailForward; + else formCustomFn.value = null; }, }); const initialDataLoaded = ref(false); -const urlCreate = ref(null); -const urlUpdate = ref(`LdapConfigs/${1}`); -const customFn = ref(null); +const formUrlCreate = ref(null); +const formUrlUpdate = ref(`LdapConfigs/${1}`); +const formCustomFn = ref(null); const onTestConection = async () => { try { @@ -53,19 +58,23 @@ const onTestConection = async () => { const getInitialLdapConfig = async () => { try { initialDataLoaded.value = false; - const { data } = await axios.get(urlUpdate.value); + const { data } = await axios.get(URL_UPDATE); initialData.value = data; hasData.value = true; return data; } catch (error) { hasData.value = false; + arrayData.destroy(); console.error('Error fetching initial LDAP config', error); return null; } finally { - if (hasData.value) urlCreate.value = null; - else { - urlUpdate.value = null; - urlCreate.value = `LdapConfigs`; + // Si asignamos un valor a urlUpdate, debemos asignar null a urlCreate y viceversa, ya puede causar problemas en formModel + if (hasData.value) { + formUrlUpdate.value = URL_UPDATE; + formUrlCreate.value = null; + } else { + formUrlUpdate.value = null; + formUrlCreate.value = URL_CREATE; } initialDataLoaded.value = true; } @@ -73,7 +82,7 @@ const getInitialLdapConfig = async () => { const deleteMailForward = async () => { try { - await axios.delete(urlUpdate.value); + await axios.delete(URL_UPDATE); initialData.value = { ...DEFAULT_DATA }; hasData.value = false; notify(t('globals.dataSaved'), 'positive'); @@ -92,9 +101,9 @@ onMounted(async () => await getInitialLdapConfig()); :key="initialDataLoaded" model="AccountLdap" :form-initial-data="initialData" - :url-create="urlCreate" - :url-update="urlUpdate" - :save-fn="customFn" + :url-create="formUrlCreate" + :url-update="formUrlUpdate" + :save-fn="formCustomFn" auto-load @on-data-saved="getInitialLdapConfig()" >