Documentos Pacientes, Template Documentos Pacientes Saas, Documentos prontuários, Documentos Externos, Visualização Externa, Permissão de Visualização, Render Otimização
This commit is contained in:
+27
-9
@@ -33,6 +33,10 @@ function isTenantArea(path = '') {
|
||||
}
|
||||
|
||||
// ── Setup Wizard redirect ────────────────────────────────────────
|
||||
// Cache por sessão: uma vez confirmado, não verifica de novo
|
||||
let _setupClearedUid = null;
|
||||
let _setupClearedIsClinic = null;
|
||||
|
||||
async function checkSetupWizard() {
|
||||
if (!isTenantArea(route.path)) return;
|
||||
if (route.path.includes('/setup')) return;
|
||||
@@ -40,19 +44,33 @@ async function checkSetupWizard() {
|
||||
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;
|
||||
|
||||
const activeMembership = tenantStore.memberships?.find((m) => m.id === tenantStore.activeTenantId);
|
||||
const activeMembership = tenantStore.memberships?.find((m) => m.tenant_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);
|
||||
// Se já confirmamos que este uid passou o setup, não verifica de novo
|
||||
if (_setupClearedUid === uid && _setupClearedIsClinic === isClinic) return;
|
||||
|
||||
const { data } = await supabase
|
||||
.from('agenda_configuracoes')
|
||||
.select('setup_concluido, setup_clinica_concluido, atendimento_mode')
|
||||
.eq('owner_id', uid)
|
||||
.maybeSingle();
|
||||
|
||||
if (!data) return; // sem linha = setup nunca iniciado, não redireciona
|
||||
|
||||
// Considera completo se qualquer flag de conclusão estiver setada
|
||||
const setupDone = data.setup_concluido || data.setup_clinica_concluido || !!data.atendimento_mode;
|
||||
|
||||
if (setupDone) {
|
||||
// Grava cache: não verifica mais nesta sessão
|
||||
_setupClearedUid = uid;
|
||||
_setupClearedIsClinic = isClinic;
|
||||
return;
|
||||
}
|
||||
|
||||
const dest = isClinic ? '/admin/setup' : '/therapist/setup';
|
||||
router.push(dest);
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
|
||||
Reference in New Issue
Block a user