siakad-itm/resources/js/pages/admin/manage/announcements/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

104 lines
3.6 KiB
TypeScript

import type { ColumnDef } from '@tanstack/react-table';
import { format } from 'date-fns';
import { Pencil, Trash2 } from 'lucide-react';
import { RowActions } from '@/components/row-actions';
import { Badge } from '@/components/ui/badge';
import type { Announcement } from '@/types/announcement';
export type { Announcement } from '@/types/announcement';
type CreateColumnsParams = {
handleEdit: (announcement: Announcement) => void;
handleDeleteClick: (announcement: Announcement) => void;
canUpdate: boolean;
canDelete: boolean;
};
export function createAnnouncementColumns(
params: CreateColumnsParams,
): ColumnDef<Announcement>[] {
const { handleEdit, handleDeleteClick, canUpdate, canDelete } = params;
return [
{
accessorKey: 'title',
header: () => <span>Judul</span>,
cell: ({ row }) => {
const announcement = row.original;
return (
<div>
<p className="font-medium">{announcement.title}</p>
<p className="line-clamp-1 max-w-md text-xs text-muted-foreground">
{announcement.content}
</p>
</div>
);
},
},
{
accessorKey: 'department.name',
header: () => <span>Target</span>,
cell: ({ row }) => {
const announcement = row.original;
if (!announcement.department && !announcement.enrollment_year) {
return <Badge variant="outline">Semua Mahasiswa</Badge>;
}
return (
<div className="flex flex-wrap gap-1">
<Badge variant="secondary">
{announcement.department?.name ?? 'Semua Jurusan'}
</Badge>
{announcement.enrollment_year && (
<Badge variant="secondary">
Angkatan {announcement.enrollment_year}
</Badge>
)}
</div>
);
},
},
{
accessorKey: 'creator.profile.full_name',
header: () => <span>Dibuat Oleh</span>,
cell: ({ row }) => row.original.creator?.profile?.full_name ?? '-',
},
{
accessorKey: 'created_at',
header: () => <span>Tanggal</span>,
cell: ({ row }) =>
format(new Date(row.original.created_at), 'd MMM yyyy, HH:mm'),
},
{
id: 'actions',
header: () => <span className="block text-center">Aksi</span>,
meta: {
className: 'w-[100px] text-center',
headerClassName: 'w-[100px] text-center',
},
cell: ({ row }) => (
<RowActions
actions={[
{
label: 'Edit',
icon: <Pencil className="h-4 w-4" />,
show: canUpdate,
onClick: () => handleEdit(row.original),
},
{
label: 'Hapus',
icon: (
<Trash2 className="h-4 w-4 text-destructive" />
),
show: canDelete,
onClick: () => handleDeleteClick(row.original),
},
]}
/>
),
},
];
}