fix: handle rendering of contacts section

This commit is contained in:
Shariq Ansari 2024-06-15 12:27:00 +05:30
parent afeac24b36
commit c430abc33a
2 changed files with 31 additions and 30 deletions

View File

@ -74,6 +74,7 @@ const dirty = computed(() => {
function saveChanges() { function saveChanges() {
let _sections = JSON.parse(JSON.stringify(sections.data)) let _sections = JSON.parse(JSON.stringify(sections.data))
_sections.forEach((section) => { _sections.forEach((section) => {
if (!section.fields) return
section.fields = section.fields.map((field) => field.name) section.fields = section.fields.map((field) => field.name)
}) })
loading.value = true loading.value = true

View File

@ -485,41 +485,26 @@ const fieldsLayout = createResource({
cache: ['fieldsLayout', props.dealId], cache: ['fieldsLayout', props.dealId],
params: { doctype: 'CRM Deal', name: props.dealId }, params: { doctype: 'CRM Deal', name: props.dealId },
auto: true, auto: true,
transform: (data) => getParsedFields(data, deal_contacts.data), transform: (data) => getParsedFields(data),
}) })
function getParsedFields(sections, contacts) { function getParsedFields(sections, contacts) {
sections.forEach((section) => { sections.forEach((section) => {
if (section.name == 'contacts_tab') { if (section.name == 'contacts_section') return
delete section.fields section.fields.forEach((field) => {
section.contacts = if (field.name == 'organization') {
contacts?.map((contact) => { field.create = (value, close) => {
return { _organization.value.organization_name = value
name: contact.name, showOrganizationModal.value = true
full_name: contact.full_name, close()
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 },
})
} }
}) field.link = (org) =>
} router.push({
name: 'Organization',
params: { organizationId: org },
})
}
})
}) })
return sections return sections
} }
@ -597,6 +582,21 @@ const deal_contacts = createResource({
params: { name: props.dealId }, params: { name: props.dealId },
cache: ['deal_contacts', props.dealId], cache: ['deal_contacts', props.dealId],
auto: true, 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() { function triggerCall() {