fix: render custom actions on lead/deal header

This commit is contained in:
Shariq Ansari 2023-12-28 16:45:32 +05:30
parent 1e780ff1ac
commit 95886bfde0
3 changed files with 44 additions and 19 deletions

View File

@ -4,6 +4,10 @@
<Breadcrumbs :items="breadcrumbs" /> <Breadcrumbs :items="breadcrumbs" />
</template> </template>
<template #right-header> <template #right-header>
<CustomActions
v-if="deal.data._customActions"
:actions="deal.data._customActions"
/>
<Dropdown <Dropdown
:options="[ :options="[
{ {
@ -310,8 +314,13 @@ import Link from '@/components/Controls/Link.vue'
import Section from '@/components/Section.vue' import Section from '@/components/Section.vue'
import SectionFields from '@/components/SectionFields.vue' import SectionFields from '@/components/SectionFields.vue'
import SLASection from '@/components/SLASection.vue' import SLASection from '@/components/SLASection.vue'
import { openWebsite, createToast } from '@/utils' import CustomActions from '@/components/CustomActions.vue'
import { usersStore } from '@/stores/users' import {
openWebsite,
createToast,
setupAssignees,
setupCustomActions,
} from '@/utils'
import { contactsStore } from '@/stores/contacts' import { contactsStore } from '@/stores/contacts'
import { organizationsStore } from '@/stores/organizations' import { organizationsStore } from '@/stores/organizations'
import { statusesStore } from '@/stores/statuses' import { statusesStore } from '@/stores/statuses'
@ -329,7 +338,6 @@ import {
import { ref, computed, h } from 'vue' import { ref, computed, h } from 'vue'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
const { getUser } = usersStore()
const { getContactByName, contacts } = contactsStore() const { getContactByName, contacts } = contactsStore()
const { organizations, getOrganization } = organizationsStore() const { organizations, getOrganization } = organizationsStore()
const { statusOptions, getDealStatus } = statusesStore() const { statusOptions, getDealStatus } = statusesStore()
@ -348,12 +356,8 @@ const deal = createResource({
cache: ['deal', props.dealId], cache: ['deal', props.dealId],
auto: true, auto: true,
onSuccess: (data) => { onSuccess: (data) => {
let assignees = JSON.parse(data._assign) || [] setupAssignees(data)
data._assignedTo = assignees.map((user) => ({ setupCustomActions(data, { doc: data, updateField })
name: user,
image: getUser(user).user_image,
label: getUser(user).full_name,
}))
}, },
}) })

View File

@ -4,6 +4,10 @@
<Breadcrumbs :items="breadcrumbs" /> <Breadcrumbs :items="breadcrumbs" />
</template> </template>
<template #right-header> <template #right-header>
<CustomActions
v-if="lead.data._customActions"
:actions="lead.data._customActions"
/>
<Dropdown <Dropdown
:options="[ :options="[
{ {
@ -216,8 +220,13 @@ import MultipleAvatar from '@/components/MultipleAvatar.vue'
import Section from '@/components/Section.vue' import Section from '@/components/Section.vue'
import SectionFields from '@/components/SectionFields.vue' import SectionFields from '@/components/SectionFields.vue'
import SLASection from '@/components/SLASection.vue' import SLASection from '@/components/SLASection.vue'
import { openWebsite, createToast } from '@/utils' import CustomActions from '@/components/CustomActions.vue'
import { usersStore } from '@/stores/users' import {
openWebsite,
createToast,
setupAssignees,
setupCustomActions,
} from '@/utils'
import { contactsStore } from '@/stores/contacts' import { contactsStore } from '@/stores/contacts'
import { organizationsStore } from '@/stores/organizations' import { organizationsStore } from '@/stores/organizations'
import { statusesStore } from '@/stores/statuses' import { statusesStore } from '@/stores/statuses'
@ -236,7 +245,6 @@ import {
import { ref, computed } from 'vue' import { ref, computed } from 'vue'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
const { getUser } = usersStore()
const { contacts } = contactsStore() const { contacts } = contactsStore()
const { organizations, getOrganization } = organizationsStore() const { organizations, getOrganization } = organizationsStore()
const { statusOptions, getLeadStatus } = statusesStore() const { statusOptions, getLeadStatus } = statusesStore()
@ -255,12 +263,8 @@ const lead = createResource({
cache: ['lead', props.leadId], cache: ['lead', props.leadId],
auto: true, auto: true,
onSuccess: (data) => { onSuccess: (data) => {
let assignees = JSON.parse(data._assign) || [] setupAssignees(data)
data._assignedTo = assignees.map((user) => ({ setupCustomActions(data, { doc: data, updateField })
name: user,
image: getUser(user).user_image,
label: getUser(user).full_name,
}))
}, },
}) })

View File

@ -1,8 +1,9 @@
import TaskStatusIcon from '@/components/Icons/TaskStatusIcon.vue' import TaskStatusIcon from '@/components/Icons/TaskStatusIcon.vue'
import TaskPriorityIcon from '@/components/Icons/TaskPriorityIcon.vue' import TaskPriorityIcon from '@/components/Icons/TaskPriorityIcon.vue'
import { useDateFormat, useTimeAgo } from '@vueuse/core' import { useDateFormat, useTimeAgo } from '@vueuse/core'
import { usersStore } from '@/stores/users'
import { toast } from 'frappe-ui' import { toast } from 'frappe-ui'
import { h, computed } from 'vue' import { h } from 'vue'
export function createToast(options) { export function createToast(options) {
toast({ toast({
@ -112,3 +113,19 @@ export function validateEmail(email) {
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
return regExp.test(email) return regExp.test(email)
} }
export function setupAssignees(data) {
let { getUser } = usersStore()
let assignees = JSON.parse(data._assign) || []
data._assignedTo = assignees.map((user) => ({
name: user,
image: getUser(user).user_image,
label: getUser(user).full_name,
}))
}
export function setupCustomActions(data, obj) {
let script = new Function(data._form_script + '\nreturn setupForm')()
let formScript = script(obj)
data._customActions = formScript?.actions || []
}