From be40a3fddc30eca64cf8684948bdb26d2ccf362a Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Wed, 13 Dec 2023 11:28:17 +0530 Subject: [PATCH] fix: show response by in sla status badge if in due state refactored code --- crm/fcrm/doctype/crm_deal/crm_deal.py | 1 + crm/fcrm/doctype/crm_lead/crm_lead.py | 1 + .../components/ListViews/DealsListView.vue | 5 +- .../components/ListViews/LeadsListView.vue | 5 +- frontend/src/components/SectionFields.vue | 6 +- frontend/src/pages/Deal.vue | 9 -- frontend/src/pages/Deals.vue | 42 ++++--- frontend/src/pages/Lead.vue | 112 +++++++----------- frontend/src/pages/Leads.vue | 42 ++++--- 9 files changed, 111 insertions(+), 112 deletions(-) diff --git a/crm/fcrm/doctype/crm_deal/crm_deal.py b/crm/fcrm/doctype/crm_deal/crm_deal.py index ac215ed5..bd775193 100644 --- a/crm/fcrm/doctype/crm_deal/crm_deal.py +++ b/crm/fcrm/doctype/crm_deal/crm_deal.py @@ -139,6 +139,7 @@ class CRMDeal(Document): "mobile_no", "deal_owner", "sla_status", + "response_by", "first_response_time", "first_responded_on", "modified", diff --git a/crm/fcrm/doctype/crm_lead/crm_lead.py b/crm/fcrm/doctype/crm_lead/crm_lead.py index f8a0fb6d..bd26b6a5 100644 --- a/crm/fcrm/doctype/crm_lead/crm_lead.py +++ b/crm/fcrm/doctype/crm_lead/crm_lead.py @@ -219,6 +219,7 @@ class CRMLead(Document): "lead_owner", "first_name", "sla_status", + "response_by", "first_response_time", "first_responded_on", "modified", diff --git a/frontend/src/components/ListViews/DealsListView.vue b/frontend/src/components/ListViews/DealsListView.vue index 72efab98..a02b6996 100644 --- a/frontend/src/components/ListViews/DealsListView.vue +++ b/frontend/src/components/ListViews/DealsListView.vue @@ -51,6 +51,7 @@ 'creation', 'first_response_time', 'first_responded_on', + 'response_by', ].includes(column.key) " class="truncate text-base" @@ -62,11 +63,11 @@ class="truncate text-base" >
diff --git a/frontend/src/components/ListViews/LeadsListView.vue b/frontend/src/components/ListViews/LeadsListView.vue index 01eae1e0..c8d78b8d 100644 --- a/frontend/src/components/ListViews/LeadsListView.vue +++ b/frontend/src/components/ListViews/LeadsListView.vue @@ -60,6 +60,7 @@ 'creation', 'first_response_time', 'first_responded_on', + 'response_by', ].includes(column.key) " class="truncate text-base" @@ -71,11 +72,11 @@ class="truncate text-base" >
diff --git a/frontend/src/components/SectionFields.vue b/frontend/src/components/SectionFields.vue index d6e7ca7a..460f01c8 100644 --- a/frontend/src/components/SectionFields.vue +++ b/frontend/src/components/SectionFields.vue @@ -3,12 +3,12 @@
-
+
{{ field.label }}
-
+
-
Response By
- - {{ timeAgo(lead.data.response_by) }} +
{{ s.label }}
+ +
{{ s.value }}
+
-
-
Fulfilled In
- - {{ formatTime(lead.data.first_response_time) }} - -
-
-
Fulfilled In
- - {{ formatTime(lead.data.first_response_time) }} - -
-
-
Status
-
- -
-
@@ -259,6 +206,7 @@ import { dateFormat, timeAgo, formatTime, + dateTooltipFormat, } from '@/utils' import { usersStore } from '@/stores/users' import { contactsStore } from '@/stores/contacts' @@ -298,15 +246,6 @@ const lead = createResource({ params: { name: props.leadId }, cache: ['lead', props.leadId], auto: true, - onSuccess: (data) => { - if ( - data.response_by && - data.sla_status == 'First Response Due' && - new Date(data.response_by) < new Date() - ) { - updateField('sla_status', 'Failed') - } - }, }) const reload = ref(false) @@ -441,4 +380,41 @@ function updateField(name, value, callback) { callback?.() }) } + +let slaSection = computed(() => { + let sections = [] + if (lead.data.first_response_time) { + sections.push({ + label: 'Fulfilled In', + value: formatTime(lead.data.first_response_time), + tooltipText: dateFormat(lead.data.first_responded_on, dateTooltipFormat), + }) + } + + let status = lead.data.sla_status + let tooltipText = status + let color = + lead.data.sla_status == 'Failed' + ? 'red' + : lead.data.sla_status == 'Fulfilled' + ? 'green' + : 'orange' + + if (status == 'First Response Due') { + status = timeAgo(lead.data.response_by) + tooltipText = dateFormat(lead.data.response_by, dateTooltipFormat) + if (new Date(lead.data.response_by) < new Date()) { + color = 'red' + } + } + + sections.push({ + label: 'Status', + isBadge: true, + value: status, + tooltipText: tooltipText, + color: color, + }) + return sections +}) diff --git a/frontend/src/pages/Leads.vue b/frontend/src/pages/Leads.vue index c52fb9b0..f4b25b30 100644 --- a/frontend/src/pages/Leads.vue +++ b/frontend/src/pages/Leads.vue @@ -155,14 +155,25 @@ const rows = computed(() => { color: getLeadStatus(lead.status)?.iconColorClass, } } else if (row == 'sla_status') { + let value = lead.sla_status + let tooltipText = value + let color = + lead.sla_status == 'Failed' + ? 'red' + : lead.sla_status == 'Fulfilled' + ? 'green' + : 'orange' + if (value == 'First Response Due') { + value = timeAgo(lead.response_by) + tooltipText = dateFormat(lead.response_by, dateTooltipFormat) + if (new Date(lead.response_by) < new Date()) { + color = 'red' + } + } _rows[row] = { - label: lead.sla_status, - color: - lead.sla_status === 'Failed' - ? 'red' - : lead.sla_status === 'Fulfilled' - ? 'green' - : 'gray', + label: tooltipText, + value: value, + color: color, } } else if (row == 'lead_owner') { _rows[row] = { @@ -174,15 +185,18 @@ const rows = computed(() => { label: dateFormat(lead[row], dateTooltipFormat), timeAgo: timeAgo(lead[row]), } - } else if (['first_response_time', 'first_responded_on'].includes(row)) { + } else if ( + ['first_response_time', 'first_responded_on', 'response_by'].includes( + row + ) + ) { + let field = row == 'response_by' ? 'response_by' : 'first_responded_on' _rows[row] = { - label: lead.first_responded_on - ? dateFormat(lead.first_responded_on, dateTooltipFormat) - : '', + label: lead[field] ? dateFormat(lead[field], dateTooltipFormat) : '', timeAgo: lead[row] - ? row == 'first_responded_on' - ? timeAgo(lead[row]) - : formatTime(lead[row]) + ? row == 'first_response_time' + ? formatTime(lead[row]) + : timeAgo(lead[row]) : '', } }