siakad-itm/resources/js/pages/admin/master/departments/columns.tsx
Yoga Pangestu 5994f38f01 feat: implement permission checks for academic terms, courses, departments, and user management
- Added permission checks for creating, updating, and deleting academic terms, courses, and departments.
- Updated the routes to enforce permissions for various actions in the admin panel.
- Enhanced user management by adding permissions for administrators, lecturers, and students.
- Refactored components to conditionally render actions based on user permissions.
- Updated the auth type to include optional permissions array for user roles.
2026-08-30 23:27:31 +07:00

92 lines
3.1 KiB
TypeScript

import type { ColumnDef } from '@tanstack/react-table';
import { Pencil, Trash2 } from 'lucide-react';
import { RowActions } from '@/components/row-actions';
import { Badge } from '@/components/ui/badge';
import type { Department } from '@/types/department';
export type { Department } from '@/types/department';
type CreateColumnsParams = {
handleEdit: (department: Department) => void;
handleDeleteClick: (department: Department) => void;
canUpdate: boolean;
canDelete: boolean;
};
export function createDepartmentColumns(
params: CreateColumnsParams,
): ColumnDef<Department>[] {
const { handleEdit, handleDeleteClick, canUpdate, canDelete } = params;
return [
{
accessorKey: 'code',
header: () => <span>Kode</span>,
cell: ({ row }) => (
<span className="font-medium">
{row.getValue('code') as string}
</span>
),
},
{
accessorKey: 'name',
header: () => <span>Nama</span>,
cell: ({ row }) => <span>{row.getValue('name') as string}</span>,
},
{
accessorKey: 'degree_level',
header: () => <span className="block text-center">Jenjang</span>,
meta: {
className: 'w-[100px] text-center',
headerClassName: 'w-[100px] text-center',
},
cell: ({ row }) => {
const degreeLevel = row.getValue('degree_level') as
string | null;
return (
<div className="flex justify-center">
{degreeLevel ? (
<Badge variant="secondary">{degreeLevel}</Badge>
) : (
<span className="text-muted-foreground">-</span>
)}
</div>
);
},
},
{
id: 'actions',
header: () => <span className="block text-center">Aksi</span>,
meta: {
className: 'w-[100px] text-center',
headerClassName: 'w-[100px] text-center',
},
cell: ({ row }) => {
const department = row.original;
return (
<RowActions
actions={[
{
label: 'Edit',
icon: <Pencil className="h-4 w-4" />,
show: canUpdate,
onClick: () => handleEdit(department),
},
{
label: 'Hapus',
icon: (
<Trash2 className="h-4 w-4 text-destructive" />
),
show: canDelete,
onClick: () => handleDeleteClick(department),
},
]}
/>
);
},
},
];
}