From 41c65eb77763782eb5e74a791f071e71598d4d72 Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Wed, 12 Mar 2025 18:13:57 +0530 Subject: [PATCH] fix: update onboarding status when first email is sent --- crm/api/onboarding.py | 2 +- frontend/src/components/CommunicationArea.vue | 1 + frontend/src/composables/onboarding.js | 55 +++++++++++++------ 3 files changed, 39 insertions(+), 19 deletions(-) diff --git a/crm/api/onboarding.py b/crm/api/onboarding.py index 4ad1ab3b..088000e3 100644 --- a/crm/api/onboarding.py +++ b/crm/api/onboarding.py @@ -20,7 +20,7 @@ def update_user_onboarding_status(steps: str): @frappe.whitelist() -def get_first_non_converted_lead(): +def get_first_lead(): lead = frappe.get_all( "CRM Lead", filters={"converted": 0}, diff --git a/frontend/src/components/CommunicationArea.vue b/frontend/src/components/CommunicationArea.vue index 203d11eb..4052a3b8 100644 --- a/frontend/src/components/CommunicationArea.vue +++ b/frontend/src/components/CommunicationArea.vue @@ -227,6 +227,7 @@ async function submitEmail() { reload.value = true emit('scroll') capture('email_sent', { doctype: props.doctype }) + updateOnboardingStep('send_first_email') } async function submitComment() { diff --git a/frontend/src/composables/onboarding.js b/frontend/src/composables/onboarding.js index 129f938f..9250f9ab 100644 --- a/frontend/src/composables/onboarding.js +++ b/frontend/src/composables/onboarding.js @@ -55,12 +55,10 @@ const steps = reactive([ onClick: async () => { minimize.value = true - firstLead.value = - !firstLead.value && - (await call('crm.api.onboarding.get_first_non_converted_lead')) + let lead = await getFirstLead() - if (firstLead.value) { - router.push({ name: 'Lead', params: { leadId: firstLead.value } }) + if (lead) { + router.push({ name: 'Lead', params: { leadId: lead } }) } else { router.push({ name: 'Leads' }) } @@ -73,13 +71,12 @@ const steps = reactive([ completed: false, onClick: async () => { minimize.value = true - firstDeal.value = - !firstDeal.value && (await call('crm.api.onboarding.get_first_deal')) + let deal = await getFirstDeal() - if (firstDeal.value) { + if (deal) { router.push({ name: 'Deal', - params: { dealId: firstDeal.value }, + params: { dealId: deal }, hash: '#tasks', }) } else { @@ -94,13 +91,12 @@ const steps = reactive([ completed: false, onClick: async () => { minimize.value = true - firstDeal.value = - !firstDeal.value && (await call('crm.api.onboarding.get_first_deal')) + let deal = await getFirstDeal() - if (firstDeal.value) { + if (deal) { router.push({ name: 'Deal', - params: { dealId: firstDeal.value }, + params: { dealId: deal }, hash: '#notes', }) } else { @@ -115,13 +111,12 @@ const steps = reactive([ completed: false, onClick: async () => { minimize.value = true - firstDeal.value = - !firstDeal.value && (await call('crm.api.onboarding.get_first_deal')) + let deal = await getFirstDeal() - if (firstDeal.value) { + if (deal) { router.push({ name: 'Deal', - params: { dealId: firstDeal.value }, + params: { dealId: deal }, hash: '#comments', }) } else { @@ -130,10 +125,24 @@ const steps = reactive([ }, }, { - name: 'send_email', + name: 'send_first_email', title: 'Send email', icon: markRaw(EmailIcon), completed: false, + onClick: async () => { + minimize.value = true + let deal = await getFirstDeal() + + if (deal) { + router.push({ + name: 'Deal', + params: { dealId: deal }, + hash: '#emails', + }) + } else { + router.push({ name: 'Leads' }) + } + }, }, { name: 'change_deal_status', @@ -143,6 +152,16 @@ const steps = reactive([ }, ]) +async function getFirstLead() { + if (firstLead.value) return firstLead.value + return await call('crm.api.onboarding.get_first_lead') +} + +async function getFirstDeal() { + if (firstDeal.value) return firstDeal.value + return await call('crm.api.onboarding.get_first_deal') +} + const stepsCompleted = computed( () => steps.filter((step) => step.completed).length, )