Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/resources/scripts/components/elements/Can.tsx
7461 views
1
import React, { memo } from 'react';
2
import { usePermissions } from '@/plugins/usePermissions';
3
import isEqual from 'react-fast-compare';
4
5
interface Props {
6
action: string | string[];
7
matchAny?: boolean;
8
renderOnError?: React.ReactNode | null;
9
children: React.ReactNode;
10
}
11
12
const Can = ({ action, matchAny = false, renderOnError, children }: Props) => {
13
const can = usePermissions(action);
14
15
return (
16
<>
17
{(matchAny && can.filter((p) => p).length > 0) || (!matchAny && can.every((p) => p))
18
? children
19
: renderOnError}
20
</>
21
);
22
};
23
24
export default memo(Can, isEqual);
25
26