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