import React from 'react' import { Head } from '@inertiajs/react' import { router } from '@inertiajs/react' import { toast } from 'react-toastify' import { useModalState } from '@/Hooks' import { hasPermission } from '@/utils' import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout' import Pagination from '@/Components/Pagination' import ModalConfirm from '@/Components/ModalConfirm' import FormModal from './FormModal' export default function Roles(props) { const { data: roles, links } = props.roles const formModal = useModalState(false) const toggle = (role = null) => { formModal.setData(role) formModal.toggle() } const confirmModal = useModalState(false) const handleDelete = (role) => { confirmModal.setData(role) confirmModal.toggle() } const onDelete = () => { const role = confirmModal.data if(role != null) { router.delete(route('roles.destroy', role), { onSuccess: () => toast.success('The Data has been deleted'), }) } } const canCreate = hasPermission('create-role', props.auth.user) const canUpdate = hasPermission('update-role', props.auth.user) const canDelete = hasPermission('delete-role', props.auth.user) return (
{canCreate && (
toggle()} > Tambah
)}
{roles?.map((role) => ( ))}
Id Nama
{role.id} {role.name} {canUpdate && (
toggle(role) } > Edit
)} {canDelete && (
handleDelete(role) } > Delete
)}
) }