- Implemented RoleEdit component for editing roles with permissions. - Created RoleIndex component for listing roles with delete confirmation. - Added routes for role management in web.php with appropriate permissions. - Developed RoleTest to cover authentication, authorization, and data integrity for role management.
90 lines
2.8 KiB
TypeScript
90 lines
2.8 KiB
TypeScript
import { ConfirmDialog } from '@/components/confirm-dialog';
|
|
import { DataTable } from '@/components/data-table';
|
|
import { Button } from '@/components/ui/button';
|
|
import { index as rolesIndex, create as roleCreate, edit as roleEdit, destroy as roleDestroy } from '@/routes/admin/settings/roles';
|
|
import { Head, router } from '@inertiajs/react';
|
|
import { Plus } from 'lucide-react';
|
|
import { useState } from 'react';
|
|
import { createRoleColumns, type Role } from './columns';
|
|
|
|
type Props = {
|
|
roles: Role[];
|
|
};
|
|
|
|
export default function RoleIndex({ roles }: Props) {
|
|
const [deleting, setDeleting] = useState<Role | null>(null);
|
|
|
|
function handleDelete() {
|
|
if (!deleting) {
|
|
return;
|
|
}
|
|
|
|
router.delete(roleDestroy.url(deleting.id), {
|
|
onSuccess: () => setDeleting(null),
|
|
});
|
|
}
|
|
|
|
const columns = createRoleColumns({
|
|
handleEdit: (role) => {
|
|
window.location.href = roleEdit.url(role.id);
|
|
},
|
|
handleDeleteClick: (role) => setDeleting(role),
|
|
});
|
|
|
|
return (
|
|
<>
|
|
<Head title="Role & Permission" />
|
|
|
|
<div className="flex h-full flex-1 flex-col gap-6 overflow-x-auto p-4 md:p-6">
|
|
<div className="flex items-center justify-between">
|
|
<div>
|
|
<h2 className="text-2xl font-semibold tracking-tight">
|
|
Role & Permission
|
|
</h2>
|
|
</div>
|
|
<Button asChild>
|
|
<a href={roleCreate.url()}>
|
|
<Plus className="h-4 w-4" />
|
|
Tambah
|
|
</a>
|
|
</Button>
|
|
</div>
|
|
|
|
<DataTable
|
|
columns={columns}
|
|
data={roles}
|
|
searchKey="name"
|
|
searchPlaceholder="Cari role..."
|
|
emptyText="Belum ada data role."
|
|
/>
|
|
|
|
<ConfirmDialog
|
|
open={deleting !== null}
|
|
onOpenChange={(open) => {
|
|
if (!open) {
|
|
setDeleting(null);
|
|
}
|
|
}}
|
|
title="Hapus Role"
|
|
description={`Apakah Anda yakin ingin menghapus role "${deleting?.name}"? Semua user dengan role ini akan kehilangan permission terkait.`}
|
|
confirmLabel="Hapus"
|
|
onConfirm={handleDelete}
|
|
/>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|
|
|
|
RoleIndex.layout = {
|
|
breadcrumbs: [
|
|
{
|
|
title: 'Pengaturan',
|
|
href: '/admin/settings',
|
|
},
|
|
{
|
|
title: 'Role & Permission',
|
|
href: rolesIndex.url(),
|
|
},
|
|
],
|
|
};
|