From 9d3b771b55da4ff0f2d217d2e168c3422669fc9d Mon Sep 17 00:00:00 2001 From: Thijn Date: Mon, 30 Dec 2024 14:33:56 +0100 Subject: [PATCH] fixed close contactmoment on edit --- .../contactMomenten/ContactMomentenForm.vue | 24 ++++++++++++++----- src/store/modules/contactmoment.ts | 11 +++++++-- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/modals/contactMomenten/ContactMomentenForm.vue b/src/modals/contactMomenten/ContactMomentenForm.vue index 6edc158..60b36d2 100644 --- a/src/modals/contactMomenten/ContactMomentenForm.vue +++ b/src/modals/contactMomenten/ContactMomentenForm.vue @@ -517,7 +517,7 @@ import { contactMomentStore, navigationStore, taakStore, zaakStore } from '../.. Zaak starten - @@ -565,9 +565,10 @@ import { contactMomentStore, navigationStore, taakStore, zaakStore } from '../.. // Components import { BTabs, BTab } from 'bootstrap-vue' import { NcButton, NcActions, NcLoadingIcon, NcDialog, NcTextArea, NcNoteCard, NcListItem, NcActionButton, NcEmptyContent } from '@nextcloud/vue' +import { generateUrl } from '@nextcloud/router' import _ from 'lodash' - import getValidISOstring from '../../services/getValidISOstring.js' + // Forms import SearchKlantModal from '../../modals/klanten/SearchKlantModal.vue' import EditTaak from '../../modals/taken/EditTaak.vue' @@ -588,7 +589,6 @@ import Minus from 'vue-material-design-icons/Minus.vue' import ProgressClose from 'vue-material-design-icons/ProgressClose.vue' import Eye from 'vue-material-design-icons/Eye.vue' import router from '../../router/router.ts' -import { generateUrl } from '@nextcloud/router'; export default { name: 'ContactMomentenForm', @@ -806,7 +806,7 @@ export default { startDate: contactMomentCopy.startDate ?? new Date().toISOString(), status: contactMomentCopy.status === 'gesloten' ? 'gesloten' : 'open', contactmoment: contactMomentCopy.selectedKlantContactMoment, - }) + }, { redirect: !this.dashboardWidget }) .then((response) => { this.contactMoment.addedTaken.forEach(taak => { fetch(`/index.php/apps/zaakafhandelapp/api/taken/${taak}`, { @@ -940,7 +940,18 @@ export default { }, async closeContactMoment(id) { - const { data } = await contactMomentStore.getContactMoment(id) + let data + + if (this.isEdit) { + data = { + ...this.contactMoment, + ...this.contactMomenten[this.selectedContactMoment], + } + } else if (this.isView) { + data = (await contactMomentStore.getContactMoment(id))?.data + } else { + return + } if (data?.status === 'gesloten') { console.info('Contactmoment is already closed') @@ -951,13 +962,14 @@ export default { status: 'gesloten', }) - contactMomentStore.saveContactMoment(newContactMoment) + contactMomentStore.saveContactMoment(newContactMoment, { redirect: !this.dashboardWidget }) .then(({ response }) => { if (response.ok) { this.closeModal() this.$emit('save-success') } }) + }, async fetchKlantData(id) { diff --git a/src/store/modules/contactmoment.ts b/src/store/modules/contactmoment.ts index 6ae2b14..73e3543 100644 --- a/src/store/modules/contactmoment.ts +++ b/src/store/modules/contactmoment.ts @@ -134,10 +134,15 @@ export const useContactMomentStore = defineStore('contactmomenten', { * Otherwise, it will be updated. * * @param contactMomentItem - The contact moment item to save. + * @param options - The options to save the contact moment. + * @param options.redirect - Whether to redirect to the contact moment after saving. (default: `true`) * @throws If there is no contact moment item to save or if the HTTP request fails. * @return {Promise<{ response: Response, data: TContactMoment, entity: ContactMoment }>} The response, raw data, and entity. */ - async saveContactMoment(contactMomentItem: TContactMoment | ContactMoment): Promise<{ response: Response, data: TContactMoment, entity: ContactMoment }> { + async saveContactMoment( + contactMomentItem: TContactMoment | ContactMoment, + options: { redirect?: boolean } = { redirect: true }, + ): Promise<{ response: Response, data: TContactMoment, entity: ContactMoment }> { if (!contactMomentItem) { throw new Error('No contactmoment item to save') } @@ -169,7 +174,9 @@ export const useContactMomentStore = defineStore('contactmomenten', { this.setContactMomentItem(data) this.refreshContactMomentenList() - router.push({ name: 'dynamic-view', params: { view: 'contactmomenten', id: entity.id } }) + if (options.redirect) { + router.push({ name: 'dynamic-view', params: { view: 'contactmomenten', id: entity.id } }) + } return { response, data, entity } },