feat: enhance payroll functionality by adding user authentication and role checks

This commit is contained in:
Yoga Pangestu 2026-08-14 03:47:47 +07:00
parent 7976a457f5
commit ec5da5c5ba
2 changed files with 14 additions and 2 deletions

View File

@ -28,6 +28,7 @@ export type Payroll = {
export type PayrollAdjustment = {
id: number;
created_by_id: number;
type: 'bonus' | 'deduction';
amount: number;
description: string;
@ -68,6 +69,8 @@ type CreateColumnsParams = {
payrollId: number,
) => void;
can: (permission: string) => boolean;
hasAnyRole: (roles: string[]) => boolean;
userId: number;
};
export function createPayrollColumns(
@ -79,6 +82,8 @@ export function createPayrollColumns(
handleAddAdjustment,
handleDeleteAdjustment,
can,
hasAnyRole,
userId,
} = params;
const hasAnyPayrollAction = can('payroll.adjust') || can('payroll.pay') || can('payroll.cancel');
@ -187,7 +192,7 @@ export function createPayrollColumns(
<span className="max-w-[100px] text-muted-foreground">
{adj.description}
</span>
{can('payroll.adjust') && payroll.status === 'unpaid' && (
{can('payroll.adjust') && payroll.status === 'unpaid' && (adj.created_by_id === userId || hasAnyRole(['developer', 'owner'])) && (
<button
onClick={() =>
handleDeleteAdjustment(

View File

@ -38,9 +38,14 @@ type Props = {
status: string;
payrolls: Payroll[];
};
auth: {
user: {
id: number;
};
};
};
export default function PayrollPeriodShow({ payrollPeriod }: Props) {
export default function PayrollPeriodShow({ payrollPeriod, auth }: Props) {
const { can, hasAnyRole } = useCan();
const canViewAll = hasAnyRole(['developer', 'owner', 'direktur', 'admin-toko']);
const [paying, setPaying] = useState<Payroll | null>(null);
@ -103,6 +108,8 @@ export default function PayrollPeriodShow({ payrollPeriod }: Props) {
setDeletingAdjustment({ adjustment, payrollId });
},
can,
hasAnyRole,
userId: auth.user.id,
});
const activePayrolls = payrollPeriod.payrolls.filter(