siakad-itm/resources/js/pages/admin/users/lecturers/columns.tsx
Yoga Pangestu 07a00a92a2
Some checks failed
tests / ci (pull_request) Has been cancelled
Refactor lecturer management to support multiple departments
- Updated LecturerController to load multiple departments for lecturers.
- Modified LecturerRequest to accept an array of department IDs instead of a single department ID.
- Changed Department model to establish a many-to-many relationship with Lecturer.
- Adjusted Lecturer model to reflect the new many-to-many relationship with Department.
- Updated LecturerService to handle multiple departments during creation and updates.
- Created LecturerFactory and StudentFactory for generating test data.
- Added a migration for the new lecturer_department pivot table.
- Refactored seeder classes to accommodate the new structure for lecturers and departments.
- Enhanced frontend components for creating and editing lecturers to support multiple department selection.
2026-08-30 12:18:13 +07:00

135 lines
4.5 KiB
TypeScript

import type { ColumnDef } from '@tanstack/react-table';
import { Key, Pencil, Trash2 } from 'lucide-react';
import { ActiveStatusSwitch } from '@/components/active-status-switch';
import { GenderBadge } from '@/components/gender-badge';
import { RowActions } from '@/components/row-actions';
export type Lecturer = {
id: number;
username: string;
email: string;
is_active: boolean;
profile: { full_name: string; phone_number: string; gender: string } | null;
lecturer: {
lecturer_number: string;
departments: { id: number; name: string }[];
} | null;
};
type CreateColumnsParams = {
handleEdit: (lecturer: Lecturer) => void;
handleDeleteClick: (lecturer: Lecturer) => void;
handleResetPassword: (lecturer: Lecturer) => void;
handleUserStatusChange: (lecturer: Lecturer, isActive: boolean) => void;
};
export function createLecturerColumns(
params: CreateColumnsParams,
): ColumnDef<Lecturer>[] {
const {
handleEdit,
handleDeleteClick,
handleResetPassword,
handleUserStatusChange,
} = params;
return [
{
id: 'identity',
header: () => <span>NIDN</span>,
cell: ({ row }) => (
<div className="flex flex-col">
<span>{row.original.lecturer?.lecturer_number ?? '-'}</span>
<span className="text-sm text-muted-foreground">
{row.original.profile?.full_name ?? '-'}
</span>
</div>
),
},
{
id: 'account',
header: () => <span>Akun</span>,
cell: ({ row }) => (
<div className="flex flex-col">
<span>{row.original.username}</span>
<span className="text-sm text-muted-foreground">
{row.original.email}
</span>
</div>
),
},
{
id: 'departments',
header: () => <span>Jurusan</span>,
cell: ({ row }) => {
const departments = row.original.lecturer?.departments ?? [];
return departments.length > 0
? departments
.map((department) => department.name)
.join(', ')
: '-';
},
},
{
accessorKey: 'profile.phone_number',
header: () => <span>Nomor Telepon</span>,
cell: ({ row }) => row.original.profile?.phone_number ?? '-',
},
{
accessorKey: 'profile.gender',
header: () => <span>Jenis Kelamin</span>,
cell: ({ row }) => (
<GenderBadge gender={row.original.profile?.gender} />
),
},
{
accessorKey: 'is_active',
header: () => <span>Status Akun</span>,
cell: ({ row }) => (
<ActiveStatusSwitch
isActive={row.original.is_active}
onChange={(isActive) =>
handleUserStatusChange(row.original, isActive)
}
/>
),
},
{
id: 'actions',
header: () => <span className="block text-center">Aksi</span>,
meta: {
className: 'w-[100px] text-center',
headerClassName: 'w-[100px] text-center',
},
cell: ({ row }) => {
const lecturer = row.original;
return (
<RowActions
actions={[
{
label: 'Edit',
icon: <Pencil className="h-4 w-4" />,
onClick: () => handleEdit(lecturer),
},
{
label: 'Reset Kata Sandi',
icon: <Key className="h-4 w-4" />,
onClick: () => handleResetPassword(lecturer),
},
{
label: 'Hapus',
icon: (
<Trash2 className="h-4 w-4 text-destructive" />
),
onClick: () => handleDeleteClick(lecturer),
},
]}
/>
);
},
},
];
}