2022-11-25 20:25:03 +00:00
|
|
|
import type { ReactNode } from 'react';
|
|
|
|
|
2021-01-01 17:21:13 +00:00
|
|
|
import Can from '@/components/elements/Can';
|
2021-01-31 02:01:32 +00:00
|
|
|
import { ServerError } from '@/components/elements/ScreenBlock';
|
|
|
|
|
2021-01-01 17:21:13 +00:00
|
|
|
export interface RequireServerPermissionProps {
|
2022-11-25 20:25:03 +00:00
|
|
|
children?: ReactNode;
|
|
|
|
|
2022-06-26 19:13:52 +00:00
|
|
|
permissions: string | string[];
|
2021-01-01 17:21:13 +00:00
|
|
|
}
|
|
|
|
|
2022-11-25 20:25:03 +00:00
|
|
|
function RequireServerPermission({ children, permissions }: RequireServerPermissionProps) {
|
2021-01-01 17:21:13 +00:00
|
|
|
return (
|
|
|
|
<Can
|
|
|
|
action={permissions}
|
|
|
|
renderOnError={
|
2022-06-26 19:13:52 +00:00
|
|
|
<ServerError title={'Access Denied'} message={'You do not have permission to access this page.'} />
|
2021-01-01 17:21:13 +00:00
|
|
|
}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</Can>
|
|
|
|
);
|
2022-11-25 20:25:03 +00:00
|
|
|
}
|
2021-01-01 17:21:13 +00:00
|
|
|
|
|
|
|
export default RequireServerPermission;
|