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 Types(props) { const { data: groups, links } = props.groups const formModal = useModalState(false) const toggle = (group = null) => { formModal.setData(group) formModal.toggle() } const confirmModal = useModalState(false) const handleDelete = (group) => { confirmModal.setData(group) confirmModal.toggle() } const onDelete = () => { const group = confirmModal.data if(group != null) { router.delete(route('groups.destroy', group), { onSuccess: () => toast.success('The Data has been deleted'), }) } } const canCreate = hasPermission('create-group', props.auth.user) const canUpdate = hasPermission('update-group', props.auth.user) const canDelete = hasPermission('delete-group', props.auth.user) return (
{canCreate && (
toggle()} > Tambah
)}
{groups?.map((group) => ( ))}
Id Nama
{group.id} {group.name} {canUpdate && (
toggle(group) } > Edit
)} {canDelete && (
handleDelete(group) } > Delete
)}
) }