2022-11-25 13:25:03 -07:00
|
|
|
import type { ReactNode } from 'react';
|
|
|
|
|
2021-01-01 17:21:13 +00:00
|
|
|
import Can from '@/components/elements/Can';
|
2021-01-30 18:01:32 -08:00
|
|
|
import { ServerError } from '@/components/elements/ScreenBlock';
|
|
|
|
|
2021-01-01 17:21:13 +00:00
|
|
|
export interface RequireServerPermissionProps {
|
2022-11-25 13:25:03 -07:00
|
|
|
children?: ReactNode;
|
|
|
|
|
2022-06-26 15:13:52 -04:00
|
|
|
permissions: string | string[];
|
2021-01-01 17:21:13 +00:00
|
|
|
}
|
|
|
|
|
2022-11-25 13:25:03 -07:00
|
|
|
function RequireServerPermission({ children, permissions }: RequireServerPermissionProps) {
|
2021-01-01 17:21:13 +00:00
|
|
|
return (
|
|
|
|
<Can
|
|
|
|
action={permissions}
|
|
|
|
renderOnError={
|
2022-06-26 15:13:52 -04: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 13:25:03 -07:00
|
|
|
}
|
2021-01-01 17:21:13 +00:00
|
|
|
|
|
|
|
export default RequireServerPermission;
|