2022-06-12 15:36:55 +00:00
|
|
|
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}>
|
2022-06-26 19:13:52 +00:00
|
|
|
{!permission ? (
|
2022-06-12 15:36:55 +00:00
|
|
|
children
|
2022-06-26 19:13:52 +00:00
|
|
|
) : (
|
2022-06-12 15:36:55 +00:00
|
|
|
<Can
|
2022-06-28 00:41:49 +00:00
|
|
|
matchAny
|
2022-06-12 15:36:55 +00:00
|
|
|
action={permission}
|
|
|
|
renderOnError={
|
2022-06-26 19:13:52 +00:00
|
|
|
<ServerError title={'Access Denied'} message={'You do not have permission to access this page.'} />
|
2022-06-12 15:36:55 +00:00
|
|
|
}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</Can>
|
2022-06-26 19:13:52 +00:00
|
|
|
)}
|
2022-06-12 15:36:55 +00:00
|
|
|
</Route>
|
|
|
|
);
|