mirror of
https://github.com/pterodactyl/panel.git
synced 2026-11-30 11:25:52 -05:00
Co-authored-by: Anthony <anthony@infraly.co> Co-authored-by: Sky Mulley <daniel.mulley@outlook.com>
22 lines
573 B
TypeScript
22 lines
573 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;
|
|
}
|
|
|
|
export default function Can({ action, matchAny = false, renderOnError, children }: Props) {
|
|
const can = usePermissions(action);
|
|
|
|
return (
|
|
<>
|
|
{(matchAny && can.filter((p) => p).length > 0) || (!matchAny && can.every((p) => p))
|
|
? children
|
|
: renderOnError}
|
|
</>
|
|
);
|
|
}
|