misc_pterodactyl-panel/resources/scripts/components/elements/Can.tsx

25 lines
650 B
TypeScript
Raw Normal View History

import React, { memo } from 'react';
2020-03-29 21:19:17 +00:00
import { usePermissions } from '@/plugins/usePermissions';
import isEqual from 'react-fast-compare';
interface Props {
action: string | string[];
matchAny?: boolean;
renderOnError?: React.ReactNode | null;
children: React.ReactNode;
}
const Can = ({ action, matchAny = false, renderOnError, children }: Props) => {
2020-03-29 21:19:17 +00:00
const can = usePermissions(action);
return (
<>
{(matchAny && can.filter((p) => p).length > 0) || (!matchAny && can.every((p) => p))
? children
: renderOnError}
</>
);
};
export default memo(Can, isEqual);