refactor: render assignees from document.js

reload assignees if lead_owner/deal_owner is changed

(cherry picked from commit e214ce8bfbedfe93338ab04c2ee55259a60e9d8e)
This commit is contained in:
Shariq Ansari 2025-06-05 18:55:28 +05:30 committed by Mergify
parent 88f4e10833
commit 22e38c05b4
5 changed files with 61 additions and 10 deletions

View File

@ -365,7 +365,11 @@
</div>
</div>
<div v-else-if="title == 'Data'" class="h-full flex flex-col px-3 sm:px-10">
<DataFields :doctype="doctype" :docname="doc.data.name" />
<DataFields
:doctype="doctype"
:docname="doc.data.name"
@afterSave="(data) => emit('afterSave', data)"
/>
</div>
<div
v-else
@ -514,6 +518,8 @@ const props = defineProps({
},
})
const emit = defineEmits(['afterSave'])
const route = useRoute()
const doc = defineModel()

View File

@ -76,6 +76,9 @@ const props = defineProps({
required: true,
},
})
const emit = defineEmits(['afterSave'])
const { isManager } = usersStore()
const showDataFieldsModal = ref(false)
@ -90,7 +93,21 @@ const tabs = createResource({
})
function saveChanges() {
document.save.submit()
if (!document.isDirty) return
const updatedDoc = { ...document.doc }
const oldDoc = { ...document.originalDoc }
const changes = Object.keys(updatedDoc).reduce((acc, key) => {
if (JSON.stringify(updatedDoc[key]) !== JSON.stringify(oldDoc[key])) {
acc[key] = updatedDoc[key]
}
return acc
}, {})
document.save.submit(null, {
onSuccess: () => emit('afterSave', changes),
})
}
watch(

View File

@ -417,13 +417,13 @@ const props = defineProps({
},
})
const emit = defineEmits(['afterFieldChange', 'reload'])
const { getFormattedPercent, getFormattedFloat, getFormattedCurrency } =
getMeta(props.doctype)
const { isManager, getUser } = usersStore()
const emit = defineEmits(['reload'])
const showSidePanelModal = ref(false)
let document = { doc: {} }
@ -493,7 +493,13 @@ async function fieldChange(value, df) {
await triggerOnChange(df.fieldname)
document.save.submit()
document.save.submit(null, {
onSuccess: () => {
emit('afterFieldChange', {
[df.fieldname]: value,
})
},
})
}
function parsedSection(section, editButtonAdded) {

View File

@ -13,8 +13,8 @@
:actions="deal.data._customActions"
/>
<AssignTo
v-model="deal.data._assignedTo"
:data="deal.data"
v-model="assignees.data"
:data="document.doc"
doctype="CRM Deal"
/>
<Dropdown
@ -46,6 +46,7 @@
v-model:reload="reload"
v-model:tabIndex="tabIndex"
v-model="deal"
@afterSave="reloadAssignees"
/>
</template>
</Tabs>
@ -134,6 +135,7 @@
doctype="CRM Deal"
:docname="deal.data.name"
@reload="sections.reload"
@afterFieldChange="reloadAssignees"
>
<template #actions="{ section }">
<div v-if="section.name == 'contacts_section'" class="pr-2">
@ -343,6 +345,7 @@ import { getSettings } from '@/stores/settings'
import { globalStore } from '@/stores/global'
import { statusesStore } from '@/stores/statuses'
import { getMeta } from '@/stores/meta'
import { useDocument } from '@/data/document'
import { whatsappEnabled, callEnabled } from '@/composables/settings'
import {
createResource,
@ -721,4 +724,12 @@ const activities = ref(null)
function openEmailBox() {
activities.value.emailBox.show = true
}
const { assignees, document } = useDocument('CRM Deal', props.dealId)
function reloadAssignees(changes) {
if (changes?.hasOwnProperty('lead_owner')) {
assignees.reload()
}
}
</script>

View File

@ -13,8 +13,8 @@
:actions="lead.data._customActions"
/>
<AssignTo
v-model="lead.data._assignedTo"
:data="lead.data"
v-model="assignees.data"
:data="document.doc"
doctype="CRM Lead"
/>
<Dropdown
@ -51,6 +51,7 @@
v-model:reload="reload"
v-model:tabIndex="tabIndex"
v-model="lead"
@afterSave="reloadAssignees"
/>
</template>
</Tabs>
@ -186,6 +187,7 @@
doctype="CRM Lead"
:docname="lead.data.name"
@reload="sections.reload"
@afterFieldChange="reloadAssignees"
/>
</div>
</Resizer>
@ -609,7 +611,10 @@ const existingOrganizationChecked = ref(false)
const existingContact = ref('')
const existingOrganization = ref('')
const { triggerConvertToDeal } = useDocument('CRM Lead', props.leadId)
const { triggerConvertToDeal, assignees, document } = useDocument(
'CRM Lead',
props.leadId,
)
async function convertToDeal() {
if (existingContactChecked.value && !existingContact.value) {
@ -711,4 +716,10 @@ function openQuickEntryModal() {
}
showConvertToDealModal.value = false
}
function reloadAssignees(changes) {
if (changes?.hasOwnProperty('lead_owner')) {
assignees.reload()
}
}
</script>