diff --git a/src/components/CrudModel.vue b/src/components/CrudModel.vue index 19e990862..1234ce123 100644 --- a/src/components/CrudModel.vue +++ b/src/components/CrudModel.vue @@ -10,6 +10,7 @@ import VnPaginate from 'components/ui/VnPaginate.vue'; import VnConfirm from 'components/ui/VnConfirm.vue'; import SkeletonTable from 'components/ui/SkeletonTable.vue'; import { tMobile } from 'src/composables/tMobile'; +import getDifferences from 'src/filters/getDifferences'; const { push } = useRouter(); const quasar = useQuasar(); @@ -268,28 +269,6 @@ function getChanges() { return changes; } -function getDifferences(obj1, obj2) { - let diff = {}; - delete obj1.$index; - delete obj2.$index; - - for (let key in obj1) { - if (obj2[key] && JSON.stringify(obj1[key]) !== JSON.stringify(obj2[key])) { - diff[key] = obj2[key]; - } - } - for (let key in obj2) { - if ( - obj1[key] === undefined || - JSON.stringify(obj1[key]) !== JSON.stringify(obj2[key]) - ) { - diff[key] = obj2[key]; - } - } - - return diff; -} - function isEmpty(obj) { if (obj == null) return true; if (obj === undefined) return true; diff --git a/src/components/FormModel.vue b/src/components/FormModel.vue index c668769e5..4504ea6ad 100644 --- a/src/components/FormModel.vue +++ b/src/components/FormModel.vue @@ -106,6 +106,7 @@ const originalData = ref({}); const formData = computed(() => state.get(modelValue)); const defaultButtons = computed(() => ({ save: { + dataCy: 'saveDefaultBtn', color: 'primary', icon: 'save', label: 'globals.save', @@ -113,6 +114,7 @@ const defaultButtons = computed(() => ({ type: 'submit', }, reset: { + dataCy: 'resetDefaultBtn', color: 'primary', icon: 'restart_alt', label: 'globals.reset', @@ -203,7 +205,9 @@ async function save() { isLoading.value = true; try { formData.value = trimData(formData.value); - const body = $props.mapper ? $props.mapper(formData.value) : formData.value; + const body = $props.mapper + ? $props.mapper(formData.value, originalData.value) + : formData.value; const method = $props.urlCreate ? 'post' : 'patch'; const url = $props.urlCreate || $props.urlUpdate || $props.url || arrayData.store.url; @@ -317,6 +321,7 @@ defineExpose({ :title="t(defaultButtons.reset.label)" /> { @click="insert" class="q-mb-xs" dense + data-cy="saveNote" /> diff --git a/src/components/ui/VnPaginate.vue b/src/components/ui/VnPaginate.vue index f3f6d64f1..3649ba8f5 100644 --- a/src/components/ui/VnPaginate.vue +++ b/src/components/ui/VnPaginate.vue @@ -133,7 +133,7 @@ const addFilter = async (filter, params) => { async function fetch(params) { useArrayData(props.dataKey, params); arrayData.reset(['filter.skip', 'skip', 'page']); - await arrayData.fetch({ append: false }); + await arrayData.fetch({ append: false, updateRouter: mounted.value }); return emitStoreData(); } diff --git a/src/filters/getDifferences.js b/src/filters/getDifferences.js new file mode 100644 index 000000000..3e1061aba --- /dev/null +++ b/src/filters/getDifferences.js @@ -0,0 +1,21 @@ +export default function getDifferences(obj1, obj2) { + let diff = {}; + delete obj1.$index; + delete obj2.$index; + + for (let key in obj1) { + if (obj2[key] && JSON.stringify(obj1[key]) !== JSON.stringify(obj2[key])) { + diff[key] = obj2[key]; + } + } + for (let key in obj2) { + if ( + obj1[key] === undefined || + JSON.stringify(obj1[key]) !== JSON.stringify(obj2[key]) + ) { + diff[key] = obj2[key]; + } + } + + return diff; +} diff --git a/src/filters/getUpdatedValues.js b/src/filters/getUpdatedValues.js new file mode 100644 index 000000000..5b9622fd0 --- /dev/null +++ b/src/filters/getUpdatedValues.js @@ -0,0 +1,6 @@ +export default function getUpdatedValues(keys, formData) { + return keys.reduce((acc, key) => { + acc[key] = formData[key]; + return acc; + }, {}); +} diff --git a/src/filters/index.js b/src/filters/index.js index 1f7ac77dd..a92d2eb07 100644 --- a/src/filters/index.js +++ b/src/filters/index.js @@ -11,11 +11,15 @@ import dashIfEmpty from './dashIfEmpty'; import dateRange from './dateRange'; import toHour from './toHour'; import dashOrCurrency from './dashOrCurrency'; +import getDifferences from './getDifferences'; +import getUpdatedValues from './getUpdatedValues'; import getParamWhere from './getParamWhere'; import parsePhone from './parsePhone'; import isDialogOpened from './isDialogOpened'; export { + getUpdatedValues, + getDifferences, isDialogOpened, parsePhone, toLowerCase, diff --git a/src/pages/Customer/Card/CustomerAddress.vue b/src/pages/Customer/Card/CustomerAddress.vue index 5e896c84f..657cc7ae7 100644 --- a/src/pages/Customer/Card/CustomerAddress.vue +++ b/src/pages/Customer/Card/CustomerAddress.vue @@ -2,6 +2,7 @@ import { onBeforeMount, ref, watch } from 'vue'; import { useI18n } from 'vue-i18n'; import { useRoute, useRouter } from 'vue-router'; +import FetchData from 'components/FetchData.vue'; import axios from 'axios'; @@ -52,7 +53,6 @@ const addressFilter = { onBeforeMount(() => { const { id } = route.params; - getAddressesData(id); getClientData(id); }); @@ -60,23 +60,10 @@ watch( () => route.params.id, (newValue) => { if (!newValue) return; - getAddressesData(newValue); getClientData(newValue); } ); -const getAddressesData = async (id) => { - try { - const { data } = await axios.get(`Clients/${id}/addresses`, { - params: { filter: JSON.stringify(addressFilter) }, - }); - addresses.value = data; - sortAddresses(); - } catch (error) { - return error; - } -}; - const getClientData = async (id) => { try { const { data } = await axios.get(`Clients/${id}`); @@ -101,9 +88,9 @@ const setDefault = (address) => { }); }; -const sortAddresses = () => { - if (!client.value || !addresses.value) return; - addresses.value = addresses.value.sort((a, b) => { +const sortAddresses = (data) => { + if (!client.value || !data) return; + addresses.value = data.sort((a, b) => { return isDefaultAddress(b) - isDefaultAddress(a); }); }; @@ -124,8 +111,17 @@ const toCustomerAddressEdit = (addressId) => {