/** * FeatureRoute - Route protection for disabled features * * Wraps routes to check if the feature is enabled. * If disabled, redirects to home page or shows a disabled message. */ import { Navigate, useLocation } from 'react-router-dom' import { useEnabledFeatures } from '../hooks/useEnabledFeatures' import { AlertTriangle } from 'lucide-react' interface FeatureRouteProps { path: string children: React.ReactNode redirectTo?: string showDisabledMessage?: boolean } export function FeatureRoute({ path, children, redirectTo = '/', showDisabledMessage = false, }: FeatureRouteProps) { const { isFeatureEnabled, isLoading } = useEnabledFeatures() const location = useLocation() // While loading, render children to prevent flash if (isLoading) { return <>{children} } // Check if feature is enabled if (!isFeatureEnabled(path)) { if (showDisabledMessage) { return (

Feature Disabled

This feature has been disabled by an administrator. Please contact your administrator if you need access.

Go to Dashboard
) } // Redirect to home or specified path return } return <>{children} } export default FeatureRoute