adds access modifiers for each role

This commit is contained in:
Satyam Rastogi
2026-05-12 21:08:19 +05:30
parent fea4ad2d22
commit 455462ded4
7 changed files with 517 additions and 119 deletions
+38
View File
@@ -0,0 +1,38 @@
import { usePermissions } from '../hooks/usePermissions';
/**
* Conditionally renders children based on org-level permissions.
*
* Props:
* module permission module key (e.g. 'jobs', 'leads', 'financials')
* action single action string (e.g. 'view', 'edit', 'delete')
* any array of actions; renders if user has ANY of them
* all array of actions; renders if user has ALL of them
* fallback optional element rendered when access is denied
*
* Usage:
* <PermissionGate module="jobs" action="edit">
* <EditButton />
* </PermissionGate>
*
* <PermissionGate module="financials" any={['view', 'edit']} fallback={<LockedBanner />}>
* <FinancialsPanel />
* </PermissionGate>
*/
const PermissionGate = ({ module, action, any, all, fallback = null, children }) => {
const { can, canAny, canAll } = usePermissions();
let allowed = false;
if (action) {
allowed = can(module, action);
} else if (any) {
allowed = canAny(module, any);
} else if (all) {
allowed = canAll(module, all);
}
return allowed ? children : fallback;
};
export default PermissionGate;