feat: enhance payroll functionality by adding user authentication and role checks
This commit is contained in:
parent
7976a457f5
commit
ec5da5c5ba
@ -28,6 +28,7 @@ export type Payroll = {
|
|||||||
|
|
||||||
export type PayrollAdjustment = {
|
export type PayrollAdjustment = {
|
||||||
id: number;
|
id: number;
|
||||||
|
created_by_id: number;
|
||||||
type: 'bonus' | 'deduction';
|
type: 'bonus' | 'deduction';
|
||||||
amount: number;
|
amount: number;
|
||||||
description: string;
|
description: string;
|
||||||
@ -68,6 +69,8 @@ type CreateColumnsParams = {
|
|||||||
payrollId: number,
|
payrollId: number,
|
||||||
) => void;
|
) => void;
|
||||||
can: (permission: string) => boolean;
|
can: (permission: string) => boolean;
|
||||||
|
hasAnyRole: (roles: string[]) => boolean;
|
||||||
|
userId: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function createPayrollColumns(
|
export function createPayrollColumns(
|
||||||
@ -79,6 +82,8 @@ export function createPayrollColumns(
|
|||||||
handleAddAdjustment,
|
handleAddAdjustment,
|
||||||
handleDeleteAdjustment,
|
handleDeleteAdjustment,
|
||||||
can,
|
can,
|
||||||
|
hasAnyRole,
|
||||||
|
userId,
|
||||||
} = params;
|
} = params;
|
||||||
|
|
||||||
const hasAnyPayrollAction = can('payroll.adjust') || can('payroll.pay') || can('payroll.cancel');
|
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">
|
<span className="max-w-[100px] text-muted-foreground">
|
||||||
{adj.description}
|
{adj.description}
|
||||||
</span>
|
</span>
|
||||||
{can('payroll.adjust') && payroll.status === 'unpaid' && (
|
{can('payroll.adjust') && payroll.status === 'unpaid' && (adj.created_by_id === userId || hasAnyRole(['developer', 'owner'])) && (
|
||||||
<button
|
<button
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
handleDeleteAdjustment(
|
handleDeleteAdjustment(
|
||||||
|
|||||||
@ -38,9 +38,14 @@ type Props = {
|
|||||||
status: string;
|
status: string;
|
||||||
payrolls: Payroll[];
|
payrolls: Payroll[];
|
||||||
};
|
};
|
||||||
|
auth: {
|
||||||
|
user: {
|
||||||
|
id: number;
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function PayrollPeriodShow({ payrollPeriod }: Props) {
|
export default function PayrollPeriodShow({ payrollPeriod, auth }: Props) {
|
||||||
const { can, hasAnyRole } = useCan();
|
const { can, hasAnyRole } = useCan();
|
||||||
const canViewAll = hasAnyRole(['developer', 'owner', 'direktur', 'admin-toko']);
|
const canViewAll = hasAnyRole(['developer', 'owner', 'direktur', 'admin-toko']);
|
||||||
const [paying, setPaying] = useState<Payroll | null>(null);
|
const [paying, setPaying] = useState<Payroll | null>(null);
|
||||||
@ -103,6 +108,8 @@ export default function PayrollPeriodShow({ payrollPeriod }: Props) {
|
|||||||
setDeletingAdjustment({ adjustment, payrollId });
|
setDeletingAdjustment({ adjustment, payrollId });
|
||||||
},
|
},
|
||||||
can,
|
can,
|
||||||
|
hasAnyRole,
|
||||||
|
userId: auth.user.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
const activePayrolls = payrollPeriod.payrolls.filter(
|
const activePayrolls = payrollPeriod.payrolls.filter(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user