feat: inisialisasi project kit v2
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import { usePage } from '@inertiajs/react';
|
||||
import React from 'react';
|
||||
import { PageProps } from '@/types';
|
||||
|
||||
interface CanProps {
|
||||
ability: string | string[];
|
||||
children: React.ReactNode;
|
||||
fallback?: React.ReactNode;
|
||||
}
|
||||
|
||||
export function Can({ ability, children, fallback = null }: CanProps) {
|
||||
const { permissions } = usePage<PageProps>().props.auth;
|
||||
const abilities = Array.isArray(ability) ? ability : [ability];
|
||||
|
||||
const allowed = abilities.some(a => permissions.includes(a));
|
||||
|
||||
return allowed ? <>{children}</> : <>{fallback}</>;
|
||||
}
|
||||
Reference in New Issue
Block a user