fix: skip all and reset

This commit is contained in:
Shariq Ansari 2025-03-12 20:24:19 +05:30
parent a42eb6b99e
commit b5baaf3cb1
3 changed files with 70 additions and 7 deletions

View File

@ -7,7 +7,7 @@
>
<div class="flex items-center justify-between">
<div class="text-base font-medium ml-1">
<div v-if="minimize && !isOnboardingStepsCompleted && !showHelpCenter">
<div v-if="!isOnboardingStepsCompleted && !showHelpCenter">
{{ __('Getting started') }}
</div>
<div v-else-if="showHelpCenter">

View File

@ -1,5 +1,5 @@
<template>
<div class="flex flex-col justify-center items-center gap-1 mb-3">
<div class="flex flex-col justify-center items-center gap-1 mt-4 mb-7">
<CRMLogo class="size-10 shrink-0 rounded mb-4" />
<div class="text-base font-medium">
{{ __('Welcome to Frappe CRM') }}
@ -10,12 +10,25 @@
</div>
<div class="flex flex-col gap-2.5 overflow-hidden">
<div class="flex justify-between items-center py-0.5">
<div class="text-base font-medium">{{ __('Getting started') }}</div>
<Badge
:label="__('{0}% completed', [completedPercentage])"
theme="orange"
size="lg"
/>
<div class="flex">
<Button
v-if="completedPercentage != 0"
variant="ghost"
:label="__('Reset')"
@click="reset"
/>
<Button
v-if="completedPercentage != 100"
variant="ghost"
:label="__('Skip all')"
@click="skipAll"
/>
</div>
</div>
<div class="flex flex-col gap-1.5 overflow-y-auto">
<div
@ -49,6 +62,13 @@ import { useOnboarding } from '@/composables/onboarding'
const emit = defineEmits(['close'])
const { steps, stepsCompleted, totalSteps, completedPercentage, skip } =
useOnboarding()
const {
steps,
stepsCompleted,
totalSteps,
completedPercentage,
skip,
skipAll,
reset,
} = useOnboarding()
</script>

View File

@ -190,6 +190,18 @@ export function useOnboarding() {
syncStatus()
function skip(step) {
updateOnboardingStep(step, true)
}
function skipAll() {
updateAll(true)
}
function reset() {
updateAll(false)
}
function updateOnboardingStep(step, skipped = false) {
if (isOnboardingStepsCompleted.value) return
let user = window.user
@ -223,8 +235,37 @@ export function useOnboarding() {
})
}
function skip(step) {
updateOnboardingStep(step, true)
function updateAll(value) {
if (isOnboardingStepsCompleted.value) return
let user = window.user
if (!user) return false
let _steps
if (!user.onboarding_status['frappe_crm_onboarding_status']) {
user.onboarding_status['frappe_crm_onboarding_status'] = steps.map(
(s) => {
return { name: s.name, completed: value }
},
)
} else {
_steps = user.onboarding_status['frappe_crm_onboarding_status']
_steps.forEach((step) => {
step.completed = value
})
}
steps.forEach((step) => {
step.completed = value
})
window.user = user
capture(value ? 'onboarding_skipped_all' : 'onboarding_reset_steps')
call('crm.api.onboarding.update_user_onboarding_status', {
steps: JSON.stringify(_steps),
})
}
function syncStatus() {
@ -250,5 +291,7 @@ export function useOnboarding() {
completedPercentage,
updateOnboardingStep,
skip,
skipAll,
reset,
}
}