fix: show different call status

This commit is contained in:
Shariq Ansari 2025-01-15 16:08:04 +05:30
parent a716bdf0da
commit 591e126911

View File

@ -2,14 +2,14 @@
<div> <div>
<div <div
v-show="showSmallCallPopup" v-show="showSmallCallPopup"
class="ml-2 flex cursor-pointer select-none items-center justify-between gap-2 rounded-full bg-surface-gray-7 px-1.5 py-[7px] text-base text-ink-gray-2" class="ml-2 flex cursor-pointer select-none items-center justify-between gap-2 rounded-full bg-surface-gray-7 px-2 py-[7px] text-base text-ink-gray-2"
@click="toggleCallPopup" @click="toggleCallPopup"
> >
<div <div
class="flex justify-center items-center size-5 rounded-full bg-surface-gray-6" class="flex justify-center items-center size-5 rounded-full bg-surface-gray-6"
> >
<Avatar <Avatar
v-if="contact.image" v-if="contact?.image"
:image="contact.image" :image="contact.image"
:label="contact.full_name" :label="contact.full_name"
class="size-3" class="size-3"
@ -17,26 +17,36 @@
<AvatarIcon v-else class="size-3" /> <AvatarIcon v-else class="size-3" />
</div> </div>
<div class="text-base font-medium"> <div class="text-base font-medium">
<span class="">{{ phoneNumber }}</span> <span
<span class="font-normal text-ink-gray-4"> · </span> v-if="
callStatus == 'Calling...' ||
callStatus == 'Ringing...' ||
callStatus == 'Incoming Call'
"
class="font-normal text-ink-gray-4 mr-1"
>
{{ callStatus }}
</span>
<span>{{ phoneNumber }}</span>
<span <span
v-if="callStatus == 'In Progress'" v-if="callStatus == 'In Progress'"
class="font-normal text-ink-gray-4" class="font-normal text-ink-gray-4"
> >
00:38 <span> · </span>00:38
</span> </span>
<span v-else class="font-normal text-ink-gray-4">{{ callStatus }}</span> <span
</div> v-else-if="callStatus == 'Call Ended' || callStatus == 'No Answer'"
<Button class="font-normal text-ink-gray-4"
variant="solid" :class="{
theme="red" 'text-red-700':
class="text-white !size-5 rounded-full" callStatus == 'Call Ended' || callStatus == 'No Answer',
@click="endCall" }"
> >
<template #icon> <span class="text-ink-gray-4"> · </span>
<PhoneIcon class="w-3 h-3 rotate-[135deg]" /> <span>{{ callStatus }}</span>
</template> <span v-if="callStatus == 'Call Ended'"> <span> · </span>00:38 </span>
</Button> </span>
</div>
</div> </div>
<Dialog <Dialog
v-model="showCallModal" v-model="showCallModal"
@ -68,10 +78,20 @@
class="fixed z-20 w-[280px] min-h-44 flex gap-2 cursor-move select-none flex-col rounded-lg bg-surface-gray-7 p-4 pt-2.5 text-ink-gray-2 shadow-2xl" class="fixed z-20 w-[280px] min-h-44 flex gap-2 cursor-move select-none flex-col rounded-lg bg-surface-gray-7 p-4 pt-2.5 text-ink-gray-2 shadow-2xl"
:style="style" :style="style"
> >
<!-- <pre>{{ callData }}</pre> -->
<div class="header flex items-center justify-between gap-2 text-base"> <div class="header flex items-center justify-between gap-2 text-base">
<div v-if="callStatus == 'In Progress'">00:38</div> <div v-if="callStatus == 'In Progress'">00:38</div>
<div
v-else-if="callStatus == 'Call Ended' || callStatus == 'No Answer'"
:class="{
'text-red-700':
callStatus == 'Call Ended' || callStatus == 'No Answer',
}"
>
<span>{{ __(callStatus) }}</span>
<span v-if="callStatus == 'Call Ended'"><span> · </span>00:38</span>
</div>
<div v-else>{{ __(callStatus) }}</div> <div v-else>{{ __(callStatus) }}</div>
<div class="flex">
<Button <Button
@click="toggleCallPopup" @click="toggleCallPopup"
class="bg-surface-gray-7 text-ink-white hover:bg-surface-gray-6" class="bg-surface-gray-7 text-ink-white hover:bg-surface-gray-6"
@ -81,12 +101,21 @@
<MinimizeIcon class="h-4 w-4 cursor-pointer" /> <MinimizeIcon class="h-4 w-4 cursor-pointer" />
</template> </template>
</Button> </Button>
<Button
v-if="callStatus == 'Call Ended' || callStatus == 'No Answer'"
@click="closeCallPopup"
class="bg-surface-gray-7 text-ink-white hover:bg-surface-gray-6"
icon="x"
size="md"
/>
</div>
</div> </div>
<div class="body flex-1"> <div class="body flex-1">
<div v-if="showNote" class="h-[294px] text-base">{{ note }}</div> <div v-if="showNote" class="h-[294px] text-base">{{ note }}</div>
<div v-else-if="showTask" class="h-[294px] text-base">{{ task }}</div>
<div v-else class="flex items-center gap-3"> <div v-else class="flex items-center gap-3">
<Avatar <Avatar
v-if="contact.image" v-if="contact?.image"
:image="contact.image" :image="contact.image"
:label="contact.full_name" :label="contact.full_name"
class="!size-8" class="!size-8"
@ -97,7 +126,7 @@
> >
<AvatarIcon class="size-4" /> <AvatarIcon class="size-4" />
</div> </div>
<div v-if="contact.full_name" class="flex flex-col gap-1.5"> <div v-if="contact?.full_name" class="flex flex-col gap-1.5">
<div class="text-lg font-medium">{{ contact.full_name }}</div> <div class="text-lg font-medium">{{ contact.full_name }}</div>
<div class="text-base text-ink-gray-6">{{ phoneNumber }}</div> <div class="text-base text-ink-gray-6">{{ phoneNumber }}</div>
</div> </div>
@ -106,12 +135,6 @@
</div> </div>
<div class="footer flex justify-between gap-2"> <div class="footer flex justify-between gap-2">
<div class="flex gap-2"> <div class="flex gap-2">
<Button
class="bg-surface-gray-6 text-ink-white hover:bg-surface-gray-5"
:icon="mute ? 'mic-off' : 'mic'"
size="md"
@click="toggleMute"
/>
<Button <Button
class="bg-surface-gray-6 text-ink-white hover:bg-surface-gray-5" class="bg-surface-gray-6 text-ink-white hover:bg-surface-gray-5"
size="md" size="md"
@ -122,36 +145,29 @@
</template> </template>
</Button> </Button>
<Button <Button
:icon="'more-horizontal'"
class="bg-surface-gray-6 text-ink-white hover:bg-surface-gray-5" class="bg-surface-gray-6 text-ink-white hover:bg-surface-gray-5"
size="md" size="md"
/> @click="showTaskWindow"
</div>
<Button
variant="solid"
theme="red"
class="text-white"
size="md"
@click="endCall"
> >
<template #icon> <template #icon>
<PhoneIcon class="w-4 h-4 rotate-[135deg]" /> <TaskIcon class="w-4 h-4" />
</template> </template>
</Button> </Button>
</div> </div>
</div> </div>
</div> </div>
</div>
</template> </template>
<script setup> <script setup>
import AvatarIcon from '@/components/Icons/AvatarIcon.vue' import AvatarIcon from '@/components/Icons/AvatarIcon.vue'
import MinimizeIcon from '@/components/Icons/MinimizeIcon.vue' import MinimizeIcon from '@/components/Icons/MinimizeIcon.vue'
import NoteIcon from '@/components/Icons/NoteIcon.vue' import NoteIcon from '@/components/Icons/NoteIcon.vue'
import PhoneIcon from '@/components/Icons/PhoneIcon.vue' import TaskIcon from '@/components/Icons/TaskIcon.vue'
import { Button, Dialog, FormControl, call, Avatar } from 'frappe-ui' import { Button, Dialog, FormControl, call, Avatar } from 'frappe-ui'
import { globalStore } from '@/stores/global' import { globalStore } from '@/stores/global'
import { contactsStore } from '@/stores/contacts' import { contactsStore } from '@/stores/contacts'
import { useDraggable, useWindowSize } from '@vueuse/core' import { useDraggable, useWindowSize } from '@vueuse/core'
import { ref, onBeforeUnmount, onMounted } from 'vue' import { ref, computed, onBeforeUnmount, onMounted } from 'vue'
const { getContact, getLeadContact } = contactsStore() const { getContact, getLeadContact } = contactsStore()
const { $socket, setMakeCall } = globalStore() const { $socket, setMakeCall } = globalStore()
@ -178,19 +194,22 @@ let { style } = useDraggable(callPopup, {
const showCallModal = ref(false) const showCallModal = ref(false)
const callStatus = ref('') const callStatus = ref('')
const phoneNumber = ref('09821259504') const phoneNumber = ref('')
const callData = ref(null) const callData = ref(null)
const contact = ref({ const contact = computed(() => {
if (!phoneNumber.value) {
return {
full_name: '', full_name: '',
mobile_no: '', image: '',
})
const mute = ref(false)
function toggleMute() {
mute.value = !mute.value
} }
}
let _contact = getContact(phoneNumber.value)
if (!_contact) {
_contact = getLeadContact(phoneNumber.value)
}
return _contact
})
const note = ref( const note = ref(
'This is a note for the call. This is a note for the call. This is a note for the call. This is a note for the call.', 'This is a note for the call. This is a note for the call. This is a note for the call. This is a note for the call.',
@ -200,11 +219,33 @@ const showNote = ref(false)
function showNoteWindow() { function showNoteWindow() {
showNote.value = !showNote.value showNote.value = !showNote.value
if (!showTask.value) {
updateWindowHeight(showNote.value)
}
if (showNote.value) {
showTask.value = false
}
}
const task = ref('This is a task for the call. This is a task for the call.')
const showTask = ref(false)
function showTaskWindow() {
showTask.value = !showTask.value
if (!showNote.value) {
updateWindowHeight(showTask.value)
}
if (showTask.value) {
showNote.value = false
}
}
function updateWindowHeight(condition) {
let top = parseInt(callPopup.value.style.top) let top = parseInt(callPopup.value.style.top)
let updatedTop = 0 let updatedTop = 0
updatedTop = showNote.value ? top - 224 : top + 224 updatedTop = condition ? top - 224 : top + 224
if (updatedTop < 0) { if (updatedTop < 0) {
updatedTop = 10 updatedTop = 10
@ -219,29 +260,15 @@ function showMakeCallModal(number) {
} }
function makeCall() { function makeCall() {
contact.value = getContact(phoneNumber.value)
if (!contact.value) {
contact.value = getLeadContact(phoneNumber.value)
}
showCallModal.value = false showCallModal.value = false
callStatus.value = 'Calling...' callStatus.value = 'Calling...'
showCallPopup.value = true showCallPopup.value = true
call('crm.integrations.exotel.handler.make_a_call', { call('crm.integrations.exotel.handler.make_a_call', {
to_number: phoneNumber.value, to_number: phoneNumber.value,
from_number: '07666980887',
caller_id: '08047091710',
}) })
} }
function endCall() {
callStatus.value = ''
showCallPopup.value = false
showSmallCallPopup.value = false
note.value = ''
}
onBeforeUnmount(() => { onBeforeUnmount(() => {
$socket.off('exotel_call') $socket.off('exotel_call')
}) })
@ -251,6 +278,25 @@ onMounted(() => {
callData.value = data callData.value = data
console.log(data) console.log(data)
callStatus.value = updateStatus(data)
if (!showCallPopup.value && !showSmallCallPopup.value) {
showCallPopup.value = true
}
})
setMakeCall(showMakeCallModal)
})
function closeCallPopup() {
showCallPopup.value = false
showSmallCallPopup.value = false
note.value = ''
task.value = ''
}
function updateStatus(data) {
// outgoing call
if ( if (
data.EventType == 'answered' && data.EventType == 'answered' &&
data.Direction == 'outbound-api' && data.Direction == 'outbound-api' &&
@ -258,49 +304,35 @@ onMounted(() => {
data['Legs[0][Status]'] == 'in-progress' && data['Legs[0][Status]'] == 'in-progress' &&
data['Legs[1][Status]'] == '' data['Legs[1][Status]'] == ''
) { ) {
callStatus.value = 'Ringing...' return 'Ringing...'
} else if ( } else if (
data.EventType == 'answered' && data.EventType == 'answered' &&
data.Direction == 'outbound-api' && data.Direction == 'outbound-api' &&
data.Status == 'in-progress' && data.Status == 'in-progress' &&
data['Legs[1][Status]'] == 'in-progress' data['Legs[1][Status]'] == 'in-progress'
) { ) {
callStatus.value = 'In Progress' return 'In Progress'
} else if ( } else if (
data.EventType == 'terminal' && data.EventType == 'terminal' &&
data.Direction == 'outbound-api' && data.Direction == 'outbound-api' &&
(data.Status == 'completed' || data.Status == 'no-answer') (data.Status == 'completed' || data.Status == 'no-answer')
) { ) {
callStatus.value = 'Call Ended' return data.Status == 'no-answer' ? 'No Answer' : 'Call Ended'
} }
// incoming call
if ( if (
data.EventType == 'Dial' && data.EventType == 'Dial' &&
data.Direction == 'incoming' && data.Direction == 'incoming' &&
data.Status == 'busy' data.Status == 'busy'
) { ) {
callStatus.value = 'Incoming Call' return 'Incoming Call'
} else if ( } else if (
data.EventType == 'Terminal' && data.EventType == 'Terminal' &&
data.Direction == 'incoming' && data.Direction == 'incoming' &&
data.Status == 'free' data.Status == 'free'
) { ) {
callStatus.value = 'Call Ended' return 'Call Ended'
} }
if (!showCallPopup.value && !showSmallCallPopup.value) {
showCallPopup.value = true
} }
if (callStatus.value == 'Call Ended') {
setTimeout(() => {
showCallPopup.value = false
showSmallCallPopup.value = false
note.value = ''
}, 2000)
}
})
setMakeCall(showMakeCallModal)
})
</script> </script>