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