import React, { useEffect, useState } from 'react'; import Authenticated from '@/Layouts/Authenticated'; import { Head } from '@inertiajs/inertia-react'; import { useModalState } from '@/Hooks' import Button from '@/Components/Button'; import FormModal from './FormModal'; import { getAll, deleteById } from '@/Services/Jabatan'; import { toast } from 'react-toastify'; export default function Jabatan(props) { const formModal = useModalState(false) const [items, setItems] = useState([]) const hanldeDeleteClick = (item) => { const con = confirm("delete item?") if (con) { deleteById(item.id) .then(() => toast.success('berhasil hapus')) .finally(() => fetchData()) } } const handleEditClick = (item) => { formModal.setData(item) formModal.toggle() } const fetchData = () => { getAll() .then(items => setItems(items)) } useEffect(() => { fetchData() }, []) return (
{items.map(item => ( ))}
ID Nama Tunjangan
{item.id} {item.data.nama} Rp. {item.data.tunjangan}
); }