Files

16 lines
483 B
TypeScript
Raw Permalink Normal View History

2026-10-05 18:10:18 -04:00
import React from 'react';
2020-03-29 14:19:17 -07:00
import { usePermissions } from '@/plugins/usePermissions';
interface Props {
action: string | string[];
matchAny?: boolean;
renderOnError?: React.ReactNode | null;
children: React.ReactNode;
}
2026-10-05 18:10:18 -04:00
export default function Can({ action, matchAny = false, renderOnError, children }: Props) {
2020-03-29 14:19:17 -07:00
const can = usePermissions(action);
2026-10-08 16:53:20 -04:00
return (matchAny && can.some((p) => p)) || (!matchAny && can.every((p) => p)) ? children : renderOnError;
2026-10-05 18:10:18 -04:00
}