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

30 lines
703 B
TypeScript

import React from 'react';
import { usePermissions } from '@/plugins/usePermissions';
interface Props {
action: string | string[];
matchAny?: boolean;
renderOnError?: React.ReactNode | null;
children: React.ReactNode;
}
const Can = ({ action, matchAny = false, renderOnError, children }: Props) => {
const can = usePermissions(action);
if (matchAny) {
console.log('Can.tsx', can);
}
return (
<>
{
((matchAny && can.filter(p => p).length > 0) || (!matchAny && can.every(p => p))) ?
children
:
renderOnError
}
</>
);
};
export default Can;