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