import React, { useEffect, useState } from 'react' import { toast } from 'react-toastify' import { Modal } from '@/Components/Modal' import { useForm } from '@inertiajs/inertia-react' import Button from '@/Components/Button' import Input from '@/Components/Input' import { getAll } from '@/Services/Karyawan' import { create } from '@/Services/Absensi' export default function FormModal({ modalState, periode }) { const [loading, setLoading] = useState(false) const { data, setData, reset } = useForm({ users: [] }) useEffect(() => { getAll() .then(items => setData({ users: items.filter(item => item.data.jabatan.id != "1").map(item => { return { id: item.id, name: item.data.name, nik: item.data.nik, jenisKelamin: item.data.jenisKelamin, jabatan: item.data.jabatan.nama, jabatan_id: item.data.jabatan.id, hadir: 0, sakit: 0, alfa: 0, } }) })) },[modalState]) const onHandleChange = (item, event) => { setData({ users: data.users.map(user => { if (user.id == item.id) { user[event.target.name] = event.target.value } return user }) }) } const submit = (e) => { e.preventDefault() setLoading(true) create({ ...data, periode: periode, }) .then(() => { reset() modalState.toggle() toast.success("berhasil menambahkan absensi") }) .finally(() => setLoading(false)) } return (
Absensi Karyawan
Periode : {periode}
{data.users.map(item => ( ))}
NIK Nama Jenis Kelamin Jabatan Hadir Sakit Alfa
{item.nik} {item.name} {item.jenisKelamin} {item.jabatan} onHandleChange(item, e)}/> onHandleChange(item, e)}/> onHandleChange(item, e)}/>
) }