11import HeadingSmall from '@/components/heading-small' ;
2+ import { Button } from '@/components/ui/button' ;
23import { Item , ItemContent , ItemHeader } from '@/components/ui/item' ;
34import { cn } from '@/lib/utils' ;
45import employee_info from '@/routes/employee_info' ;
@@ -7,7 +8,6 @@ import { EmployeeInfo } from '@/types/application/employee';
78import { Link , usePage } from '@inertiajs/react' ;
89import { format } from 'date-fns' ;
910import { Activity } from 'react' ;
10- import { Button } from '../ui/button' ;
1111
1212interface EmployeePersonalInfoItemProps {
1313 employee : EmployeeInfo ;
@@ -17,16 +17,17 @@ interface EmployeePersonalInfoItemProps {
1717export 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