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/Karyawan'; import { toast } from 'react-toastify'; export default function Karyawan(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 (
Karyawan
{items.map(item => ( ))}
Nama Jabatan
{item.data.name} {item.data.jabatan.nama}
{item.data.jabatan.id != "1" && ( )}
); }