1
0
forked from test/crm

fix: show whatsapp tab and action only when whatsapp is enabled

This commit is contained in:
Shariq Ansari 2024-04-24 15:52:54 +05:30
parent 0e5dc23ccf
commit 233011aab3
3 changed files with 111 additions and 96 deletions

View File

@ -47,37 +47,7 @@
<span>{{ __('New WhatsApp Message') }}</span> <span>{{ __('New WhatsApp Message') }}</span>
</Button> </Button>
</div> </div>
<Dropdown <Dropdown v-else :options="defaultActions" @click.stop>
v-else
:options="[
{
icon: h(EmailIcon, { class: 'h-4 w-4' }),
label: __('New Email'),
onClick: () => ($refs.emailBox.show = true),
},
{
icon: h(PhoneIcon, { class: 'h-4 w-4' }),
label: __('Make a Call'),
onClick: () => makeCall(doc.data.mobile_no),
},
{
icon: h(NoteIcon, { class: 'h-4 w-4' }),
label: __('New Note'),
onClick: () => showNote(),
},
{
icon: h(TaskIcon, { class: 'h-4 w-4' }),
label: __('New Task'),
onClick: () => showTask(),
},
{
icon: h(WhatsAppIcon, { class: 'h-4 w-4' }),
label: __('New WhatsApp Message'),
onClick: () => (tabIndex = 5),
},
]"
@click.stop
>
<template v-slot="{ open }"> <template v-slot="{ open }">
<Button variant="solid" class="flex items-center gap-1"> <Button variant="solid" class="flex items-center gap-1">
<template #prefix> <template #prefix>
@ -844,6 +814,7 @@ import {
import { globalStore } from '@/stores/global' import { globalStore } from '@/stores/global'
import { usersStore } from '@/stores/users' import { usersStore } from '@/stores/users'
import { contactsStore } from '@/stores/contacts' import { contactsStore } from '@/stores/contacts'
import { whatsappEnabled } from '@/stores/settings'
import { import {
Button, Button,
Tooltip, Tooltip,
@ -851,7 +822,6 @@ import {
TextEditor, TextEditor,
Avatar, Avatar,
createResource, createResource,
createListResource,
call, call,
} from 'frappe-ui' } from 'frappe-ui'
import { useElementVisibility } from '@vueuse/core' import { useElementVisibility } from '@vueuse/core'
@ -977,6 +947,40 @@ function sendTemplate(template) {
const replyMessage = ref({}) const replyMessage = ref({})
const defaultActions = computed(() => {
let actions = [
{
icon: h(EmailIcon, { class: 'h-4 w-4' }),
label: __('New Email'),
onClick: () => (emailBox.value.show = true),
},
{
icon: h(PhoneIcon, { class: 'h-4 w-4' }),
label: __('Make a Call'),
onClick: () => makeCall(doc.value.data.mobile_no),
},
{
icon: h(NoteIcon, { class: 'h-4 w-4' }),
label: __('New Note'),
onClick: () => showNote(),
},
{
icon: h(TaskIcon, { class: 'h-4 w-4' }),
label: __('New Task'),
onClick: () => showTask(),
},
{
icon: h(WhatsAppIcon, { class: 'h-4 w-4' }),
label: __('New WhatsApp Message'),
onClick: () => (tabIndex.value = 5),
condition: () => Boolean(whatsappEnabled.value),
},
]
return actions.filter((action) =>
action.condition ? action.condition() : true
)
})
function get_activities() { function get_activities() {
if (!all_activities.data?.versions) return [] if (!all_activities.data?.versions) return []
if (!all_activities.data?.calls.length) if (!all_activities.data?.calls.length)

View File

@ -320,6 +320,7 @@ import {
import { globalStore } from '@/stores/global' import { globalStore } from '@/stores/global'
import { organizationsStore } from '@/stores/organizations' import { organizationsStore } from '@/stores/organizations'
import { statusesStore } from '@/stores/statuses' import { statusesStore } from '@/stores/statuses'
import { whatsappEnabled } from '@/stores/settings'
import { import {
createResource, createResource,
Dropdown, Dropdown,
@ -435,7 +436,8 @@ const breadcrumbs = computed(() => {
}) })
const tabIndex = ref(0) const tabIndex = ref(0)
const tabs = [ const tabs = computed(() => {
let tabOptions = [
{ {
name: 'Activity', name: 'Activity',
label: __('Activity'), label: __('Activity'),
@ -465,8 +467,11 @@ const tabs = [
name: 'WhatsApp', name: 'WhatsApp',
label: __('WhatsApp'), label: __('WhatsApp'),
icon: WhatsAppIcon, icon: WhatsAppIcon,
condition: () => Boolean(whatsappEnabled.value),
}, },
] ]
return tabOptions.filter((tab) => (tab.condition ? tab.condition() : true))
})
const detailSections = computed(() => { const detailSections = computed(() => {
let data = deal.data let data = deal.data

View File

@ -287,6 +287,7 @@ import { globalStore } from '@/stores/global'
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'
import { whatsappEnabled } from '@/stores/settings'
import { import {
createResource, createResource,
FileUploader, FileUploader,
@ -399,7 +400,9 @@ const breadcrumbs = computed(() => {
}) })
const tabIndex = ref(0) const tabIndex = ref(0)
const tabs = [
const tabs = computed(() => {
let tabOptions = [
{ {
name: 'Activity', name: 'Activity',
label: __('Activity'), label: __('Activity'),
@ -429,8 +432,11 @@ const tabs = [
name: 'WhatsApp', name: 'WhatsApp',
label: __('WhatsApp'), label: __('WhatsApp'),
icon: WhatsAppIcon, icon: WhatsAppIcon,
}, condition: () => Boolean(whatsappEnabled.value),
}
] ]
return tabOptions.filter((tab) => (tab.condition ? tab.condition() : true))
})
function validateFile(file) { function validateFile(file) {
let extn = file.name.split('.').pop().toLowerCase() let extn = file.name.split('.').pop().toLowerCase()