From 7612260359f146db5e36b1fbcb065bb3da30e4a9 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 5 Aug 2024 13:36:27 +0200 Subject: [PATCH] refactor(customer_webAccess): FormModel --- src/components/FormModel.vue | 14 +- src/pages/Customer/Card/CustomerWebAccess.vue | 163 +++++------------- 2 files changed, 48 insertions(+), 129 deletions(-) diff --git a/src/components/FormModel.vue b/src/components/FormModel.vue index 115145f37..a0f6bf479 100644 --- a/src/components/FormModel.vue +++ b/src/components/FormModel.vue @@ -100,7 +100,6 @@ const isResetting = ref(false); const hasChanges = ref(!$props.observeFormChanges); const originalData = ref({}); const formData = computed(() => state.get(modelValue)); -const formUrl = computed(() => $props.url); const defaultButtons = computed(() => ({ save: { color: 'primary', @@ -148,11 +147,14 @@ if (!$props.url) (val) => updateAndEmit('onFetch', val) ); -watch(formUrl, async () => { - originalData.value = null; - reset(); - await fetch(); -}); +watch( + () => [$props.url, $props.filter], + async () => { + originalData.value = null; + reset(); + await fetch(); + } +); onBeforeRouteLeave((to, from, next) => { if (hasChanges.value && $props.observeFormChanges) diff --git a/src/pages/Customer/Card/CustomerWebAccess.vue b/src/pages/Customer/Card/CustomerWebAccess.vue index 33659dd77..8d025a365 100644 --- a/src/pages/Customer/Card/CustomerWebAccess.vue +++ b/src/pages/Customer/Card/CustomerWebAccess.vue @@ -2,164 +2,81 @@ import { computed, ref } from 'vue'; import { useI18n } from 'vue-i18n'; import { useRoute } from 'vue-router'; - import axios from 'axios'; import { useQuasar } from 'quasar'; -import { useValidator } from 'src/composables/useValidator'; -import useNotify from 'src/composables/useNotify'; -import { useStateStore } from 'stores/useStateStore'; - -import FetchData from 'components/FetchData.vue'; import VnInput from 'src/components/common/VnInput.vue'; import CustomerChangePassword from 'src/pages/Customer/components/CustomerChangePassword.vue'; +import FormModel from 'components/FormModel.vue'; -const { notify } = useNotify(); const { t } = useI18n(); -const { validate } = useValidator(); const quasar = useQuasar(); const route = useRoute(); -const stateStore = useStateStore(); - -const active = ref(false); const canChangePassword = ref(0); -const email = ref(null); -const isLoading = ref(false); -const name = ref(null); -const usersPreviewRef = ref(null); -const user = ref([]); -const dataChanges = computed(() => { - return ( - user.value.active !== active.value || - user.value.email !== email.value || - user.value.name !== name.value - ); +const filter = computed(() => { + return { + fields: ['active', 'email', 'name'], + where: { id: route.params.id }, + }; }); -const filter = { where: { id: `${route.params.id}` } }; - const showChangePasswordDialog = () => { quasar.dialog({ component: CustomerChangePassword, componentProps: { id: route.params.id, - promise: usersPreviewRef.value.fetch(), }, }); }; -const setInitialData = () => { - if (user.value.length) { - active.value = user.value[0].active; - email.value = user.value[0].email; - name.value = user.value[0].name; - } -}; - -const onSubmit = async () => { - isLoading.value = true; - - const payload = { - active: active.value, - email: email.value, - name: name.value, - }; - try { - await axios.patch(`Clients/${route.params.id}/updateUser`, payload); - notify('globals.dataSaved', 'positive'); - if (usersPreviewRef.value) usersPreviewRef.value.fetch(); - } catch (error) { - notify('errors.create', 'negative'); - } finally { - isLoading.value = false; - } -}; +async function hasCustomerRole() { + const { data } = await axios(`Clients/${route.params.id}/hasCustomerRole`); + canChangePassword.value = data; +}