Make it easier for plugins to extend the navigation and add routes

This commit is contained in:
DaneEveritt 2022-06-12 11:36:55 -04:00
parent 88a7bd7578
commit 04e97cc67e
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
5 changed files with 198 additions and 116 deletions

View file

@ -0,0 +1,30 @@
import React from 'react';
import { Route } from 'react-router-dom';
import { RouteProps } from 'react-router';
import Can from '@/components/elements/Can';
import { ServerError } from '@/components/elements/ScreenBlock';
interface Props extends Omit<RouteProps, 'path'> {
path: string;
permission: string | string[] | null;
}
export default ({ permission, children, ...props }: Props) => (
<Route {...props}>
{!permission ?
children
:
<Can
action={permission}
renderOnError={
<ServerError
title={'Access Denied'}
message={'You do not have permission to access this page.'}
/>
}
>
{children}
</Can>
}
</Route>
);