- Integrated permission checks using `can` function in payroll period management to control visibility of adjustment, pay, and cancel actions. - Updated employee management to conditionally render edit, reset password, and delete actions based on permissions. - Enhanced leave request management with permission checks for approve, reject, edit, and delete actions. - Implemented permission checks in cutting management for edit and delete actions. - Added permission checks for purchase management actions including create, edit, and delete. - Integrated permission checks in restock management for create, edit, and delete actions. - Updated transaction management to conditionally render create, edit, and delete actions based on permissions. - Enhanced category management with permission checks for edit and delete actions. - Integrated permission checks in customer management for edit and delete actions. - Updated product management to conditionally render create, edit, and delete actions based on permissions. - Enhanced raw material management with permission checks for edit and delete actions. - Integrated permission checks in supplier management for edit and delete actions. - Updated role management to conditionally render edit and delete actions based on permissions.
83 lines
2.6 KiB
TypeScript
83 lines
2.6 KiB
TypeScript
import type { ColumnDef } from '@tanstack/react-table';
|
|
import { Pencil, Trash2 } from 'lucide-react';
|
|
import { RowActions } from '@/components/row-actions';
|
|
|
|
export type Customer = {
|
|
id: number;
|
|
name: string;
|
|
phone_number: string | null;
|
|
address: string | null;
|
|
};
|
|
|
|
type CreateColumnsParams = {
|
|
handleEdit: (customer: Customer) => void;
|
|
handleDeleteClick: (customer: Customer) => void;
|
|
can: (permission: string) => boolean;
|
|
};
|
|
|
|
export function createCustomerColumns(
|
|
params: CreateColumnsParams,
|
|
): ColumnDef<Customer>[] {
|
|
const { handleEdit, handleDeleteClick, can } = params;
|
|
|
|
return [
|
|
{
|
|
accessorKey: 'name',
|
|
header: () => <span>Nama</span>,
|
|
cell: ({ row }) => (
|
|
<span className="font-medium">
|
|
{row.getValue('name') as string}
|
|
</span>
|
|
),
|
|
},
|
|
{
|
|
accessorKey: 'phone_number',
|
|
header: () => <span>No. Telepon</span>,
|
|
cell: ({ row }) => (
|
|
<span>{(row.getValue('phone_number') as string) ?? '-'}</span>
|
|
),
|
|
},
|
|
{
|
|
accessorKey: 'address',
|
|
header: () => <span>Alamat</span>,
|
|
cell: ({ row }) => (
|
|
<span className="block max-w-[200px] truncate">
|
|
{(row.getValue('address') as string) ?? '-'}
|
|
</span>
|
|
),
|
|
},
|
|
{
|
|
id: 'actions',
|
|
header: () => <span className="block text-center">Aksi</span>,
|
|
meta: {
|
|
className: 'w-[100px] text-center',
|
|
headerClassName: 'w-[100px] text-center',
|
|
},
|
|
cell: ({ row }) => {
|
|
const customer = row.original;
|
|
|
|
return (
|
|
<RowActions
|
|
actions={[
|
|
{
|
|
label: 'Edit',
|
|
icon: <Pencil className="h-4 w-4" />,
|
|
show: can('customers.update'),
|
|
onClick: () => handleEdit(customer),
|
|
},
|
|
{
|
|
label: 'Hapus',
|
|
icon: (
|
|
<Trash2 className="h-4 w-4 text-destructive" />
|
|
),
|
|
show: can('customers.delete'),
|
|
onClick: () => handleDeleteClick(customer),
|
|
},
|
|
]}
|
|
/>
|
|
);
|
|
},
|
|
},
|
|
];
|
|
}
|