From fa4a18fbbb34d7f9b8d241d8736bd9f3176e59f9 Mon Sep 17 00:00:00 2001 From: wbuezas Date: Fri, 7 Jun 2024 09:46:04 -0300 Subject: [PATCH] make account samba work again --- src/pages/Account/AccountLdap.vue | 2 +- src/pages/Account/AccountSamba.vue | 52 ++++++++++++++++++------------ 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/pages/Account/AccountLdap.vue b/src/pages/Account/AccountLdap.vue index 411c1e702..77c4d89f8 100644 --- a/src/pages/Account/AccountLdap.vue +++ b/src/pages/Account/AccountLdap.vue @@ -43,7 +43,7 @@ const hasData = computed({ const initialDataLoaded = ref(false); const formUrlCreate = ref(null); -const formUrlUpdate = ref(`LdapConfigs/${1}`); +const formUrlUpdate = ref(null); const formCustomFn = ref(null); const onTestConection = async () => { diff --git a/src/pages/Account/AccountSamba.vue b/src/pages/Account/AccountSamba.vue index 53ace6029..25428a674 100644 --- a/src/pages/Account/AccountSamba.vue +++ b/src/pages/Account/AccountSamba.vue @@ -7,13 +7,20 @@ 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('AccountSamba'); + const formModel = ref(null); + +const URL_UPDATE = `SambaConfigs/${1}`; +const URL_CREATE = `SambaConfigs`; + const DEFAULT_DATA = { id: 1, hasData: false, @@ -33,15 +40,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(`SambaConfigs/${1}`); -const customFn = ref(null); +const formUrlCreate = ref(null); +const formUrlUpdate = ref(null); +const formCustomFn = ref(null); const onTestConection = async () => { try { @@ -52,22 +59,25 @@ const onTestConection = async () => { } }; -const getInitialLdapConfig = async () => { +const getInitialSambaConfig = 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; - console.error('Error fetching initial LDAP config', error); + arrayData.destroy(); + console.error('Error fetching initial Samba config', error); return null; } finally { - if (hasData.value) urlCreate.value = null; - else { - urlUpdate.value = null; - urlCreate.value = `SambaConfigs`; + if (hasData.value) { + formUrlUpdate.value = URL_UPDATE; + formUrlCreate.value = null; + } else { + formUrlUpdate.value = null; + formUrlCreate.value = URL_CREATE; } initialDataLoaded.value = true; } @@ -75,7 +85,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'); @@ -84,7 +94,7 @@ const deleteMailForward = async () => { } }; -onMounted(async () => await getInitialLdapConfig()); +onMounted(async () => await getInitialSambaConfig());