feat: refactor column definitions to use dynamic rendering based on permissions

This commit is contained in:
Yoga Pangestu 2026-08-31 22:33:20 +07:00
parent 4350f7d9ea
commit 56c41db373
16 changed files with 135 additions and 61 deletions

View File

@ -26,7 +26,7 @@ export function createAssignmentColumns(
canViewSubmissions,
} = params;
return [
const columns: ColumnDef<Assignment>[] = [
{
accessorKey: 'title',
header: () => <span>Judul</span>,
@ -96,7 +96,10 @@ export function createAssignmentColumns(
</div>
),
},
{
];
if (canViewSubmissions || canUpdate || canDelete) {
columns.push({
id: 'actions',
header: () => <span className="block text-center">Aksi</span>,
meta: {
@ -133,6 +136,8 @@ export function createAssignmentColumns(
/>
);
},
},
];
});
}
return columns;
}

View File

@ -129,7 +129,10 @@ export default function SubmissionIndex({
<div className="text-center">{row.original.score ?? '-'}</div>
),
},
{
];
if (canUpdate || canDelete) {
columns.push({
id: 'actions',
header: () => <span className="block text-center">Aksi</span>,
meta: {
@ -156,8 +159,8 @@ export default function SubmissionIndex({
]}
/>
),
},
];
});
}
return (
<>

View File

@ -18,7 +18,7 @@ export function createMaterialColumns(
): ColumnDef<Material>[] {
const { handleEdit, handleDeleteClick, canUpdate, canDelete } = params;
return [
const columns: ColumnDef<Material>[] = [
{
accessorKey: 'meeting_number',
header: () => <span className="block text-center">Pertemuan</span>,
@ -86,7 +86,10 @@ export function createMaterialColumns(
);
},
},
{
];
if (canUpdate || canDelete) {
columns.push({
id: 'actions',
header: () => <span className="block text-center">Aksi</span>,
meta: {
@ -117,6 +120,8 @@ export function createMaterialColumns(
/>
);
},
},
];
});
}
return columns;
}

View File

@ -30,7 +30,7 @@ export function createTuitionInvoiceColumns(
canViewPayments,
} = params;
return [
const columns: ColumnDef<TuitionInvoice>[] = [
{
accessorKey: 'student.student_number',
header: () => <span>Mahasiswa</span>,
@ -126,7 +126,10 @@ export function createTuitionInvoiceColumns(
);
},
},
{
];
if (canViewPayments || canUpdate || canDelete) {
columns.push({
id: 'actions',
header: () => <span className="block text-center">Aksi</span>,
meta: {
@ -163,6 +166,8 @@ export function createTuitionInvoiceColumns(
/>
);
},
},
];
});
}
return columns;
}

View File

@ -148,7 +148,10 @@ export default function TuitionPaymentIndex({ invoice, payments }: Props) {
);
},
},
{
];
if (canUpdate || canDelete) {
columns.push({
id: 'actions',
header: () => <span className="block text-center">Aksi</span>,
meta: {
@ -175,8 +178,8 @@ export default function TuitionPaymentIndex({ invoice, payments }: Props) {
]}
/>
),
},
];
});
}
return (
<>

View File

@ -19,7 +19,7 @@ export function createAnnouncementColumns(
): ColumnDef<Announcement>[] {
const { handleEdit, handleDeleteClick, canUpdate, canDelete } = params;
return [
const columns: ColumnDef<Announcement>[] = [
{
accessorKey: 'title',
header: () => <span>Judul</span>,
@ -71,7 +71,10 @@ export function createAnnouncementColumns(
cell: ({ row }) =>
format(new Date(row.original.created_at), 'd MMM yyyy, HH:mm'),
},
{
];
if (canUpdate || canDelete) {
columns.push({
id: 'actions',
header: () => <span className="block text-center">Aksi</span>,
meta: {
@ -98,6 +101,8 @@ export function createAnnouncementColumns(
]}
/>
),
},
];
});
}
return columns;
}

View File

@ -28,7 +28,7 @@ export function createCourseClassColumns(
canViewEnrollments,
} = params;
return [
const columns: ColumnDef<CourseClass>[] = [
{
accessorKey: 'course.name',
header: () => <span>Mata Kuliah</span>,
@ -90,7 +90,10 @@ export function createCourseClassColumns(
</div>
),
},
{
];
if (canViewEnrollments || canUpdate || canDelete) {
columns.push({
id: 'actions',
header: () => <span className="block text-center">Aksi</span>,
meta: {
@ -127,6 +130,8 @@ export function createCourseClassColumns(
/>
);
},
},
];
});
}
return columns;
}

View File

@ -82,7 +82,10 @@ export default function ClassEnrollmentIndex({
: '-';
},
},
{
];
if (canDelete) {
columns.push({
id: 'actions',
header: () => <span className="block text-center">Aksi</span>,
meta: {
@ -103,8 +106,8 @@ export default function ClassEnrollmentIndex({
]}
/>
),
},
];
});
}
return (
<>

View File

@ -29,7 +29,7 @@ export function createAcademicTermColumns(
canUpdateStatus,
} = params;
return [
const columns: ColumnDef<AcademicTerm>[] = [
{
accessorKey: 'name',
header: () => <span>Nama</span>,
@ -89,7 +89,10 @@ export function createAcademicTermColumns(
);
},
},
{
];
if (canUpdate || canDelete) {
columns.push({
id: 'actions',
header: () => <span className="block text-center">Aksi</span>,
meta: {
@ -120,6 +123,8 @@ export function createAcademicTermColumns(
/>
);
},
},
];
});
}
return columns;
}

View File

@ -18,7 +18,7 @@ export function createCourseColumns(
): ColumnDef<Course>[] {
const { handleEdit, handleDeleteClick, canUpdate, canDelete } = params;
return [
const columns: ColumnDef<Course>[] = [
{
accessorKey: 'code',
header: () => <span>Kode</span>,
@ -73,7 +73,10 @@ export function createCourseColumns(
);
},
},
{
];
if (canUpdate || canDelete) {
columns.push({
id: 'actions',
header: () => <span className="block text-center">Aksi</span>,
meta: {
@ -104,6 +107,8 @@ export function createCourseColumns(
/>
);
},
},
];
});
}
return columns;
}

View File

@ -18,7 +18,7 @@ export function createDepartmentColumns(
): ColumnDef<Department>[] {
const { handleEdit, handleDeleteClick, canUpdate, canDelete } = params;
return [
const columns: ColumnDef<Department>[] = [
{
accessorKey: 'code',
header: () => <span>Kode</span>,
@ -55,7 +55,10 @@ export function createDepartmentColumns(
);
},
},
{
];
if (canUpdate || canDelete) {
columns.push({
id: 'actions',
header: () => <span className="block text-center">Aksi</span>,
meta: {
@ -86,6 +89,8 @@ export function createDepartmentColumns(
/>
);
},
},
];
});
}
return columns;
}

View File

@ -18,7 +18,7 @@ export function createAcademicAdvisingLogColumns(
): ColumnDef<AcademicAdvisingLog>[] {
const { handleEdit, handleDeleteClick, canUpdate, canDelete } = params;
return [
const columns: ColumnDef<AcademicAdvisingLog>[] = [
{
accessorKey: 'student.student_number',
header: () => <span>Mahasiswa</span>,
@ -72,7 +72,10 @@ export function createAcademicAdvisingLogColumns(
: '-';
},
},
{
];
if (canUpdate || canDelete) {
columns.push({
id: 'actions',
header: () => <span className="block text-center">Aksi</span>,
meta: {
@ -99,6 +102,8 @@ export function createAcademicAdvisingLogColumns(
]}
/>
),
},
];
});
}
return columns;
}

View File

@ -20,7 +20,7 @@ export function createLetterRequestColumns(
): ColumnDef<LetterRequest>[] {
const { handleEdit, handleDeleteClick, canUpdate, canDelete } = params;
return [
const columns: ColumnDef<LetterRequest>[] = [
{
accessorKey: 'student.student_number',
header: () => <span>Mahasiswa</span>,
@ -132,7 +132,10 @@ export function createLetterRequestColumns(
);
},
},
{
];
if (canUpdate || canDelete) {
columns.push({
id: 'actions',
header: () => <span className="block text-center">Aksi</span>,
meta: {
@ -159,6 +162,8 @@ export function createLetterRequestColumns(
]}
/>
),
},
];
});
}
return columns;
}

View File

@ -38,7 +38,7 @@ export function createAdministratorColumns(
canUpdateStatus,
} = params;
return [
const columns: ColumnDef<Administrator>[] = [
{
accessorKey: 'profile.full_name',
header: () => <span>Nama Lengkap</span>,
@ -86,7 +86,10 @@ export function createAdministratorColumns(
/>
),
},
{
];
if (canUpdate || canResetPassword || canDelete) {
columns.push({
id: 'actions',
header: () => <span className="block text-center">Aksi</span>,
meta: {
@ -123,6 +126,8 @@ export function createAdministratorColumns(
/>
);
},
},
];
});
}
return columns;
}

View File

@ -41,7 +41,7 @@ export function createLecturerColumns(
canUpdateStatus,
} = params;
return [
const columns: ColumnDef<Lecturer>[] = [
{
id: 'identity',
header: () => <span>NIDN</span>,
@ -104,7 +104,10 @@ export function createLecturerColumns(
/>
),
},
{
];
if (canUpdate || canResetPassword || canDelete) {
columns.push({
id: 'actions',
header: () => <span className="block text-center">Aksi</span>,
meta: {
@ -141,6 +144,8 @@ export function createLecturerColumns(
/>
);
},
},
];
});
}
return columns;
}

View File

@ -63,7 +63,7 @@ export function createStudentColumns(
canUpdateAccountStatus,
} = params;
return [
const columns: ColumnDef<Student>[] = [
{
id: 'identity',
header: () => <span>NIM</span>,
@ -143,7 +143,10 @@ export function createStudentColumns(
/>
),
},
{
];
if (canUpdate || canResetPassword || canDelete) {
columns.push({
id: 'actions',
header: () => <span className="block text-center">Aksi</span>,
meta: {
@ -180,6 +183,8 @@ export function createStudentColumns(
/>
);
},
},
];
});
}
return columns;
}