import React, { useEffect, useState } from 'react' import { router } from '@inertiajs/react' import { usePrevious } from 'react-use' import { Head } from '@inertiajs/react' import { Button, Dropdown } from 'flowbite-react' import { HiPencil, HiTrash } from 'react-icons/hi' import { useModalState } from '@/hooks' import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout' import Pagination from '@/Components/Pagination' import ModalConfirm from '@/Components/ModalConfirm' import FormModal from './FormModal' import SearchInput from '@/Components/SearchInput' import { hasPermission } from '@/utils' export default function Info(props) { const { query: { links, data }, auth, } = props const confirmModal = useModalState() const formModal = useModalState() const toggleFormModal = (info = null) => { formModal.setData(info) formModal.toggle() } const handleDeleteClick = (info) => { confirmModal.setData(info) confirmModal.toggle() } const onDelete = () => { if (confirmModal.data !== null) { router.delete(route('info.destroy', confirmModal.data.id)) } } const canCreate = hasPermission(auth, 'create-info') const canUpdate = hasPermission(auth, 'update-info') const canDelete = hasPermission(auth, 'delete-info') return (
{canCreate && ( )}
{data.map((info) => ( ))}
Info Publish
{info.title} {info.is_publish === 1 ? 'Yes' : 'No'} {canUpdate && ( toggleFormModal( info ) } >
Ubah
)} {canDelete && ( handleDeleteClick( info ) } >
Hapus
)}
) }