Setup Wizard
This commit is contained in:
+39
-1
@@ -1,6 +1,6 @@
|
||||
<script setup>
|
||||
import { onMounted, watch } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { supabase } from '@/lib/supabase/client'
|
||||
import { useTenantStore } from '@/stores/tenantStore'
|
||||
import { useEntitlementsStore } from '@/stores/entitlementsStore'
|
||||
@@ -8,6 +8,7 @@ import AjudaDrawer from '@/components/AjudaDrawer.vue'
|
||||
import { fetchDocsForPath } from '@/composables/useAjuda'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const tenantStore = useTenantStore()
|
||||
const entStore = useEntitlementsStore()
|
||||
|
||||
@@ -23,6 +24,36 @@ function isSaasArea (path = '') {
|
||||
return path.startsWith('/saas')
|
||||
}
|
||||
|
||||
// ── Setup Wizard redirect ────────────────────────────────────────
|
||||
async function checkSetupWizard () {
|
||||
// Só verifica em área de tenant
|
||||
if (!isTenantArea(route.path)) return
|
||||
// Não redireciona se já está no setup
|
||||
if (route.path.includes('/setup')) return
|
||||
|
||||
const uid = tenantStore.user?.id
|
||||
if (!uid) return
|
||||
|
||||
const { data } = await supabase
|
||||
.from('agenda_configuracoes')
|
||||
.select('setup_concluido, setup_clinica_concluido')
|
||||
.eq('owner_id', uid)
|
||||
.maybeSingle()
|
||||
|
||||
if (!data) return
|
||||
|
||||
// Determina o kind do tenant ativo para saber qual flag checar
|
||||
const activeMembership = tenantStore.memberships?.find(m => m.id === tenantStore.activeTenantId)
|
||||
const kind = activeMembership?.kind ?? tenantStore.activeRole ?? ''
|
||||
const isClinic = kind.startsWith('clinic')
|
||||
|
||||
const setupDone = isClinic ? data.setup_clinica_concluido : data.setup_concluido
|
||||
if (!setupDone) {
|
||||
const dest = isClinic ? '/admin/setup' : '/therapist/setup'
|
||||
router.push(dest)
|
||||
}
|
||||
}
|
||||
|
||||
async function debugSnapshot (label = 'snapshot') {
|
||||
console.group(`🧭 [APP DEBUG] ${label}`)
|
||||
try {
|
||||
@@ -96,6 +127,9 @@ async function debugSnapshot (label = 'snapshot') {
|
||||
console.log('tenantStore.memberships:', tenantStore.memberships)
|
||||
console.log("entStore.can('online_scheduling.manage'):", entStore.can?.('online_scheduling.manage'))
|
||||
console.groupEnd()
|
||||
|
||||
// Redireciona para o wizard se setup não foi concluído
|
||||
await checkSetupWizard()
|
||||
} else if (isPortalArea(path)) {
|
||||
console.log('🟣 Portal area detected → SKIP tenantStore.loadSessionAndTenant()')
|
||||
} else if (isSaasArea(path)) {
|
||||
@@ -128,6 +162,10 @@ watch(
|
||||
await debugSnapshot(`route change: ${from} -> ${to}`)
|
||||
// Atualiza docs de ajuda ao navegar
|
||||
fetchDocsForPath(route.path)
|
||||
// Verifica setup sempre que entrar em área tenant
|
||||
if (isTenantArea(route.path) && tenantStore.loaded) {
|
||||
await checkSetupWizard()
|
||||
}
|
||||
}
|
||||
)
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user