2022-06-12 11:36:55 -04:00
|
|
|
import React from 'react';
|
|
|
|
|
import Can from '@/components/elements/Can';
|
2026-10-05 18:10:18 -04:00
|
|
|
import { AccessDenied } from '@/components/elements/ScreenBlock';
|
2022-06-12 11:36:55 -04:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
interface Props {
|
2022-06-12 11:36:55 -04:00
|
|
|
permission: string | string[] | null;
|
2026-10-05 18:10:18 -04:00
|
|
|
children?: React.ReactNode;
|
2022-06-12 11:36:55 -04:00
|
|
|
}
|
|
|
|
|
|
2026-10-08 16:53:20 -04:00
|
|
|
const accessDenied = <AccessDenied message='You do not have permission to access this page.' />;
|
2026-10-05 18:10:18 -04:00
|
|
|
|
|
|
|
|
export default function PermissionRoute({ permission, children }: Props) {
|
|
|
|
|
if (!permission) {
|
2026-10-08 16:53:20 -04:00
|
|
|
return children;
|
2026-10-05 18:10:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Can matchAny action={permission} renderOnError={accessDenied}>
|
|
|
|
|
{children}
|
|
|
|
|
</Can>
|
|
|
|
|
);
|
|
|
|
|
}
|