1
0
forked from test/crm

refactor: moved all activity logic from lead/deal to activites component

This commit is contained in:
Shariq Ansari 2023-09-27 12:43:38 +05:30
parent ed6ba2c716
commit 463ead3671
4 changed files with 250 additions and 415 deletions

View File

@ -21,15 +21,15 @@ def get_lead(name):
frappe.throw(_("Lead not found"), frappe.DoesNotExistError) frappe.throw(_("Lead not found"), frappe.DoesNotExistError)
lead = lead.pop() lead = lead.pop()
return lead
@frappe.whitelist()
def get_activities(name):
get_docinfo('', "CRM Lead", name) get_docinfo('', "CRM Lead", name)
docinfo = frappe.response["docinfo"] docinfo = frappe.response["docinfo"]
activities = get_activities(lead, docinfo)
return { **lead, 'activities': activities }
def get_activities(doc, docinfo):
lead_fields_meta = frappe.get_meta("CRM Lead").fields lead_fields_meta = frappe.get_meta("CRM Lead").fields
doc = frappe.get_doc("CRM Lead", name, fields=["creation", "owner"])
activities = [{ activities = [{
"activity_type": "creation", "activity_type": "creation",
"creation": doc.creation, "creation": doc.creation,
@ -75,15 +75,6 @@ def get_activities(doc, docinfo):
} }
activities.append(activity) activities.append(activity)
for comment in docinfo.comments:
activity = {
"activity_type": "comment",
"creation": comment.creation,
"owner": comment.owner,
"data": comment.content,
}
activities.append(activity)
for communication in docinfo.communications: for communication in docinfo.communications:
activity = { activity = {
"activity_type": "communication", "activity_type": "communication",

View File

@ -3,23 +3,23 @@
<div class="flex h-7 items-center text-xl font-semibold text-gray-800"> <div class="flex h-7 items-center text-xl font-semibold text-gray-800">
{{ title }} {{ title }}
</div> </div>
<Button v-if="title == 'Calls'" variant="solid" @click="makeCall(lead.data.mobile_no)"> <Button
v-if="title == 'Calls'"
variant="solid"
@click="makeCall(lead.data.mobile_no)"
>
<PhoneIcon class="h-4 w-4" /> <PhoneIcon class="h-4 w-4" />
</Button> </Button>
<Button <Button v-else-if="title == 'Notes'" variant="solid" @click="showNote">
v-else-if="title == 'Notes'"
variant="solid"
@click="emit('makeNote')"
>
<FeatherIcon name="plus" class="h-4 w-4" /> <FeatherIcon name="plus" class="h-4 w-4" />
</Button> </Button>
</div> </div>
<div v-if="activities.length" class="flex-1 overflow-y-auto"> <div v-if="activities?.length" class="flex-1 overflow-y-auto">
<div v-if="title == 'Notes'" class="grid grid-cols-3 gap-4 px-10 py-5 pt-0"> <div v-if="title == 'Notes'" class="grid grid-cols-3 gap-4 px-10 py-5 pt-0">
<div <div
v-for="note in activities" v-for="note in activities"
class="group flex h-48 cursor-pointer flex-col justify-between gap-2 rounded-md bg-gray-50 px-4 py-3 hover:bg-gray-100" class="group flex h-48 cursor-pointer flex-col justify-between gap-2 rounded-md bg-gray-50 px-4 py-3 hover:bg-gray-100"
@click="emit('makeNote', note)" @click="showNote(note)"
> >
<div class="flex items-center justify-between"> <div class="flex items-center justify-between">
<div class="truncate text-lg font-medium"> <div class="truncate text-lg font-medium">
@ -30,7 +30,7 @@
{ {
icon: 'trash-2', icon: 'trash-2',
label: 'Delete', label: 'Delete',
onClick: () => emit('deleteNote', note.name), onClick: () => deleteNote(note.name),
}, },
]" ]"
@click.stop @click.stop
@ -346,11 +346,6 @@
</Tooltip> </Tooltip>
</div> </div>
</div> </div>
<div
v-if="activity.activity_type == 'comment'"
class="max-w-[80%] cursor-pointer rounded-xl border px-4 py-3 text-base leading-6 shadow-sm transition-all duration-300 ease-in-out"
v-html="activity.data"
/>
</div> </div>
</div> </div>
</div> </div>
@ -371,7 +366,7 @@
v-else-if="title == 'Notes'" v-else-if="title == 'Notes'"
variant="solid" variant="solid"
label="Create note" label="Create note"
@click="emit('makeNote')" @click="showNote"
/> />
<Button <Button
v-else-if="title == 'Emails'" v-else-if="title == 'Emails'"
@ -385,6 +380,7 @@
v-if="['Emails', 'Activity'].includes(title) && lead" v-if="['Emails', 'Activity'].includes(title) && lead"
v-model="lead" v-model="lead"
/> />
<NoteModal v-model="showNoteModal" :note="note" @updateNote="updateNote" />
</template> </template>
<script setup> <script setup>
import UserAvatar from '@/components/UserAvatar.vue' import UserAvatar from '@/components/UserAvatar.vue'
@ -399,8 +395,15 @@ import EmailAtIcon from '@/components/Icons/EmailAtIcon.vue'
import InboundCallIcon from '@/components/Icons/InboundCallIcon.vue' import InboundCallIcon from '@/components/Icons/InboundCallIcon.vue'
import OutboundCallIcon from '@/components/Icons/OutboundCallIcon.vue' import OutboundCallIcon from '@/components/Icons/OutboundCallIcon.vue'
import CommunicationArea from '@/components/CommunicationArea.vue' import CommunicationArea from '@/components/CommunicationArea.vue'
import { timeAgo, dateFormat, dateTooltipFormat } from '@/utils' import NoteModal from '@/components/NoteModal.vue'
import {
timeAgo,
dateFormat,
dateTooltipFormat,
secondsToDuration,
} from '@/utils'
import { usersStore } from '@/stores/users' import { usersStore } from '@/stores/users'
import { contactsStore } from '@/stores/contacts'
import { import {
Button, Button,
FeatherIcon, FeatherIcon,
@ -408,10 +411,14 @@ import {
Dropdown, Dropdown,
TextEditor, TextEditor,
Avatar, Avatar,
createResource,
createListResource,
call,
} from 'frappe-ui' } from 'frappe-ui'
import { computed, h, defineModel, markRaw } from 'vue' import { ref, computed, h, defineModel, markRaw } from 'vue'
const { getUser } = usersStore() const { getUser } = usersStore()
const { getContact } = contactsStore()
const props = defineProps({ const props = defineProps({
title: { title: {
@ -426,20 +433,105 @@ const props = defineProps({
const lead = defineModel() const lead = defineModel()
const emit = defineEmits(['makeNote', 'deleteNote']) const versions = createResource({
url: 'crm.fcrm.doctype.crm_lead.api.get_activities',
params: { name: lead.value.data.name },
cache: ['activity', lead.value.data.name],
auto: true,
})
const calls = createListResource({
type: 'list',
doctype: 'CRM Call Log',
cache: ['Call Logs', lead.value.data.name],
fields: [
'name',
'caller',
'receiver',
'from',
'to',
'duration',
'start_time',
'end_time',
'status',
'type',
'recording_url',
'creation',
'note',
],
filters: { lead: lead.value.data.name },
orderBy: 'creation desc',
pageLength: 999,
auto: true,
transform: (docs) => {
docs.forEach((doc) => {
doc.show_recording = false
doc.activity_type =
doc.type === 'Incoming' ? 'incoming_call' : 'outgoing_call'
doc.duration = secondsToDuration(doc.duration)
if (doc.type === 'Incoming') {
doc.caller = {
label: getContact(doc.from)?.full_name || 'Unknown',
image: getContact(doc.from)?.image,
}
doc.receiver = {
label: getUser(doc.receiver).full_name,
image: getUser(doc.receiver).user_image,
}
} else {
doc.caller = {
label: getUser(doc.caller).full_name,
image: getUser(doc.caller).user_image,
}
doc.receiver = {
label: getContact(doc.to)?.full_name || 'Unknown',
image: getContact(doc.to)?.image,
}
}
})
return docs
},
})
const notes = createListResource({
type: 'list',
doctype: 'CRM Note',
cache: ['Notes', lead.value.data.name],
fields: ['name', 'title', 'content', 'owner', 'modified'],
filters: { lead: lead.value.data.name },
orderBy: 'modified desc',
pageLength: 999,
auto: true,
})
function all_activities() {
if (!versions.data) return []
if (!calls.data) return versions.data
return [...versions.data, ...calls.data].sort(
(a, b) => new Date(b.creation) - new Date(a.creation)
)
}
const activities = computed(() => { const activities = computed(() => {
if (props.title == 'Calls') { let activities = []
props.activities.forEach((activity) => { if (props.title == 'Activity') {
activity.show_recording = false activities = all_activities()
}) } else if (props.title == 'Emails') {
return props.activities activities = versions.data.filter(
(activity) => activity.activity_type === 'communication'
)
} else if (props.title == 'Calls') {
return calls.data
} else if (props.title == 'Notes') {
return notes.data
} }
props.activities.forEach((activity) => { activities.forEach((activity) => {
activity.icon = timelineIcon(activity.activity_type) activity.icon = timelineIcon(activity.activity_type)
if ( if (
activity.activity_type == 'incoming_call' || activity.activity_type == 'incoming_call' ||
activity.activity_type == 'outgoing_call' activity.activity_type == 'outgoing_call' ||
activity.activity_type == 'communication'
) )
return return
@ -450,8 +542,6 @@ const activities = computed(() => {
if (activity.activity_type == 'creation') { if (activity.activity_type == 'creation') {
activity.type = activity.data activity.type = activity.data
} else if (activity.activity_type == 'comment') {
activity.type = 'added a comment'
} else if (activity.activity_type == 'added') { } else if (activity.activity_type == 'added') {
activity.type = 'added' activity.type = 'added'
activity.value = 'value as' activity.value = 'value as'
@ -464,7 +554,7 @@ const activities = computed(() => {
activity.to = 'to' activity.to = 'to'
} }
}) })
return props.activities return activities
}) })
const emptyText = computed(() => { const emptyText = computed(() => {
@ -508,6 +598,53 @@ function timelineIcon(activity_type) {
return markRaw(icon) return markRaw(icon)
} }
const showNoteModal = ref(false)
const note = ref({
title: '',
content: '',
})
function showNote(n) {
note.value = n || {
title: '',
content: '',
}
showNoteModal.value = true
}
async function deleteNote(name) {
await call('frappe.client.delete', {
doctype: 'CRM Note',
name,
})
notes.reload()
}
async function updateNote(note) {
if (note.name) {
let d = await call('frappe.client.set_value', {
doctype: 'CRM Note',
name: note.name,
fieldname: note,
})
if (d.name) {
notes.reload()
}
} else {
let d = await call('frappe.client.insert', {
doc: {
doctype: 'CRM Note',
title: note.title,
content: note.content,
lead: props.leadId,
},
})
if (d.name) {
notes.reload()
}
}
}
</script> </script>
<style scoped> <style scoped>

View File

@ -36,8 +36,8 @@
</template> </template>
</LayoutHeader> </LayoutHeader>
<div v-if="deal.data" class="flex h-full overflow-hidden"> <div v-if="deal.data" class="flex h-full overflow-hidden">
<TabGroup as="div" class="flex flex-col flex-1" @change="onTabChange"> <TabGroup as="div" class="flex flex-1 flex-col" @change="onTabChange">
<TabList class="flex items-center gap-6 border-b pl-5 relative"> <TabList class="relative flex items-center gap-6 border-b pl-5">
<Tab <Tab
ref="tabRef" ref="tabRef"
as="template" as="template"
@ -46,7 +46,7 @@
v-slot="{ selected }" v-slot="{ selected }"
> >
<button <button
class="flex items-center gap-2 py-2.5 -mb-[1px] text-base text-gray-600 border-b border-transparent hover:text-gray-900 hover:border-gray-400 transition-all duration-300 ease-in-out" class="-mb-[1px] flex items-center gap-2 border-b border-transparent py-2.5 text-base text-gray-600 transition-all duration-300 ease-in-out hover:border-gray-400 hover:text-gray-900"
:class="{ 'text-gray-900': selected }" :class="{ 'text-gray-900': selected }"
> >
<component v-if="tab.icon" :is="tab.icon" class="h-5" /> <component v-if="tab.icon" :is="tab.icon" class="h-5" />
@ -55,39 +55,33 @@
</Tab> </Tab>
<div <div
ref="indicator" ref="indicator"
class="h-[1px] bg-gray-900 w-[82px] absolute -bottom-[1px]" class="absolute -bottom-[1px] h-[1px] w-[82px] bg-gray-900"
:style="{ left: `${indicatorLeftValue}px` }" :style="{ left: `${indicatorLeftValue}px` }"
/> />
</TabList> </TabList>
<TabPanels class="flex flex-1 overflow-hidden"> <TabPanels class="flex flex-1 overflow-hidden">
<TabPanel <TabPanel
class="flex-1 flex flex-col overflow-y-auto" class="flex flex-1 flex-col overflow-y-auto"
v-for="tab in tabs" v-for="tab in tabs"
:key="tab.label" :key="tab.label"
> >
<Activities <Activities :title="tab.label" v-model="deal" />
:title="tab.activityTitle"
:activities="tab.content"
v-model="deal"
@makeNote="(e) => showNote(e)"
@deleteNote="(e) => deleteNote(e)"
/>
</TabPanel> </TabPanel>
</TabPanels> </TabPanels>
</TabGroup> </TabGroup>
<div class="flex flex-col justify-between border-l w-[352px]"> <div class="flex w-[352px] flex-col justify-between border-l">
<div <div
class="flex items-center border-b px-5 py-2.5 h-[41px] font-semibold text-lg" class="flex h-[41px] items-center border-b px-5 py-2.5 text-lg font-semibold"
> >
About this deal About this deal
</div> </div>
<FileUploader @success="changeDealImage" :validateFile="validateFile"> <FileUploader @success="changeDealImage" :validateFile="validateFile">
<template #default="{ openFileSelector, error }"> <template #default="{ openFileSelector, error }">
<div class="flex gap-5 items-center justify-start p-5 border-b"> <div class="flex items-center justify-start gap-5 border-b p-5">
<div class="relative w-[88px] h-[88px] group"> <div class="group relative h-[88px] w-[88px]">
<Avatar <Avatar
size="3xl" size="3xl"
class="w-[88px] h-[88px]" class="h-[88px] w-[88px]"
:label="deal.data.organization_name" :label="deal.data.organization_name"
:image="deal.data.organization_logo" :image="deal.data.organization_logo"
/> />
@ -112,19 +106,19 @@
class="!absolute bottom-0 left-0 right-0" class="!absolute bottom-0 left-0 right-0"
> >
<div <div
class="absolute bottom-0 left-0 right-0 rounded-b-full z-1 h-11 flex items-center justify-center pt-3 bg-black bg-opacity-40 cursor-pointer opacity-0 group-hover:opacity-100 duration-300 ease-in-out" class="z-1 absolute bottom-0 left-0 right-0 flex h-11 cursor-pointer items-center justify-center rounded-b-full bg-black bg-opacity-40 pt-3 opacity-0 duration-300 ease-in-out group-hover:opacity-100"
style=" style="
-webkit-clip-path: inset(12px 0 0 0); -webkit-clip-path: inset(12px 0 0 0);
clip-path: inset(12px 0 0 0); clip-path: inset(12px 0 0 0);
" "
> >
<CameraIcon class="h-6 w-6 text-white cursor-pointer" /> <CameraIcon class="h-6 w-6 cursor-pointer text-white" />
</div> </div>
</Dropdown> </Dropdown>
</div> </div>
<div class="flex flex-col gap-2.5 truncate"> <div class="flex flex-col gap-2.5 truncate">
<Tooltip :text="deal.data.organization_name"> <Tooltip :text="deal.data.organization_name">
<div class="font-medium text-2xl truncate"> <div class="truncate text-2xl font-medium">
{{ deal.data.organization_name }} {{ deal.data.organization_name }}
</div> </div>
</Tooltip> </Tooltip>
@ -154,7 +148,7 @@
</div> </div>
</template> </template>
</FileUploader> </FileUploader>
<div class="flex-1 flex flex-col justify-between overflow-hidden"> <div class="flex flex-1 flex-col justify-between overflow-hidden">
<div class="flex flex-col overflow-y-auto"> <div class="flex flex-col overflow-y-auto">
<div <div
v-for="(section, i) in detailSections" v-for="(section, i) in detailSections"
@ -164,7 +158,7 @@
> >
<Toggler :is-opened="section.opened" v-slot="{ opened, toggle }"> <Toggler :is-opened="section.opened" v-slot="{ opened, toggle }">
<div <div
class="flex items-center gap-2 text-base font-semibold leading-5 pl-2 pr-3 cursor-pointer max-w-fit" class="flex max-w-fit cursor-pointer items-center gap-2 pl-2 pr-3 text-base font-semibold leading-5"
@click="toggle()" @click="toggle()"
> >
<FeatherIcon <FeatherIcon
@ -186,9 +180,9 @@
<div <div
v-for="field in section.fields" v-for="field in section.fields"
:key="field.label" :key="field.label"
class="flex items-center px-3 gap-2 text-base leading-5 first:mt-3" class="flex items-center gap-2 px-3 text-base leading-5 first:mt-3"
> >
<div class="text-gray-600 w-[106px]"> <div class="w-[106px] text-gray-600">
{{ field.label }} {{ field.label }}
</div> </div>
<div class="flex-1"> <div class="flex-1">
@ -240,7 +234,7 @@
variant="ghost" variant="ghost"
@click="togglePopover()" @click="togglePopover()"
:label="getUser(deal.data[field.name]).full_name" :label="getUser(deal.data[field.name]).full_name"
class="!justify-start w-full" class="w-full !justify-start"
> >
<template #prefix> <template #prefix>
<UserAvatar <UserAvatar
@ -268,7 +262,7 @@
<template #default="{ open }"> <template #default="{ open }">
<Button <Button
:label="deal.data[field.name]" :label="deal.data[field.name]"
class="justify-between w-full" class="w-full justify-between"
> >
<template #prefix> <template #prefix>
<IndicatorIcon <IndicatorIcon
@ -339,13 +333,11 @@
</div> </div>
</div> </div>
</div> </div>
<NoteModal v-model="showNoteModal" :note="note" @updateNote="updateNote" />
</template> </template>
<script setup> <script setup>
import ActivityIcon from '@/components/Icons/ActivityIcon.vue' import ActivityIcon from '@/components/Icons/ActivityIcon.vue'
import EmailIcon from '@/components/Icons/EmailIcon.vue' import EmailIcon from '@/components/Icons/EmailIcon.vue'
import PhoneIcon from '@/components/Icons/PhoneIcon.vue' import PhoneIcon from '@/components/Icons/PhoneIcon.vue'
import TaskIcon from '@/components/Icons/TaskIcon.vue'
import NoteIcon from '@/components/Icons/NoteIcon.vue' import NoteIcon from '@/components/Icons/NoteIcon.vue'
import IndicatorIcon from '@/components/Icons/IndicatorIcon.vue' import IndicatorIcon from '@/components/Icons/IndicatorIcon.vue'
import CameraIcon from '@/components/Icons/CameraIcon.vue' import CameraIcon from '@/components/Icons/CameraIcon.vue'
@ -355,21 +347,18 @@ import Toggler from '@/components/Toggler.vue'
import Activities from '@/components/Activities.vue' import Activities from '@/components/Activities.vue'
import Breadcrumbs from '@/components/Breadcrumbs.vue' import Breadcrumbs from '@/components/Breadcrumbs.vue'
import UserAvatar from '@/components/UserAvatar.vue' import UserAvatar from '@/components/UserAvatar.vue'
import NoteModal from '@/components/NoteModal.vue'
import { TabGroup, TabList, Tab, TabPanels, TabPanel } from '@headlessui/vue' import { TabGroup, TabList, Tab, TabPanels, TabPanel } from '@headlessui/vue'
import { TransitionPresets, useTransition } from '@vueuse/core' import { TransitionPresets, useTransition } from '@vueuse/core'
import { import {
dealStatuses, dealStatuses,
statusDropdownOptions, statusDropdownOptions,
openWebsite, openWebsite,
secondsToDuration,
createToast, createToast,
} from '@/utils' } from '@/utils'
import { usersStore } from '@/stores/users' import { usersStore } from '@/stores/users'
import { contactsStore } from '@/stores/contacts' import { contactsStore } from '@/stores/contacts'
import { import {
createResource, createResource,
createListResource,
FeatherIcon, FeatherIcon,
FileUploader, FileUploader,
ErrorMessage, ErrorMessage,
@ -378,12 +367,11 @@ import {
Dropdown, Dropdown,
Tooltip, Tooltip,
Avatar, Avatar,
call,
} from 'frappe-ui' } from 'frappe-ui'
import { ref, computed } from 'vue' import { ref, computed } from 'vue'
const { getUser, users } = usersStore() const { getUser, users } = usersStore()
const { getContact, contacts } = contactsStore() const { contacts } = contactsStore()
const props = defineProps({ const props = defineProps({
dealId: { dealId: {
@ -438,49 +426,24 @@ const breadcrumbs = computed(() => {
return items return items
}) })
const tabs = computed(() => { const tabs = [
return [ {
{ label: 'Activity',
label: 'Activity', icon: ActivityIcon,
icon: ActivityIcon, },
content: all_activities(), {
activityTitle: 'Activity', label: 'Emails',
}, icon: EmailIcon,
{ },
label: 'Emails', {
icon: EmailIcon, label: 'Calls',
content: deal.data.activities.filter( icon: PhoneIcon,
(activity) => activity.activity_type === 'communication' },
), {
activityTitle: 'Emails', label: 'Notes',
}, icon: NoteIcon,
{ },
label: 'Calls', ]
icon: PhoneIcon,
content: calls.data,
activityTitle: 'Calls',
},
// {
// label: 'Tasks',
// icon: TaskIcon,
// activityTitle: 'Tasks',
// },
{
label: 'Notes',
icon: NoteIcon,
activityTitle: 'Notes',
content: notes.data,
},
]
})
function all_activities() {
if (!deal.data) return []
if (!calls.data) return deal.data.activities
return [...deal.data.activities, ...calls.data].sort(
(a, b) => new Date(b.creation) - new Date(a.creation)
)
}
function changeDealImage(file) { function changeDealImage(file) {
deal.data.organization_logo = file.file_url deal.data.organization_logo = file.file_url
@ -611,116 +574,6 @@ const activeAgents = computed(() => {
}) })
}) })
const showNoteModal = ref(false)
const note = ref({
title: '',
content: '',
})
const notes = createListResource({
type: 'list',
doctype: 'CRM Note',
cache: ['Notes', props.dealId],
fields: ['name', 'title', 'content', 'owner', 'modified'],
filters: { lead: props.dealId },
orderBy: 'modified desc',
pageLength: 999,
auto: true,
})
function showNote(n) {
note.value = n || {
title: '',
content: '',
}
showNoteModal.value = true
}
async function deleteNote(name) {
await call('frappe.client.delete', {
doctype: 'CRM Note',
name,
})
notes.reload()
}
async function updateNote(note) {
if (note.name) {
let d = await call('frappe.client.set_value', {
doctype: 'CRM Note',
name: note.name,
fieldname: note,
})
if (d.name) {
notes.reload()
}
} else {
let d = await call('frappe.client.insert', {
doc: {
doctype: 'CRM Note',
title: note.title,
content: note.content,
lead: props.dealId,
},
})
if (d.name) {
notes.reload()
}
}
}
const calls = createListResource({
type: 'list',
doctype: 'CRM Call Log',
cache: ['Call Logs', props.dealId],
fields: [
'name',
'caller',
'receiver',
'from',
'to',
'duration',
'start_time',
'end_time',
'status',
'type',
'recording_url',
'creation',
'note',
],
filters: { lead: props.dealId },
orderBy: 'creation desc',
pageLength: 999,
auto: true,
transform: (docs) => {
docs.forEach((doc) => {
doc.activity_type =
doc.type === 'Incoming' ? 'incoming_call' : 'outgoing_call'
doc.duration = secondsToDuration(doc.duration)
if (doc.type === 'Incoming') {
doc.caller = {
label: getContact(doc.from)?.full_name || 'Unknown',
image: getContact(doc.from)?.image,
}
doc.receiver = {
label: getUser(doc.receiver).full_name,
image: getUser(doc.receiver).user_image,
}
} else {
doc.caller = {
label: getUser(doc.caller).full_name,
image: getUser(doc.caller).user_image,
}
doc.receiver = {
label: getContact(doc.to)?.full_name || 'Unknown',
image: getContact(doc.to)?.image,
}
}
})
return docs
},
})
function updateAssignedAgent(email) { function updateAssignedAgent(email) {
deal.data.lead_owner = email deal.data.lead_owner = email
updateDeal('lead_owner', email) updateDeal('lead_owner', email)

View File

@ -38,9 +38,9 @@
/> />
</template> </template>
</LayoutHeader> </LayoutHeader>
<div v-if="lead.data" class="flex h-full overflow-hidden"> <div v-if="lead?.data" class="flex h-full overflow-hidden">
<TabGroup as="div" class="flex flex-col flex-1" @change="onTabChange"> <TabGroup as="div" class="flex flex-1 flex-col" @change="onTabChange">
<TabList class="flex items-center gap-6 border-b pl-5 relative"> <TabList class="relative flex items-center gap-6 border-b pl-5">
<Tab <Tab
ref="tabRef" ref="tabRef"
as="template" as="template"
@ -49,7 +49,7 @@
v-slot="{ selected }" v-slot="{ selected }"
> >
<button <button
class="flex items-center gap-2 py-2.5 -mb-[1px] text-base text-gray-600 border-b border-transparent hover:text-gray-900 hover:border-gray-400 transition-all duration-300 ease-in-out" class="-mb-[1px] flex items-center gap-2 border-b border-transparent py-2.5 text-base text-gray-600 transition-all duration-300 ease-in-out hover:border-gray-400 hover:text-gray-900"
:class="{ 'text-gray-900': selected }" :class="{ 'text-gray-900': selected }"
> >
<component v-if="tab.icon" :is="tab.icon" class="h-5" /> <component v-if="tab.icon" :is="tab.icon" class="h-5" />
@ -58,39 +58,33 @@
</Tab> </Tab>
<div <div
ref="indicator" ref="indicator"
class="h-[1px] bg-gray-900 w-[82px] absolute -bottom-[1px]" class="absolute -bottom-[1px] h-[1px] w-[82px] bg-gray-900"
:style="{ left: `${indicatorLeftValue}px` }" :style="{ left: `${indicatorLeftValue}px` }"
/> />
</TabList> </TabList>
<TabPanels class="flex flex-1 overflow-hidden"> <TabPanels class="flex flex-1 overflow-hidden">
<TabPanel <TabPanel
class="flex-1 flex flex-col overflow-y-auto" class="flex flex-1 flex-col overflow-y-auto"
v-for="tab in tabs" v-for="tab in tabs"
:key="tab.label" :key="tab.label"
> >
<Activities <Activities :title="tab.label" v-model="lead" />
:title="tab.activityTitle"
:activities="tab.content"
v-model="lead"
@makeNote="(e) => showNote(e)"
@deleteNote="(e) => deleteNote(e)"
/>
</TabPanel> </TabPanel>
</TabPanels> </TabPanels>
</TabGroup> </TabGroup>
<div class="flex flex-col justify-between border-l w-[352px]"> <div class="flex w-[352px] flex-col justify-between border-l">
<div <div
class="flex items-center border-b px-5 py-2.5 h-[41px] font-semibold text-lg" class="flex h-[41px] items-center border-b px-5 py-2.5 text-lg font-semibold"
> >
About this lead About this lead
</div> </div>
<FileUploader @success="changeLeadImage" :validateFile="validateFile"> <FileUploader @success="changeLeadImage" :validateFile="validateFile">
<template #default="{ openFileSelector, error }"> <template #default="{ openFileSelector, error }">
<div class="flex gap-5 items-center justify-start p-5"> <div class="flex items-center justify-start gap-5 p-5">
<div class="relative w-[88px] h-[88px] group"> <div class="group relative h-[88px] w-[88px]">
<Avatar <Avatar
size="3xl" size="3xl"
class="w-[88px] h-[88px]" class="h-[88px] w-[88px]"
:label="lead.data.first_name" :label="lead.data.first_name"
:image="lead.data.image" :image="lead.data.image"
/> />
@ -113,19 +107,19 @@
class="!absolute bottom-0 left-0 right-0" class="!absolute bottom-0 left-0 right-0"
> >
<div <div
class="absolute bottom-0 left-0 right-0 rounded-b-full z-1 h-11 flex items-center justify-center pt-3 bg-black bg-opacity-40 cursor-pointer opacity-0 group-hover:opacity-100 duration-300 ease-in-out" class="z-1 absolute bottom-0 left-0 right-0 flex h-11 cursor-pointer items-center justify-center rounded-b-full bg-black bg-opacity-40 pt-3 opacity-0 duration-300 ease-in-out group-hover:opacity-100"
style=" style="
-webkit-clip-path: inset(12px 0 0 0); -webkit-clip-path: inset(12px 0 0 0);
clip-path: inset(12px 0 0 0); clip-path: inset(12px 0 0 0);
" "
> >
<CameraIcon class="h-6 w-6 text-white cursor-pointer" /> <CameraIcon class="h-6 w-6 cursor-pointer text-white" />
</div> </div>
</Dropdown> </Dropdown>
</div> </div>
<div class="flex flex-col gap-2.5 truncate"> <div class="flex flex-col gap-2.5 truncate">
<Tooltip :text="lead.data.lead_name"> <Tooltip :text="lead.data.lead_name">
<div class="font-medium text-2xl truncate"> <div class="truncate text-2xl font-medium">
{{ lead.data.lead_name }} {{ lead.data.lead_name }}
</div> </div>
</Tooltip> </Tooltip>
@ -155,7 +149,7 @@
</div> </div>
</template> </template>
</FileUploader> </FileUploader>
<div class="flex-1 flex flex-col justify-between overflow-hidden"> <div class="flex flex-1 flex-col justify-between overflow-hidden">
<div class="flex flex-col overflow-y-auto"> <div class="flex flex-col overflow-y-auto">
<div <div
v-for="(section, i) in detailSections" v-for="(section, i) in detailSections"
@ -163,9 +157,9 @@
class="flex flex-col" class="flex flex-col"
> >
<Toggler :is-opened="section.opened" v-slot="{ opened, toggle }"> <Toggler :is-opened="section.opened" v-slot="{ opened, toggle }">
<div class="sticky bg-white top-0 p-3 border-t z-10"> <div class="sticky top-0 z-10 border-t bg-white p-3">
<div <div
class="flex items-center gap-2 text-base font-semibold leading-5 px-2 cursor-pointer max-w-fit" class="flex max-w-fit cursor-pointer items-center gap-2 px-2 text-base font-semibold leading-5"
@click="toggle()" @click="toggle()"
> >
<FeatherIcon <FeatherIcon
@ -188,9 +182,9 @@
<div <div
v-for="field in section.fields" v-for="field in section.fields"
:key="field.name" :key="field.name"
class="flex items-center px-3 gap-2 text-base leading-5 last:mb-3" class="flex items-center gap-2 px-3 text-base leading-5 last:mb-3"
> >
<div class="text-gray-600 w-[106px]"> <div class="w-[106px] text-gray-600">
{{ field.label }} {{ field.label }}
</div> </div>
<div class="flex-1"> <div class="flex-1">
@ -242,7 +236,7 @@
variant="ghost" variant="ghost"
@click="togglePopover()" @click="togglePopover()"
:label="getUser(lead.data[field.name]).full_name" :label="getUser(lead.data[field.name]).full_name"
class="!justify-start w-full" class="w-full !justify-start"
> >
<template #prefix> <template #prefix>
<UserAvatar <UserAvatar
@ -270,7 +264,7 @@
<template #default="{ open }"> <template #default="{ open }">
<Button <Button
:label="lead.data[field.name]" :label="lead.data[field.name]"
class="justify-between w-full" class="w-full justify-between"
> >
<template #prefix> <template #prefix>
<IndicatorIcon <IndicatorIcon
@ -311,7 +305,6 @@
</div> </div>
</div> </div>
</div> </div>
<NoteModal v-model="showNoteModal" :note="note" @updateNote="updateNote" />
</template> </template>
<script setup> <script setup>
import ActivityIcon from '@/components/Icons/ActivityIcon.vue' import ActivityIcon from '@/components/Icons/ActivityIcon.vue'
@ -325,21 +318,18 @@ import Toggler from '@/components/Toggler.vue'
import Activities from '@/components/Activities.vue' import Activities from '@/components/Activities.vue'
import Breadcrumbs from '@/components/Breadcrumbs.vue' import Breadcrumbs from '@/components/Breadcrumbs.vue'
import UserAvatar from '@/components/UserAvatar.vue' import UserAvatar from '@/components/UserAvatar.vue'
import NoteModal from '@/components/NoteModal.vue'
import { TabGroup, TabList, Tab, TabPanels, TabPanel } from '@headlessui/vue' import { TabGroup, TabList, Tab, TabPanels, TabPanel } from '@headlessui/vue'
import { TransitionPresets, useTransition } from '@vueuse/core' import { TransitionPresets, useTransition } from '@vueuse/core'
import { import {
leadStatuses, leadStatuses,
statusDropdownOptions, statusDropdownOptions,
openWebsite, openWebsite,
secondsToDuration,
createToast, createToast,
} from '@/utils' } from '@/utils'
import { usersStore } from '@/stores/users' import { usersStore } from '@/stores/users'
import { contactsStore } from '@/stores/contacts' import { contactsStore } from '@/stores/contacts'
import { import {
createResource, createResource,
createListResource,
FileUploader, FileUploader,
ErrorMessage, ErrorMessage,
FeatherIcon, FeatherIcon,
@ -348,14 +338,13 @@ import {
Dropdown, Dropdown,
Tooltip, Tooltip,
Avatar, Avatar,
call,
} from 'frappe-ui' } from 'frappe-ui'
import { ref, computed } from 'vue' import { ref, computed } from 'vue'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
import CameraIcon from '../components/Icons/CameraIcon.vue' import CameraIcon from '../components/Icons/CameraIcon.vue'
const { getUser, users } = usersStore() const { getUser, users } = usersStore()
const { getContact, contacts } = contactsStore() const { contacts } = contactsStore()
const router = useRouter() const router = useRouter()
const props = defineProps({ const props = defineProps({
@ -411,49 +400,24 @@ const breadcrumbs = computed(() => {
return items return items
}) })
const tabs = computed(() => { const tabs = [
return [ {
{ label: 'Activity',
label: 'Activity', icon: ActivityIcon,
icon: ActivityIcon, },
content: all_activities(), {
activityTitle: 'Activity', label: 'Emails',
}, icon: EmailIcon,
{ },
label: 'Emails', {
icon: EmailIcon, label: 'Calls',
content: lead.data.activities.filter( icon: PhoneIcon,
(activity) => activity.activity_type === 'communication' },
), {
activityTitle: 'Emails', label: 'Notes',
}, icon: NoteIcon,
{ },
label: 'Calls', ]
icon: PhoneIcon,
content: calls.data,
activityTitle: 'Calls',
},
// {
// label: 'Tasks',
// icon: TaskIcon,
// activityTitle: 'Tasks',
// },
{
label: 'Notes',
icon: NoteIcon,
activityTitle: 'Notes',
content: notes.data,
},
]
})
function all_activities() {
if (!lead.data) return []
if (!calls.data) return lead.data.activities
return [...lead.data.activities, ...calls.data].sort(
(a, b) => new Date(b.creation) - new Date(a.creation)
)
}
function changeLeadImage(file) { function changeLeadImage(file) {
lead.data.image = file.file_url lead.data.image = file.file_url
@ -607,116 +571,6 @@ function convertToDeal() {
router.push({ name: 'Deal', params: { dealId: lead.data.name } }) router.push({ name: 'Deal', params: { dealId: lead.data.name } })
} }
const showNoteModal = ref(false)
const note = ref({
title: '',
content: '',
})
const notes = createListResource({
type: 'list',
doctype: 'CRM Note',
cache: ['Notes', props.leadId],
fields: ['name', 'title', 'content', 'owner', 'modified'],
filters: { lead: props.leadId },
orderBy: 'modified desc',
pageLength: 999,
auto: true,
})
function showNote(n) {
note.value = n || {
title: '',
content: '',
}
showNoteModal.value = true
}
async function deleteNote(name) {
await call('frappe.client.delete', {
doctype: 'CRM Note',
name,
})
notes.reload()
}
async function updateNote(note) {
if (note.name) {
let d = await call('frappe.client.set_value', {
doctype: 'CRM Note',
name: note.name,
fieldname: note,
})
if (d.name) {
notes.reload()
}
} else {
let d = await call('frappe.client.insert', {
doc: {
doctype: 'CRM Note',
title: note.title,
content: note.content,
lead: props.leadId,
},
})
if (d.name) {
notes.reload()
}
}
}
const calls = createListResource({
type: 'list',
doctype: 'CRM Call Log',
cache: ['Call Logs', props.leadId],
fields: [
'name',
'caller',
'receiver',
'from',
'to',
'duration',
'start_time',
'end_time',
'status',
'type',
'recording_url',
'creation',
'note',
],
filters: { lead: props.leadId },
orderBy: 'creation desc',
pageLength: 999,
auto: true,
transform: (docs) => {
docs.forEach((doc) => {
doc.activity_type =
doc.type === 'Incoming' ? 'incoming_call' : 'outgoing_call'
doc.duration = secondsToDuration(doc.duration)
if (doc.type === 'Incoming') {
doc.caller = {
label: getContact(doc.from)?.full_name || 'Unknown',
image: getContact(doc.from)?.image,
}
doc.receiver = {
label: getUser(doc.receiver).full_name,
image: getUser(doc.receiver).user_image,
}
} else {
doc.caller = {
label: getUser(doc.caller).full_name,
image: getUser(doc.caller).user_image,
}
doc.receiver = {
label: getContact(doc.to)?.full_name || 'Unknown',
image: getContact(doc.to)?.image,
}
}
})
return docs
},
})
function updateAssignedAgent(email) { function updateAssignedAgent(email) {
lead.data.lead_owner = email lead.data.lead_owner = email
updateLead('lead_owner', email) updateLead('lead_owner', email)