From c430abc33ac1f5379c0fd5aa00e952410a2fafaf Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Sat, 15 Jun 2024 12:27:00 +0530 Subject: [PATCH] fix: handle rendering of contacts section --- .../src/components/Settings/FieldsLayout.vue | 1 + frontend/src/pages/Deal.vue | 60 +++++++++---------- 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/frontend/src/components/Settings/FieldsLayout.vue b/frontend/src/components/Settings/FieldsLayout.vue index b53642c2..d43fbc93 100644 --- a/frontend/src/components/Settings/FieldsLayout.vue +++ b/frontend/src/components/Settings/FieldsLayout.vue @@ -74,6 +74,7 @@ const dirty = computed(() => { function saveChanges() { let _sections = JSON.parse(JSON.stringify(sections.data)) _sections.forEach((section) => { + if (!section.fields) return section.fields = section.fields.map((field) => field.name) }) loading.value = true diff --git a/frontend/src/pages/Deal.vue b/frontend/src/pages/Deal.vue index 0acf08d2..adbf0c6e 100644 --- a/frontend/src/pages/Deal.vue +++ b/frontend/src/pages/Deal.vue @@ -485,41 +485,26 @@ const fieldsLayout = createResource({ cache: ['fieldsLayout', props.dealId], params: { doctype: 'CRM Deal', name: props.dealId }, auto: true, - transform: (data) => getParsedFields(data, deal_contacts.data), + transform: (data) => getParsedFields(data), }) function getParsedFields(sections, contacts) { sections.forEach((section) => { - if (section.name == 'contacts_tab') { - delete section.fields - section.contacts = - contacts?.map((contact) => { - return { - name: contact.name, - full_name: contact.full_name, - email: contact.email, - mobile_no: contact.mobile_no, - image: contact.image, - is_primary: contact.is_primary, - opened: false, - } - }) || [] - } else { - section.fields.forEach((field) => { - if (field.name == 'organization') { - field.create = (value, close) => { - _organization.value.organization_name = value - showOrganizationModal.value = true - close() - } - field.link = (org) => - router.push({ - name: 'Organization', - params: { organizationId: org }, - }) + if (section.name == 'contacts_section') return + section.fields.forEach((field) => { + if (field.name == 'organization') { + field.create = (value, close) => { + _organization.value.organization_name = value + showOrganizationModal.value = true + close() } - }) - } + field.link = (org) => + router.push({ + name: 'Organization', + params: { organizationId: org }, + }) + } + }) }) return sections } @@ -597,6 +582,21 @@ const deal_contacts = createResource({ params: { name: props.dealId }, cache: ['deal_contacts', props.dealId], auto: true, + onSuccess: (data) => { + fieldsLayout.data.find( + (section) => section.name == 'contacts_section', + ).contacts = data.map((contact) => { + return { + name: contact.name, + full_name: contact.full_name, + email: contact.email, + mobile_no: contact.mobile_no, + image: contact.image, + is_primary: contact.is_primary, + opened: false, + } + }) + }, }) function triggerCall() {