import React, { useEffect, useRef } from 'react' import NumberFormat from 'react-number-format' import { useForm } from '@inertiajs/inertia-react' import { toast } from 'react-toastify' import { formatIDR } from '@/utils' export default function FormEmployeeModal(props) { const { isOpen, toggle = () => {}, employee = null } = props const { data, setData, post, processing, errors, clearErrors } = useForm({ name: '', whatsapp: '', basic_salary: 0, photo: null, img_alt: null, }) const inputPhoto = useRef() const handleOnChange = (event) => { setData(event.target.name, event.target.value) } const handleReset = () => { setData({ name: '', whatsapp: '', basic_salary: 0, photo: null, img_alt: null, }) clearErrors() } const handleCancel = () => { handleReset() toggle() } const handleSubmit = () => { if (employee !== null) { post(route('employees.update', employee), { forceFormData: true, onSuccess: () => Promise.all([ handleReset(), toggle(), toast.success('The Data has been changed'), ]), }) return } post(route('employees.store'), { onSuccess: () => Promise.all([ handleReset(), toggle(), toast.success('The Data has been saved'), ]), }) } useEffect(() => { setData({ name: employee?.name ? employee.name : '', whatsapp: employee?.whatsapp ? employee.whatsapp : '', basic_salary: employee?.basic_salary ? formatIDR(employee.basic_salary) : '', img_alt: employee?.photo_url ? employee.photo_url : null, }) }, [employee]) return (

Barang

setData('basic_salary', value)} placeholder="gaji pokok" />
{ console.log(inputPhoto.current.click()) }} > {data.photo ? data.photo.name : ''}
setData('photo', e.target.files[0])} accept="image/png, image/jpeg, image/jpg" />
{data.img_alt !== null && }
Simpan
Batal
) }