analytica-frontend-lib
Version:
Repositório público dos componentes utilizados nas plataformas da Analytica Ensino
44 lines • 1.58 kB
TypeScript
import React from 'react';
import type { ModulesConfig } from '../types/modulesConfig';
type ModuleKey = keyof ModulesConfig;
/** Keys of ModulesConfig whose value is a boolean (i.e. gateable modules). */
type BooleanModuleKey = {
[K in ModuleKey]: ModulesConfig[K] extends boolean ? K : never;
}[ModuleKey];
interface BaseModuleProtectedRouteProps {
children: React.ReactNode;
redirectTo?: string;
}
/**
* Gate on a boolean module key (`module`) OR on an explicit `enabled` flag
* (for derived/nested gates such as the Simulados master, `simulations.enabled`).
* At least one of the two is required, so a route can never be left ungated.
*/
export type ModuleProtectedRouteProps = BaseModuleProtectedRouteProps & ({
module: BooleanModuleKey;
enabled?: boolean;
} | {
module?: BooleanModuleKey;
enabled: boolean;
});
/**
* Route guard component that redirects if the specified module is disabled
* Use this component to wrap routes that should only be accessible when the module is enabled
*
* @example
* <Route path="simulador-sisu" element={
* <ModuleProtectedRoute module="simulator">
* <SimuladorSisu />
* </ModuleProtectedRoute>
* } />
*
* @example
* <Route path="simulados" element={
* <ModuleProtectedRoute enabled={hasSimulations}>
* <Simulados />
* </ModuleProtectedRoute>
* } />
*/
export declare const ModuleProtectedRoute: ({ module, enabled, children, redirectTo, }: ModuleProtectedRouteProps) => import("react/jsx-runtime").JSX.Element | null;
export {};
//# sourceMappingURL=ModuleProtectedRoute.d.ts.map