feat: simplify permission checks by removing redundant role conditions in useCan hook

This commit is contained in:
Yoga Pangestu 2026-08-16 15:41:13 +07:00
parent 953a395f24
commit 85ba5631b3
2 changed files with 11 additions and 19 deletions

View File

@ -104,7 +104,7 @@ const hrItems: NavMenuItem[] = [
const sistemItems: NavMenuItem[] = [
{ title: 'Pengaturan', href: '/admin/settings', icon: Settings, permission: ['settings.view_system', 'settings.view_homepage', 'settings.view_social_media', 'settings.view_hr'] },
// { title: 'Role & Permission', href: rolesIndex.url(), icon: Shield, permission: 'roles.view' },
{ title: 'Role & Permission', href: rolesIndex.url(), icon: Shield, permission: 'roles.view' },
// { title: 'Log Aktivitas', href: '#', icon: Activity, permission: 'activity_logs.view' },
];

View File

@ -18,8 +18,8 @@ type PageProps = {
function extractNames(items?: RoleOrPermission[]): string[] {
if (!items) {
return [];
}
return [];
}
return items.map((item) => (typeof item === 'string' ? item : item.name));
}
@ -33,40 +33,32 @@ export function useCan() {
function can(permission: string): boolean {
if (!user) {
return false;
}
if (roleNames.includes('developer') || roleNames.includes('owner')) {
return true;
}
return false;
}
return permissionNames.includes(permission);
}
function canAny(...permissions: string[]): boolean {
if (!user) {
return false;
}
if (roleNames.includes('developer') || roleNames.includes('owner')) {
return true;
}
return false;
}
return permissions.some((p) => permissionNames.includes(p));
}
function hasRole(role: string): boolean {
if (!user) {
return false;
}
return false;
}
return roleNames.includes(role);
}
function hasAnyRole(roles: string[]): boolean {
if (!user) {
return false;
}
return false;
}
return roles.some((role) => roleNames.includes(role));
}