From f5fa47bae0b6d640dab19318580d594d91546a5f Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Thu, 30 May 2024 14:00:12 +0530 Subject: [PATCH] refactor: show call log detail in call log modal --- .../src/components/Modals/CallLogModal.vue | 92 +++++++++---- frontend/src/pages/CallLogs.vue | 122 +----------------- frontend/src/utils/callLog.js | 84 ++++++++++++ 3 files changed, 157 insertions(+), 141 deletions(-) create mode 100644 frontend/src/utils/callLog.js diff --git a/frontend/src/components/Modals/CallLogModal.vue b/frontend/src/components/Modals/CallLogModal.vue index 66bd1544..903e76c2 100644 --- a/frontend/src/components/Modals/CallLogModal.vue +++ b/frontend/src/components/Modals/CallLogModal.vue @@ -84,7 +84,9 @@ @@ -64,20 +64,10 @@ import LayoutHeader from '@/components/LayoutHeader.vue' import ViewControls from '@/components/ViewControls.vue' import CallLogsListView from '@/components/ListViews/CallLogsListView.vue' import CallLogModal from '@/components/Modals/CallLogModal.vue' -import { - secondsToDuration, - dateFormat, - dateTooltipFormat, - timeAgo, -} from '@/utils' -import { usersStore } from '@/stores/users' -import { contactsStore } from '@/stores/contacts' +import { getCallLogDetail } from '@/utils/callLog' import { Breadcrumbs } from 'frappe-ui' import { computed, ref } from 'vue' -const { getUser } = usersStore() -const { getContact, getLeadContact } = contactsStore() - const breadcrumbs = [{ label: __('Call Logs'), route: { name: 'Call Logs' } }] const callLogsListView = ref(null) @@ -94,119 +84,17 @@ const rows = computed(() => { return callLogs.value?.data.data.map((callLog) => { let _rows = {} callLogs.value?.data.rows.forEach((row) => { - _rows[row] = callLog[row] - - let incoming = callLog.type === 'Incoming' - - if (row === 'caller') { - _rows[row] = { - label: incoming - ? getContact(callLog.from)?.full_name || - getLeadContact(callLog.from)?.full_name || - 'Unknown' - : getUser(callLog.caller).full_name, - image: incoming - ? getContact(callLog.from)?.image || - getLeadContact(callLog.from)?.image - : getUser(callLog.caller).user_image, - } - } else if (row === 'receiver') { - _rows[row] = { - label: incoming - ? getUser(callLog.receiver).full_name - : getContact(callLog.to)?.full_name || - getLeadContact(callLog.to)?.full_name || - 'Unknown', - image: incoming - ? getUser(callLog.receiver).user_image - : getContact(callLog.to)?.image || - getLeadContact(callLog.to)?.image, - } - } else if (row === 'duration') { - _rows[row] = { - label: secondsToDuration(callLog.duration), - icon: 'clock', - } - } else if (row === 'type') { - _rows[row] = { - label: callLog.type, - icon: incoming ? 'phone-incoming' : 'phone-outgoing', - } - } else if (row === 'status') { - _rows[row] = { - label: statusLabelMap[callLog.status], - color: statusColorMap[callLog.status], - } - } else if (['modified', 'creation'].includes(row)) { - _rows[row] = { - label: dateFormat(callLog[row], dateTooltipFormat), - timeAgo: __(timeAgo(callLog[row])), - } - } + _rows[row] = getCallLogDetail(row, callLog) }) return _rows }) }) const showCallLogModal = ref(false) - -const callLog = ref({ - name: '', - caller: '', - receiver: '', - duration: '', - type: '', - status: '', - from: '', - to: '', - note: '', - recording_url: '', - reference_doctype: '', - reference_docname: '', - creation: '', -}) +const selectedCallLog = ref(null) function showCallLog(name) { - let d = rows.value?.find((row) => row.name === name) - callLog.value = { - name: d.name, - caller: d.caller, - receiver: d.receiver, - duration: d.duration, - type: d.type, - status: d.status, - from: d.from, - to: d.to, - note: d.note, - recording_url: d.recording_url, - reference_doctype: d.reference_doctype, - reference_docname: d.reference_docname, - creation: d.creation, - } + selectedCallLog.value = name showCallLogModal.value = true } - -const statusLabelMap = { - Completed: 'Completed', - Initiated: 'Initiated', - Busy: 'Declined', - Failed: 'Failed', - Queued: 'Queued', - Cancelled: 'Cancelled', - Ringing: 'Ringing', - 'No Answer': 'Missed Call', - 'In Progress': 'In Progress', -} - -const statusColorMap = { - Completed: 'green', - Busy: 'orange', - Failed: 'red', - Initiated: 'gray', - Queued: 'gray', - Cancelled: 'gray', - Ringing: 'gray', - 'No Answer': 'red', - 'In Progress': 'blue', -} diff --git a/frontend/src/utils/callLog.js b/frontend/src/utils/callLog.js new file mode 100644 index 00000000..9b8ad118 --- /dev/null +++ b/frontend/src/utils/callLog.js @@ -0,0 +1,84 @@ +import { + secondsToDuration, + dateFormat, + dateTooltipFormat, + timeAgo, +} from '@/utils' +import { usersStore } from '@/stores/users' +import { contactsStore } from '@/stores/contacts' + +const { getUser } = usersStore() +const { getContact, getLeadContact } = contactsStore() + +export function getCallLogDetail(row, log) { + let incoming = log.type === 'Incoming' + + if (row === 'caller') { + return { + label: incoming + ? getContact(log.from)?.full_name || + getLeadContact(log.from)?.full_name || + 'Unknown' + : getUser(log.caller).full_name, + image: incoming + ? getContact(log.from)?.image || getLeadContact(log.from)?.image + : getUser(log.caller).user_image, + } + } else if (row === 'receiver') { + return { + label: incoming + ? getUser(log.receiver).full_name + : getContact(log.to)?.full_name || + getLeadContact(log.to)?.full_name || + 'Unknown', + image: incoming + ? getUser(log.receiver).user_image + : getContact(log.to)?.image || getLeadContact(log.to)?.image, + } + } else if (row === 'duration') { + return { + label: secondsToDuration(log.duration), + icon: 'clock', + } + } else if (row === 'type') { + return { + label: log.type, + icon: incoming ? 'phone-incoming' : 'phone-outgoing', + } + } else if (row === 'status') { + return { + label: statusLabelMap[log.status], + color: statusColorMap[log.status], + } + } else if (['modified', 'creation'].includes(row)) { + return { + label: dateFormat(log[row], dateTooltipFormat), + timeAgo: __(timeAgo(log[row])), + } + } + return log[row] +} + +export const statusLabelMap = { + Completed: 'Completed', + Initiated: 'Initiated', + Busy: 'Declined', + Failed: 'Failed', + Queued: 'Queued', + Cancelled: 'Cancelled', + Ringing: 'Ringing', + 'No Answer': 'Missed Call', + 'In Progress': 'In Progress', +} + +export const statusColorMap = { + Completed: 'green', + Busy: 'orange', + Failed: 'red', + Initiated: 'gray', + Queued: 'gray', + Cancelled: 'gray', + Ringing: 'gray', + 'No Answer': 'red', + 'In Progress': 'blue', +}