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> </div>
<div v-else-if="title == 'Data'" class="h-full flex flex-col px-3 sm:px-10"> <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>
<div <div
v-else v-else
@ -514,6 +518,8 @@ const props = defineProps({
}, },
}) })
const emit = defineEmits(['afterSave'])
const route = useRoute() const route = useRoute()
const doc = defineModel() const doc = defineModel()

View File

@ -76,6 +76,9 @@ const props = defineProps({
required: true, required: true,
}, },
}) })
const emit = defineEmits(['afterSave'])
const { isManager } = usersStore() const { isManager } = usersStore()
const showDataFieldsModal = ref(false) const showDataFieldsModal = ref(false)
@ -90,7 +93,21 @@ const tabs = createResource({
}) })
function saveChanges() { 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( watch(

View File

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

View File

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

View File

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