b031117925
- PluginsView: registra o plugin 'newwhats' (config só no catálogo, exclusivo do
superadmin via view 'plugins' — já gateada em isViewAllowed).
- pluginRegistry: 'newwhats' em ALWAYS_ON (ativação por plugin é local/localStorage
e não propaga; ALWAYS_ON garante Inbox/Secretária para TODOS os usuários).
- App.tsx: views wa-inbox/wa-secretaria (ViewKey, rotas, render); gating
isPluginActive('newwhats') libera a qualquer usuário.
- Sidebar: itens WHATSAPP + SECRETÁRIA IA quando o plugin está ativo.
- Novas views consomem o proxy /api/nw/v1/* (motor ext-api). Estágio 1: funcional
(lista/thread/envio; ask da secretária), visual aproximado do motor.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
45 lines
2.0 KiB
TypeScript
45 lines
2.0 KiB
TypeScript
export const ACTIVE_PLUGINS_KEY = 'SCOREODONTO_ACTIVE_PLUGINS';
|
|
export const PLUGIN_CONFIG_KEY = 'SCOREODONTO_PLUGIN_CONFIG';
|
|
|
|
// "Visualizar como" (superadmin) ativa todos os plugins para teste, sem depender
|
|
// do cache em localStorage (que é reconciliado/limpo em outros fluxos).
|
|
const PREVIEW_PLUGINS = ['rx-scoreodonto', 'locacao-salas', 'profissionais-marketplace'];
|
|
|
|
export const getActivePlugins = (): string[] => {
|
|
try {
|
|
if (localStorage.getItem('SCOREODONTO_PREVIEW_ROLE')) return [...PREVIEW_PLUGINS];
|
|
return JSON.parse(localStorage.getItem(ACTIVE_PLUGINS_KEY) || '[]');
|
|
} catch { return []; }
|
|
};
|
|
|
|
// Plugins sempre ligados (capability de plataforma, sem opção de desativar).
|
|
// 'newwhats': Inbox/Secretária precisam aparecer para TODOS os usuários, mas a
|
|
// ativação por plugin é local (localStorage/navegador) e não propaga entre contas.
|
|
// Por isso fica ALWAYS_ON; a CONFIG continua exclusiva do superadmin (view 'plugins').
|
|
// (Futuro: gate por /api/nw/status quando o backend expuser "configurado".)
|
|
export const ALWAYS_ON_PLUGINS = ['locacao-salas', 'newwhats'];
|
|
|
|
export const isPluginActive = (id: string): boolean => ALWAYS_ON_PLUGINS.includes(id) || getActivePlugins().includes(id);
|
|
|
|
export const togglePlugin = (id: string): boolean => {
|
|
const active = getActivePlugins();
|
|
const wasActive = active.includes(id);
|
|
const next = wasActive ? active.filter(p => p !== id) : [...active, id];
|
|
localStorage.setItem(ACTIVE_PLUGINS_KEY, JSON.stringify(next));
|
|
return !wasActive;
|
|
};
|
|
|
|
export const getPluginConfig = (id: string): Record<string, string> => {
|
|
try {
|
|
const all = JSON.parse(localStorage.getItem(PLUGIN_CONFIG_KEY) || '{}');
|
|
return all[id] || {};
|
|
} catch { return {}; }
|
|
};
|
|
|
|
export const savePluginConfig = (id: string, config: Record<string, string>) => {
|
|
try {
|
|
const all = JSON.parse(localStorage.getItem(PLUGIN_CONFIG_KEY) || '{}');
|
|
localStorage.setItem(PLUGIN_CONFIG_KEY, JSON.stringify({ ...all, [id]: config }));
|
|
} catch {}
|
|
};
|