diff --git a/frontend/src/components/Telephony/ExotelCallUI.vue b/frontend/src/components/Telephony/ExotelCallUI.vue index b4363c36..bd447774 100644 --- a/frontend/src/components/Telephony/ExotelCallUI.vue +++ b/frontend/src/components/Telephony/ExotelCallUI.vue @@ -2,14 +2,14 @@
- {{ phoneNumber }} - · + + {{ callStatus }} + + {{ phoneNumber }} - 00:38 + · 00:38 + + + · + {{ callStatus }} + · 00:38 - {{ callStatus }}
-
-
00:38
-
{{ __(callStatus) }}
- + {{ __(callStatus) }} + · 00:38 +
+
{{ __(callStatus) }}
+
+ +
{{ note }}
+
{{ task }}
-
+
{{ contact.full_name }}
{{ phoneNumber }}
@@ -106,12 +135,6 @@
@@ -146,12 +162,12 @@ import AvatarIcon from '@/components/Icons/AvatarIcon.vue' import MinimizeIcon from '@/components/Icons/MinimizeIcon.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 { globalStore } from '@/stores/global' import { contactsStore } from '@/stores/contacts' import { useDraggable, useWindowSize } from '@vueuse/core' -import { ref, onBeforeUnmount, onMounted } from 'vue' +import { ref, computed, onBeforeUnmount, onMounted } from 'vue' const { getContact, getLeadContact } = contactsStore() const { $socket, setMakeCall } = globalStore() @@ -178,20 +194,23 @@ let { style } = useDraggable(callPopup, { const showCallModal = ref(false) const callStatus = ref('') -const phoneNumber = ref('09821259504') +const phoneNumber = ref('') const callData = ref(null) -const contact = ref({ - full_name: '', - mobile_no: '', +const contact = computed(() => { + if (!phoneNumber.value) { + return { + full_name: '', + image: '', + } + } + let _contact = getContact(phoneNumber.value) + if (!_contact) { + _contact = getLeadContact(phoneNumber.value) + } + return _contact }) -const mute = ref(false) - -function toggleMute() { - mute.value = !mute.value -} - 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.', ) @@ -200,11 +219,33 @@ const showNote = ref(false) function showNoteWindow() { 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 updatedTop = 0 - updatedTop = showNote.value ? top - 224 : top + 224 + updatedTop = condition ? top - 224 : top + 224 if (updatedTop < 0) { updatedTop = 10 @@ -219,29 +260,15 @@ function showMakeCallModal(number) { } function makeCall() { - contact.value = getContact(phoneNumber.value) - if (!contact.value) { - contact.value = getLeadContact(phoneNumber.value) - } - showCallModal.value = false callStatus.value = 'Calling...' showCallPopup.value = true call('crm.integrations.exotel.handler.make_a_call', { to_number: phoneNumber.value, - from_number: '07666980887', - caller_id: '08047091710', }) } -function endCall() { - callStatus.value = '' - showCallPopup.value = false - showSmallCallPopup.value = false - note.value = '' -} - onBeforeUnmount(() => { $socket.off('exotel_call') }) @@ -251,56 +278,61 @@ onMounted(() => { callData.value = data console.log(data) - if ( - data.EventType == 'answered' && - data.Direction == 'outbound-api' && - data.Status == 'in-progress' && - data['Legs[0][Status]'] == 'in-progress' && - data['Legs[1][Status]'] == '' - ) { - callStatus.value = 'Ringing...' - } else if ( - data.EventType == 'answered' && - data.Direction == 'outbound-api' && - data.Status == 'in-progress' && - data['Legs[1][Status]'] == 'in-progress' - ) { - callStatus.value = 'In Progress' - } else if ( - data.EventType == 'terminal' && - data.Direction == 'outbound-api' && - (data.Status == 'completed' || data.Status == 'no-answer') - ) { - callStatus.value = 'Call Ended' - } - - if ( - data.EventType == 'Dial' && - data.Direction == 'incoming' && - data.Status == 'busy' - ) { - callStatus.value = 'Incoming Call' - } else if ( - data.EventType == 'Terminal' && - data.Direction == 'incoming' && - data.Status == 'free' - ) { - callStatus.value = 'Call Ended' - } + callStatus.value = updateStatus(data) 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) }) + +function closeCallPopup() { + showCallPopup.value = false + showSmallCallPopup.value = false + note.value = '' + task.value = '' +} + +function updateStatus(data) { + // outgoing call + if ( + data.EventType == 'answered' && + data.Direction == 'outbound-api' && + data.Status == 'in-progress' && + data['Legs[0][Status]'] == 'in-progress' && + data['Legs[1][Status]'] == '' + ) { + return 'Ringing...' + } else if ( + data.EventType == 'answered' && + data.Direction == 'outbound-api' && + data.Status == 'in-progress' && + data['Legs[1][Status]'] == 'in-progress' + ) { + return 'In Progress' + } else if ( + data.EventType == 'terminal' && + data.Direction == 'outbound-api' && + (data.Status == 'completed' || data.Status == 'no-answer') + ) { + return data.Status == 'no-answer' ? 'No Answer' : 'Call Ended' + } + + // incoming call + if ( + data.EventType == 'Dial' && + data.Direction == 'incoming' && + data.Status == 'busy' + ) { + return 'Incoming Call' + } else if ( + data.EventType == 'Terminal' && + data.Direction == 'incoming' && + data.Status == 'free' + ) { + return 'Call Ended' + } +}