534 lines
15 KiB
Vue
534 lines
15 KiB
Vue
<template>
|
|
<LayoutHeader>
|
|
<template #left-header>
|
|
<Breadcrumbs :items="breadcrumbs">
|
|
<template #prefix="{ item }">
|
|
<Icon v-if="item.icon" :icon="item.icon" class="mr-2 h-4" />
|
|
</template>
|
|
</Breadcrumbs>
|
|
</template>
|
|
<template v-if="!errorTitle" #right-header>
|
|
<CustomActions
|
|
v-if="document._actions?.length"
|
|
:actions="document._actions"
|
|
/>
|
|
<CustomActions
|
|
v-if="document.actions?.length"
|
|
:actions="document.actions"
|
|
/>
|
|
<AssignTo v-model="assignees.data" :data="doc" doctype="CRM Lead" />
|
|
<Dropdown
|
|
v-if="doc"
|
|
:options="
|
|
statusOptions(
|
|
'lead',
|
|
document.statuses?.length ? document.statuses : document._statuses,
|
|
triggerStatusChange,
|
|
)
|
|
"
|
|
>
|
|
<template #default="{ open }">
|
|
<Button v-if="doc.status" :label="doc.status">
|
|
<template #prefix>
|
|
<IndicatorIcon :class="getLeadStatus(doc.status).color" />
|
|
</template>
|
|
<template #suffix>
|
|
<FeatherIcon
|
|
:name="open ? 'chevron-up' : 'chevron-down'"
|
|
class="h-4"
|
|
/>
|
|
</template>
|
|
</Button>
|
|
</template>
|
|
</Dropdown>
|
|
<Button
|
|
:label="__('Convert to Deal')"
|
|
variant="solid"
|
|
@click="showConvertToDealModal = true"
|
|
/>
|
|
</template>
|
|
</LayoutHeader>
|
|
<div v-if="doc.name" class="flex h-full overflow-hidden">
|
|
<Tabs as="div" v-model="tabIndex" :tabs="tabs">
|
|
<template #tab-panel>
|
|
<Activities
|
|
ref="activities"
|
|
doctype="CRM Lead"
|
|
:docname="doc.name"
|
|
:tabs="tabs"
|
|
v-model:reload="reload"
|
|
v-model:tabIndex="tabIndex"
|
|
@beforeSave="saveChanges"
|
|
@afterSave="reloadAssignees"
|
|
/>
|
|
</template>
|
|
</Tabs>
|
|
<Resizer class="flex flex-col justify-between border-l" side="right">
|
|
<div
|
|
class="flex h-10.5 cursor-copy items-center border-b px-5 py-2.5 text-lg font-medium text-ink-gray-9"
|
|
@click="copyToClipboard(doc.name)"
|
|
>
|
|
{{ __(doc.name) }}
|
|
</div>
|
|
<FileUploader
|
|
@success="(file) => updateField('image', file.file_url)"
|
|
:validateFile="validateIsImageFile"
|
|
>
|
|
<template #default="{ openFileSelector, error }">
|
|
<div class="flex items-center justify-start gap-5 border-b p-5">
|
|
<div class="group relative size-12">
|
|
<Avatar
|
|
size="3xl"
|
|
class="size-12"
|
|
:label="title"
|
|
:image="doc.image"
|
|
/>
|
|
<component
|
|
:is="doc.image ? Dropdown : 'div'"
|
|
v-bind="
|
|
doc.image
|
|
? {
|
|
options: [
|
|
{
|
|
icon: 'upload',
|
|
label: doc.image
|
|
? __('Change image')
|
|
: __('Upload image'),
|
|
onClick: openFileSelector,
|
|
},
|
|
{
|
|
icon: 'trash-2',
|
|
label: __('Remove image'),
|
|
onClick: () => updateField('image', ''),
|
|
},
|
|
],
|
|
}
|
|
: { onClick: openFileSelector }
|
|
"
|
|
class="!absolute bottom-0 left-0 right-0"
|
|
>
|
|
<div
|
|
class="z-1 absolute bottom-0.5 left-0 right-0.5 flex h-9 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="
|
|
-webkit-clip-path: inset(12px 0 0 0);
|
|
clip-path: inset(12px 0 0 0);
|
|
"
|
|
>
|
|
<CameraIcon class="size-4 cursor-pointer text-white" />
|
|
</div>
|
|
</component>
|
|
</div>
|
|
<div class="flex flex-col gap-2.5 truncate">
|
|
<Tooltip :text="doc.lead_name || __('Set first name')">
|
|
<div class="truncate text-2xl font-medium text-ink-gray-9">
|
|
{{ title }}
|
|
</div>
|
|
</Tooltip>
|
|
<div class="flex gap-1.5">
|
|
<Tooltip v-if="callEnabled" :text="__('Make a call')">
|
|
<div>
|
|
<Button
|
|
@click="
|
|
() =>
|
|
doc.mobile_no
|
|
? makeCall(doc.mobile_no)
|
|
: toast.error(__('No phone number set'))
|
|
"
|
|
>
|
|
<template #icon>
|
|
<PhoneIcon />
|
|
</template>
|
|
</Button>
|
|
</div>
|
|
</Tooltip>
|
|
<Tooltip :text="__('Send an email')">
|
|
<div>
|
|
<Button
|
|
@click="
|
|
doc.email
|
|
? openEmailBox()
|
|
: toast.error(__('No email set'))
|
|
"
|
|
>
|
|
<template #icon>
|
|
<Email2Icon />
|
|
</template>
|
|
</Button>
|
|
</div>
|
|
</Tooltip>
|
|
<Tooltip :text="__('Go to website')">
|
|
<div>
|
|
<Button
|
|
@click="
|
|
doc.website
|
|
? openWebsite(doc.website)
|
|
: toast.error(__('No website set'))
|
|
"
|
|
>
|
|
<template #icon>
|
|
<LinkIcon />
|
|
</template>
|
|
</Button>
|
|
</div>
|
|
</Tooltip>
|
|
<Tooltip :text="__('Attach a file')">
|
|
<div>
|
|
<Button @click="showFilesUploader = true">
|
|
<template #icon>
|
|
<AttachmentIcon />
|
|
</template>
|
|
</Button>
|
|
</div>
|
|
</Tooltip>
|
|
<<<<<<< HEAD
|
|
=======
|
|
<Tooltip :text="__('Delete')">
|
|
<div>
|
|
<Button
|
|
@click="deleteLeadWithModal"
|
|
variant="subtle"
|
|
theme="red"
|
|
icon="trash-2"
|
|
/>
|
|
</div>
|
|
</Tooltip>
|
|
>>>>>>> 0144bc10 (fix: use document.doc instead of lead.data/deal.data)
|
|
</div>
|
|
<ErrorMessage :message="__(error)" />
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</FileUploader>
|
|
<SLASection
|
|
v-if="doc.sla_status"
|
|
v-model="doc"
|
|
@updateField="updateField"
|
|
/>
|
|
<div
|
|
v-if="sections.data"
|
|
class="flex flex-1 flex-col justify-between overflow-hidden"
|
|
>
|
|
<SidePanelLayout
|
|
:sections="sections.data"
|
|
doctype="CRM Lead"
|
|
:docname="doc.name"
|
|
@reload="sections.reload"
|
|
@afterFieldChange="reloadAssignees"
|
|
/>
|
|
</div>
|
|
</Resizer>
|
|
</div>
|
|
<ErrorPage
|
|
v-else-if="errorTitle"
|
|
:errorTitle="errorTitle"
|
|
:errorMessage="errorMessage"
|
|
/>
|
|
<ConvertToDealModal
|
|
v-if="showConvertToDealModal"
|
|
v-model="showConvertToDealModal"
|
|
:lead="doc"
|
|
/>
|
|
<FilesUploader
|
|
v-if="doc?.name"
|
|
v-model="showFilesUploader"
|
|
doctype="CRM Lead"
|
|
:docname="doc.name"
|
|
@after="
|
|
() => {
|
|
activities?.all_activities?.reload()
|
|
changeTabTo('attachments')
|
|
}
|
|
"
|
|
/>
|
|
<DeleteLinkedDocModal
|
|
v-if="showDeleteLinkedDocModal"
|
|
v-model="showDeleteLinkedDocModal"
|
|
:doctype="'CRM Lead'"
|
|
:docname="leadId"
|
|
name="Leads"
|
|
/>
|
|
</template>
|
|
<script setup>
|
|
import ErrorPage from '@/components/ErrorPage.vue'
|
|
import Icon from '@/components/Icon.vue'
|
|
import Resizer from '@/components/Resizer.vue'
|
|
import ActivityIcon from '@/components/Icons/ActivityIcon.vue'
|
|
import EmailIcon from '@/components/Icons/EmailIcon.vue'
|
|
import Email2Icon from '@/components/Icons/Email2Icon.vue'
|
|
import CommentIcon from '@/components/Icons/CommentIcon.vue'
|
|
import DetailsIcon from '@/components/Icons/DetailsIcon.vue'
|
|
import PhoneIcon from '@/components/Icons/PhoneIcon.vue'
|
|
import TaskIcon from '@/components/Icons/TaskIcon.vue'
|
|
import NoteIcon from '@/components/Icons/NoteIcon.vue'
|
|
import WhatsAppIcon from '@/components/Icons/WhatsAppIcon.vue'
|
|
import IndicatorIcon from '@/components/Icons/IndicatorIcon.vue'
|
|
import CameraIcon from '@/components/Icons/CameraIcon.vue'
|
|
import LinkIcon from '@/components/Icons/LinkIcon.vue'
|
|
import AttachmentIcon from '@/components/Icons/AttachmentIcon.vue'
|
|
import LayoutHeader from '@/components/LayoutHeader.vue'
|
|
import Activities from '@/components/Activities/Activities.vue'
|
|
import AssignTo from '@/components/AssignTo.vue'
|
|
import FilesUploader from '@/components/FilesUploader/FilesUploader.vue'
|
|
import SidePanelLayout from '@/components/SidePanelLayout.vue'
|
|
import SLASection from '@/components/SLASection.vue'
|
|
import CustomActions from '@/components/CustomActions.vue'
|
|
import ConvertToDealModal from '@/components/Modals/ConvertToDealModal.vue'
|
|
import {
|
|
openWebsite,
|
|
setupCustomizations,
|
|
copyToClipboard,
|
|
validateIsImageFile,
|
|
} from '@/utils'
|
|
import { getView } from '@/utils/view'
|
|
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,
|
|
FileUploader,
|
|
Dropdown,
|
|
Tooltip,
|
|
Avatar,
|
|
Tabs,
|
|
Breadcrumbs,
|
|
call,
|
|
usePageMeta,
|
|
toast,
|
|
} from 'frappe-ui'
|
|
import { ref, computed, onMounted, watch, nextTick } from 'vue'
|
|
import { useRouter, useRoute } from 'vue-router'
|
|
import { useActiveTabManager } from '@/composables/useActiveTabManager'
|
|
|
|
const { brand } = getSettings()
|
|
const { $dialog, $socket, makeCall } = globalStore()
|
|
const { statusOptions, getLeadStatus } = statusesStore()
|
|
const { doctypeMeta } = getMeta('CRM Lead')
|
|
|
|
const route = useRoute()
|
|
const router = useRouter()
|
|
|
|
const props = defineProps({
|
|
leadId: {
|
|
type: String,
|
|
required: true,
|
|
},
|
|
})
|
|
|
|
const errorTitle = ref('')
|
|
const errorMessage = ref('')
|
|
const showDeleteLinkedDocModal = ref(false)
|
|
const showConvertToDealModal = ref(false)
|
|
|
|
const { triggerOnChange, assignees, document, scripts, error } = useDocument(
|
|
'CRM Lead',
|
|
props.leadId,
|
|
)
|
|
|
|
const doc = computed(() => document.doc || {})
|
|
|
|
watch(error, (err) => {
|
|
if (err) {
|
|
errorTitle.value = __(
|
|
err.exc_type == 'DoesNotExistError'
|
|
? 'Document not found'
|
|
: 'Error occurred',
|
|
)
|
|
errorMessage.value = __(err.messages?.[0] || 'An error occurred')
|
|
} else {
|
|
errorTitle.value = ''
|
|
errorMessage.value = ''
|
|
}
|
|
})
|
|
|
|
watch(
|
|
() => document.doc,
|
|
async (_doc) => {
|
|
if (scripts.data?.length) {
|
|
let s = await setupCustomizations(scripts.data, {
|
|
doc: _doc,
|
|
$dialog,
|
|
$socket,
|
|
router,
|
|
toast,
|
|
updateField,
|
|
createToast: toast.create,
|
|
deleteDoc: deleteLeadWithModal,
|
|
call,
|
|
})
|
|
document._actions = s.actions || []
|
|
document._statuses = s.statuses || []
|
|
}
|
|
},
|
|
{ once: true },
|
|
)
|
|
|
|
const reload = ref(false)
|
|
const showFilesUploader = ref(false)
|
|
|
|
const breadcrumbs = computed(() => {
|
|
let items = [{ label: __('Leads'), route: { name: 'Leads' } }]
|
|
|
|
if (route.query.view || route.query.viewType) {
|
|
let view = getView(route.query.view, route.query.viewType, 'CRM Lead')
|
|
if (view) {
|
|
items.push({
|
|
label: __(view.label),
|
|
icon: view.icon,
|
|
route: {
|
|
name: 'Leads',
|
|
params: { viewType: route.query.viewType },
|
|
query: { view: route.query.view },
|
|
},
|
|
})
|
|
}
|
|
}
|
|
|
|
items.push({
|
|
label: title.value,
|
|
route: { name: 'Lead', params: { leadId: props.leadId } },
|
|
})
|
|
return items
|
|
})
|
|
|
|
const title = computed(() => {
|
|
let t = doctypeMeta['CRM Lead']?.title_field || 'name'
|
|
return doc?.[t] || props.leadId
|
|
})
|
|
|
|
usePageMeta(() => {
|
|
return {
|
|
title: title.value,
|
|
icon: brand.favicon,
|
|
}
|
|
})
|
|
|
|
const tabs = computed(() => {
|
|
let tabOptions = [
|
|
{
|
|
name: 'Activity',
|
|
label: __('Activity'),
|
|
icon: ActivityIcon,
|
|
},
|
|
{
|
|
name: 'Emails',
|
|
label: __('Emails'),
|
|
icon: EmailIcon,
|
|
},
|
|
{
|
|
name: 'Comments',
|
|
label: __('Comments'),
|
|
icon: CommentIcon,
|
|
},
|
|
{
|
|
name: 'Data',
|
|
label: __('Data'),
|
|
icon: DetailsIcon,
|
|
},
|
|
{
|
|
name: 'Calls',
|
|
label: __('Calls'),
|
|
icon: PhoneIcon,
|
|
},
|
|
{
|
|
name: 'Tasks',
|
|
label: __('Tasks'),
|
|
icon: TaskIcon,
|
|
},
|
|
{
|
|
name: 'Notes',
|
|
label: __('Notes'),
|
|
icon: NoteIcon,
|
|
},
|
|
{
|
|
name: 'Attachments',
|
|
label: __('Attachments'),
|
|
icon: AttachmentIcon,
|
|
},
|
|
{
|
|
name: 'WhatsApp',
|
|
label: __('WhatsApp'),
|
|
icon: WhatsAppIcon,
|
|
condition: () => whatsappEnabled.value,
|
|
},
|
|
]
|
|
return tabOptions.filter((tab) => (tab.condition ? tab.condition() : true))
|
|
})
|
|
|
|
const { tabIndex, changeTabTo } = useActiveTabManager(tabs, 'lastLeadTab')
|
|
|
|
watch(tabs, (value) => {
|
|
if (value && route.params.tabName) {
|
|
let index = value.findIndex(
|
|
(tab) => tab.name.toLowerCase() === route.params.tabName.toLowerCase(),
|
|
)
|
|
if (index !== -1) {
|
|
tabIndex.value = index
|
|
}
|
|
}
|
|
})
|
|
|
|
const sections = createResource({
|
|
url: 'crm.fcrm.doctype.crm_fields_layout.crm_fields_layout.get_sidepanel_sections',
|
|
cache: ['sidePanelSections', 'CRM Lead'],
|
|
params: { doctype: 'CRM Lead' },
|
|
auto: true,
|
|
})
|
|
|
|
async function triggerStatusChange(value) {
|
|
await triggerOnChange('status', value)
|
|
document.save.submit()
|
|
}
|
|
|
|
function updateField(name, value) {
|
|
value = Array.isArray(name) ? '' : value
|
|
let oldValues = Array.isArray(name) ? {} : doc.value[name]
|
|
|
|
if (Array.isArray(name)) {
|
|
name.forEach((field) => (doc.value[field] = value))
|
|
} else {
|
|
doc.value[name] = value
|
|
}
|
|
|
|
document.save.submit(null, {
|
|
onSuccess: () => (reload.value = true),
|
|
onError: (err) => {
|
|
if (Array.isArray(name)) {
|
|
name.forEach((field) => (doc.value[field] = oldValues[field]))
|
|
} else {
|
|
doc.value[name] = oldValues
|
|
}
|
|
toast.error(err.messages?.[0] || __('Error updating field'))
|
|
},
|
|
})
|
|
}
|
|
|
|
async function deleteLeadWithModal() {
|
|
showDeleteLinkedDocModal.value = true
|
|
}
|
|
|
|
const activities = ref(null)
|
|
|
|
function openEmailBox() {
|
|
let currentTab = tabs.value[tabIndex.value]
|
|
if (!['Emails', 'Comments', 'Activities'].includes(currentTab.name)) {
|
|
activities.value.changeTabTo('emails')
|
|
}
|
|
nextTick(() => (activities.value.emailBox.show = true))
|
|
}
|
|
|
|
function saveChanges(data) {
|
|
document.save.submit(null, {
|
|
onSuccess: () => reloadAssignees(data),
|
|
})
|
|
}
|
|
|
|
function reloadAssignees(data) {
|
|
if (data?.hasOwnProperty('lead_owner')) {
|
|
assignees.reload()
|
|
}
|
|
}
|
|
</script>
|