refactor: update AssignTo component to use docname prop and streamline assignment logic
This commit is contained in:
parent
3ed2c4812a
commit
faef5cb866
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div @click="showCallLogDetailModal = true" class="cursor-pointer">
|
<div>
|
||||||
<div class="mb-1 flex items-center justify-stretch gap-2 py-1 text-base">
|
<div class="mb-1 flex items-center justify-stretch gap-2 py-1 text-base">
|
||||||
<div class="inline-flex items-center flex-wrap gap-1 text-ink-gray-5">
|
<div class="inline-flex items-center flex-wrap gap-1 text-ink-gray-5">
|
||||||
<Avatar
|
<Avatar
|
||||||
@ -25,7 +25,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="flex flex-col gap-2 border border-outline-gray-modals rounded-md bg-surface-cards px-3 py-2.5 text-ink-gray-9"
|
@click="showCallLogDetailModal = true"
|
||||||
|
class="flex flex-col gap-2 border cursor-pointer border-outline-gray-modals rounded-md bg-surface-cards px-3 py-2.5 text-ink-gray-9"
|
||||||
>
|
>
|
||||||
<div class="flex items-center justify-between">
|
<div class="flex items-center justify-between">
|
||||||
<div class="inline-flex gap-2 items-center text-base font-medium">
|
<div class="inline-flex gap-2 items-center text-base font-medium">
|
||||||
|
|||||||
@ -13,9 +13,10 @@
|
|||||||
<AssignToBody
|
<AssignToBody
|
||||||
v-show="open"
|
v-show="open"
|
||||||
v-model="assignees"
|
v-model="assignees"
|
||||||
:doc="data"
|
:docname="docname"
|
||||||
:doctype="doctype"
|
:doctype="doctype"
|
||||||
:open="open"
|
:open="open"
|
||||||
|
:onUpdate="ownerField && saveAssignees"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
</NestedPopover>
|
</NestedPopover>
|
||||||
@ -24,11 +25,74 @@
|
|||||||
import NestedPopover from '@/components/NestedPopover.vue'
|
import NestedPopover from '@/components/NestedPopover.vue'
|
||||||
import MultipleAvatar from '@/components/MultipleAvatar.vue'
|
import MultipleAvatar from '@/components/MultipleAvatar.vue'
|
||||||
import AssignToBody from '@/components/AssignToBody.vue'
|
import AssignToBody from '@/components/AssignToBody.vue'
|
||||||
|
import { useDocument } from '@/data/document'
|
||||||
|
import { toast } from 'frappe-ui'
|
||||||
|
import { computed } from 'vue'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
data: Object,
|
|
||||||
doctype: String,
|
doctype: String,
|
||||||
|
docname: String,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const { document } = useDocument(props.doctype, props.docname)
|
||||||
|
|
||||||
const assignees = defineModel()
|
const assignees = defineModel()
|
||||||
|
|
||||||
|
const ownerField = computed(() => {
|
||||||
|
if (props.doctype === 'CRM Lead') {
|
||||||
|
return 'lead_owner'
|
||||||
|
} else if (props.doctype === 'CRM Deal') {
|
||||||
|
return 'deal_owner'
|
||||||
|
} else {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
async function saveAssignees(
|
||||||
|
addedAssignees,
|
||||||
|
removedAssignees,
|
||||||
|
addAssignees,
|
||||||
|
removeAssignees,
|
||||||
|
) {
|
||||||
|
removedAssignees.length && (await removeAssignees.submit(removedAssignees))
|
||||||
|
addedAssignees.length && (await addAssignees.submit(addedAssignees))
|
||||||
|
|
||||||
|
const nextAssignee = assignees.value.find(
|
||||||
|
(a) => a.name !== document.doc[ownerField.value],
|
||||||
|
)
|
||||||
|
|
||||||
|
let owner = ownerField.value.replace('_', ' ')
|
||||||
|
|
||||||
|
if (
|
||||||
|
document.doc[ownerField.value] &&
|
||||||
|
removedAssignees.includes(document.doc[ownerField.value])
|
||||||
|
) {
|
||||||
|
document.doc[ownerField.value] = nextAssignee ? nextAssignee.name : ''
|
||||||
|
document.save.submit()
|
||||||
|
|
||||||
|
if (nextAssignee) {
|
||||||
|
toast.info(
|
||||||
|
__(
|
||||||
|
'Since you removed {0} from the assignee, the {0} has been changed to the next available assignee {1}.',
|
||||||
|
[owner, nextAssignee.label || nextAssignee.name],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
toast.info(
|
||||||
|
__(
|
||||||
|
'Since you removed {0} from the assignee, the {0} has also been removed.',
|
||||||
|
[owner],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else if (!document.doc[ownerField.value] && nextAssignee) {
|
||||||
|
document.doc[ownerField.value] = nextAssignee ? nextAssignee.name : ''
|
||||||
|
toast.info(
|
||||||
|
__('Since you added a new assignee, the {0} has been set to {1}.', [
|
||||||
|
owner,
|
||||||
|
nextAssignee.label || nextAssignee.name,
|
||||||
|
]),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -74,22 +74,26 @@ import UserAvatar from '@/components/UserAvatar.vue'
|
|||||||
import Link from '@/components/Controls/Link.vue'
|
import Link from '@/components/Controls/Link.vue'
|
||||||
import { usersStore } from '@/stores/users'
|
import { usersStore } from '@/stores/users'
|
||||||
import { capture } from '@/telemetry'
|
import { capture } from '@/telemetry'
|
||||||
import { Tooltip, call, Switch, toast } from 'frappe-ui'
|
import { Tooltip, Switch, toast, createResource } from 'frappe-ui'
|
||||||
import { ref, computed, watch } from 'vue'
|
import { ref, watch } from 'vue'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
doc: {
|
|
||||||
type: Object,
|
|
||||||
default: null,
|
|
||||||
},
|
|
||||||
doctype: {
|
doctype: {
|
||||||
type: String,
|
type: String,
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
|
docname: {
|
||||||
|
type: Object,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
open: {
|
open: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
|
onUpdate: {
|
||||||
|
type: Function,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const emit = defineEmits(['reload'])
|
const emit = defineEmits(['reload'])
|
||||||
@ -102,12 +106,6 @@ const error = ref('')
|
|||||||
|
|
||||||
const { users, getUser } = usersStore()
|
const { users, getUser } = usersStore()
|
||||||
|
|
||||||
const owner = computed(() => {
|
|
||||||
if (!props.doc) return ''
|
|
||||||
if (props.doctype == 'CRM Lead') return props.doc.lead_owner
|
|
||||||
return props.doc.deal_owner
|
|
||||||
})
|
|
||||||
|
|
||||||
const removeValue = (value) => {
|
const removeValue = (value) => {
|
||||||
if (value === getUser('').name) {
|
if (value === getUser('').name) {
|
||||||
assignToMe.value = false
|
assignToMe.value = false
|
||||||
@ -119,6 +117,10 @@ const removeValue = (value) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const addValue = (value) => {
|
const addValue = (value) => {
|
||||||
|
if (value === getUser('').name) {
|
||||||
|
assignToMe.value = true
|
||||||
|
}
|
||||||
|
|
||||||
error.value = ''
|
error.value = ''
|
||||||
let obj = {
|
let obj = {
|
||||||
name: value,
|
name: value,
|
||||||
@ -155,6 +157,9 @@ watch(
|
|||||||
)
|
)
|
||||||
|
|
||||||
async function updateAssignees() {
|
async function updateAssignees() {
|
||||||
|
if (JSON.stringify(oldAssignees.value) === JSON.stringify(assignees.value))
|
||||||
|
return
|
||||||
|
|
||||||
const removedAssignees = oldAssignees.value
|
const removedAssignees = oldAssignees.value
|
||||||
.filter(
|
.filter(
|
||||||
(assignee) => !assignees.value.find((a) => a.name === assignee.name),
|
(assignee) => !assignees.value.find((a) => a.name === assignee.name),
|
||||||
@ -167,23 +172,45 @@ async function updateAssignees() {
|
|||||||
)
|
)
|
||||||
.map((assignee) => assignee.name)
|
.map((assignee) => assignee.name)
|
||||||
|
|
||||||
if (removedAssignees.length) {
|
if (props.onUpdate) {
|
||||||
await call('crm.api.doc.remove_assignments', {
|
props.onUpdate(
|
||||||
doctype: props.doctype,
|
addedAssignees,
|
||||||
name: props.doc.name,
|
removedAssignees,
|
||||||
assignees: removedAssignees,
|
addAssignees,
|
||||||
})
|
removeAssignees,
|
||||||
toast.success(__('Assignees removed successfully.'))
|
)
|
||||||
}
|
} else {
|
||||||
|
if (removedAssignees.length) {
|
||||||
if (addedAssignees.length) {
|
await removeAssignees.submit(removedAssignees)
|
||||||
capture('assign_to', { doctype: props.doctype })
|
}
|
||||||
call('frappe.desk.form.assign_to.add', {
|
if (addedAssignees.length) {
|
||||||
doctype: props.doctype,
|
addAssignees.submit(addedAssignees)
|
||||||
name: props.doc.name,
|
}
|
||||||
assign_to: addedAssignees,
|
|
||||||
})
|
|
||||||
toast.success(__('Assignees added successfully.'))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const addAssignees = createResource({
|
||||||
|
url: 'frappe.desk.form.assign_to.add',
|
||||||
|
makeParams: (addedAssignees) => ({
|
||||||
|
doctype: props.doctype,
|
||||||
|
name: props.docname,
|
||||||
|
assign_to: addedAssignees,
|
||||||
|
}),
|
||||||
|
onSuccess: () => {
|
||||||
|
capture('assign_to', { doctype: props.doctype })
|
||||||
|
toast.success(__('Assignees added successfully.'))
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const removeAssignees = createResource({
|
||||||
|
url: 'crm.api.doc.remove_assignments',
|
||||||
|
makeParams: (removedAssignees) => ({
|
||||||
|
doctype: props.doctype,
|
||||||
|
name: props.docname,
|
||||||
|
assignees: removedAssignees,
|
||||||
|
}),
|
||||||
|
onSuccess: () => {
|
||||||
|
toast.success(__('Assignees removed successfully.'))
|
||||||
|
},
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
v-if="document.actions?.length"
|
v-if="document.actions?.length"
|
||||||
:actions="document.actions"
|
:actions="document.actions"
|
||||||
/>
|
/>
|
||||||
<AssignTo v-model="assignees.data" :data="doc" doctype="CRM Deal" />
|
<AssignTo v-model="assignees.data" doctype="CRM Lead" :docname="dealId" />
|
||||||
<Dropdown
|
<Dropdown
|
||||||
v-if="doc"
|
v-if="doc"
|
||||||
:options="
|
:options="
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
v-if="document.actions?.length"
|
v-if="document.actions?.length"
|
||||||
:actions="document.actions"
|
:actions="document.actions"
|
||||||
/>
|
/>
|
||||||
<AssignTo v-model="assignees.data" :data="doc" doctype="CRM Lead" />
|
<AssignTo v-model="assignees.data" doctype="CRM Lead" :docname="leadId" />
|
||||||
<Dropdown
|
<Dropdown
|
||||||
v-if="doc"
|
v-if="doc"
|
||||||
:options="
|
:options="
|
||||||
|
|||||||
@ -42,7 +42,7 @@
|
|||||||
v-if="doc.name"
|
v-if="doc.name"
|
||||||
class="flex h-12 items-center justify-between gap-2 border-b px-3 py-2.5"
|
class="flex h-12 items-center justify-between gap-2 border-b px-3 py-2.5"
|
||||||
>
|
>
|
||||||
<AssignTo v-model="assignees.data" :data="doc" doctype="CRM Deal" />
|
<AssignTo v-model="assignees.data" doctype="CRM Lead" :docname="dealId" />
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<CustomActions
|
<CustomActions
|
||||||
v-if="document._actions?.length"
|
v-if="document._actions?.length"
|
||||||
|
|||||||
@ -42,7 +42,7 @@
|
|||||||
v-if="doc.name"
|
v-if="doc.name"
|
||||||
class="flex h-12 items-center justify-between gap-2 border-b px-3 py-2.5"
|
class="flex h-12 items-center justify-between gap-2 border-b px-3 py-2.5"
|
||||||
>
|
>
|
||||||
<AssignTo v-model="assignees.data" :data="doc" doctype="CRM Lead" />
|
<AssignTo v-model="assignees.data" doctype="CRM Lead" :docname="leadId" />
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<CustomActions
|
<CustomActions
|
||||||
v-if="document._actions?.length"
|
v-if="document._actions?.length"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user