Skip to content

Commit be5f125

Browse files
feat(EmployeePersonalInfoItem): enhance edit and list permissions handling for employee links
1 parent c6c94dd commit be5f125

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

resources/js/components/helpers/employee-personal-info-item.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import HeadingSmall from '@/components/heading-small';
2+
import { Button } from '@/components/ui/button';
23
import { Item, ItemContent, ItemHeader } from '@/components/ui/item';
34
import { cn } from '@/lib/utils';
45
import employee_info from '@/routes/employee_info';
@@ -7,7 +8,6 @@ import { EmployeeInfo } from '@/types/application/employee';
78
import { Link, usePage } from '@inertiajs/react';
89
import { format } from 'date-fns';
910
import { Activity } from 'react';
10-
import { Button } from '../ui/button';
1111

1212
interface EmployeePersonalInfoItemProps {
1313
employee: EmployeeInfo;
@@ -17,16 +17,17 @@ interface EmployeePersonalInfoItemProps {
1717
export default function EmployeePersonalInfoItem({ employee, dateOfBirth }: Readonly<EmployeePersonalInfoItemProps>) {
1818
const { auth } = usePage<SharedData>().props;
1919

20+
const isNonAdminEmployee = employee.position !== 'System Administrator';
2021
const isAllowedToList = auth.permissions.includes('employee_info.index');
21-
const isAllowedToEdit = auth.permissions.includes('employee_info.edit');
22+
const isAllowedToEdit = auth.permissions.includes('employee_info.edit') && isNonAdminEmployee;
2223

2324
const employeeListLinkRoute = employee_info.index();
2425
const finalEmployeeListLinkRoute = isAllowedToList ? employeeListLinkRoute : '#';
25-
const editLinkRoute = '#'; // TODO: Update route when edit page is available
26+
27+
const editLinkRoute = employee_info.edit(employee.id);
2628
const finalEditLinkRoute = isAllowedToEdit ? editLinkRoute : '#';
2729

2830
const disabledLinkStyles = 'pointer-events-none opacity-50';
29-
const disabledLinkClass = cn((!isAllowedToEdit || !isAllowedToList) && disabledLinkStyles);
3031

3132
return (
3233
<Item variant="outline">
@@ -113,13 +114,21 @@ export default function EmployeePersonalInfoItem({ employee, dateOfBirth }: Read
113114

114115
<div className="inline-flex items-center gap-x-2 md:col-span-2">
115116
<Button variant="ghost" asChild>
116-
<Link href={finalEmployeeListLinkRoute} className={disabledLinkClass} prefetch="hover">
117+
<Link
118+
href={finalEmployeeListLinkRoute}
119+
className={cn(!isAllowedToList && disabledLinkStyles)}
120+
prefetch="hover"
121+
>
117122
List Employees
118123
</Link>
119124
</Button>
120125

121126
<Button asChild>
122-
<Link href={finalEditLinkRoute} className={disabledLinkClass} prefetch="hover">
127+
<Link
128+
href={finalEditLinkRoute}
129+
className={cn(!isAllowedToEdit && disabledLinkStyles)}
130+
prefetch="hover"
131+
>
123132
Edit Employee
124133
</Link>
125134
</Button>

0 commit comments

Comments
 (0)