white-label: brand de la clinica por configuracion (fase 1 de instancia sin branding SKEEN)
- backend: GET/PUT /skeen/frontend/v1/brand leyendo ir.config_parameter skeen.clinic.brand (JSON: nombre, logo_claro, logo_oscuro, pie) con defaults SKEEN; GET publico (el login lo necesita sin sesion), PUT admin con auditoria. frontend_users.xml: 'Administrador SKEEN' -> 'Administrador' - frontend: ClinicBrand + BRAND_DEFAULT en odoo.ts; brand y setBrand en el contexto de auth (fetch al boot + cache localStorage + document.title) - Login/layouts/mensajes/exports leen el brand en vez de strings SKEEN: Login.tsx, SkeenLayout, HomeNestLayout, Cumpleanos (wa + export), Pacientes/Ventas/Cortes/Reportes/Kpis/Alertas/AgendaPrint (titulos), useClinicaPrint (fallback nombre), Login hace GET publico al montar - Configuracion > Clinica: tarjeta 'Identidad de la clinica' (solo admin) para editar nombre/pie/logos con preview - no renombrado (invisible al usuario): rutas API /skeen/*, claves localStorage, nombres de modulos, parametros skeen.* Verificacion API: 11/11 tests OK (defaults, PUT merge, campo invalido ignorado, restore, admin neutral). Deploy: build + rsync + Odoo reiniciado
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import { createContext, useContext, useEffect, useState, useCallback } from 'react';
|
||||
import type { FC, ReactNode } from 'react';
|
||||
import { odooApi, type FrontendUser, type FrontendRole, type AgendaPerm } from '../services/odoo';
|
||||
import { odooApi, type FrontendUser, type FrontendRole, type AgendaPerm, type ClinicBrand, BRAND_DEFAULT } from '../services/odoo';
|
||||
|
||||
const TOKEN_KEY = 'skeen_token';
|
||||
const USER_KEY = 'skeen_user';
|
||||
const MENU_ROLES_KEY = 'skeen_menu_roles';
|
||||
const BRAND_KEY_LS = 'skeen_clinic_brand';
|
||||
|
||||
const ROLE_RANK: Record<FrontendRole, number> = {
|
||||
admin: 100,
|
||||
@@ -76,6 +77,9 @@ interface AuthContextValue {
|
||||
hasRole: (min: FrontendRole) => boolean;
|
||||
canSee: (href: string) => boolean;
|
||||
canAgenda: (perm: AgendaPerm) => boolean;
|
||||
// Brand de la clínica (white-label). BRAND_DEFAULT hasta que /brand responde.
|
||||
brand: ClinicBrand;
|
||||
setBrand: (b: ClinicBrand) => void;
|
||||
}
|
||||
|
||||
const AuthContext = createContext<AuthContextValue | undefined>(undefined);
|
||||
@@ -96,6 +100,34 @@ export const AuthProvider: FC<{ children: ReactNode }> = ({ children }) => {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
// Brand de la clínica: se hidrata del caché para no parpadear y se refresca
|
||||
// con /brand en el arranque (mismo patrón que menuRoles).
|
||||
const [brand, setBrandState] = useState<ClinicBrand>(() => {
|
||||
try {
|
||||
const cached = localStorage.getItem(BRAND_KEY_LS);
|
||||
return cached ? { ...BRAND_DEFAULT, ...JSON.parse(cached) } : BRAND_DEFAULT;
|
||||
} catch {
|
||||
return BRAND_DEFAULT;
|
||||
}
|
||||
});
|
||||
|
||||
const setBrand = useCallback((b: ClinicBrand) => {
|
||||
setBrandState(b);
|
||||
localStorage.setItem(BRAND_KEY_LS, JSON.stringify(b));
|
||||
// Título de la pestaña sigue al brand configurado.
|
||||
if (typeof document !== 'undefined' && b.nombre) {
|
||||
document.title = b.nombre;
|
||||
}
|
||||
}, []);
|
||||
|
||||
const refreshBrand = useCallback(async () => {
|
||||
try {
|
||||
const res = await odooApi.getBrand();
|
||||
if (res.status === 'success' && res.brand) setBrand(res.brand);
|
||||
} catch {
|
||||
// fallback: BRAND_DEFAULT / caché
|
||||
}
|
||||
}, [setBrand]);
|
||||
|
||||
const refreshMenuRoles = useCallback(async () => {
|
||||
try {
|
||||
@@ -146,6 +178,7 @@ export const AuthProvider: FC<{ children: ReactNode }> = ({ children }) => {
|
||||
setUser(res.user);
|
||||
localStorage.setItem(USER_KEY, JSON.stringify(res.user));
|
||||
refreshMenuRoles();
|
||||
refreshBrand();
|
||||
} else {
|
||||
clear();
|
||||
}
|
||||
@@ -184,6 +217,7 @@ export const AuthProvider: FC<{ children: ReactNode }> = ({ children }) => {
|
||||
setToken(res.token);
|
||||
setUser(res.user);
|
||||
refreshMenuRoles();
|
||||
refreshBrand();
|
||||
return res.user;
|
||||
};
|
||||
|
||||
@@ -232,7 +266,7 @@ export const AuthProvider: FC<{ children: ReactNode }> = ({ children }) => {
|
||||
};
|
||||
|
||||
return (
|
||||
<AuthContext.Provider value={{ user, token, loading, bootError, retryBoot, login, logout, hasRole, canSee, canAgenda }}>
|
||||
<AuthContext.Provider value={{ user, token, loading, bootError, retryBoot, login, logout, hasRole, canSee, canAgenda, brand, setBrand }}>
|
||||
{children}
|
||||
</AuthContext.Provider>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user