import React, { useEffect } from 'react' import { useForm, usePage } from '@inertiajs/react' import { toast } from 'react-toastify' export default function FormModal(props) { const { modalState } = props const { props: { regions } } = usePage() const { data, setData, post, put, processing, errors, reset, clearErrors } = useForm({ name: '', short: '', region_id: '' }) const handleOnChange = (event) => { setData(event.target.name, event.target.type === 'checkbox' ? event.target.checked : event.target.value); } const handleReset = () => { reset() clearErrors() modalState.setData(null) } const handleCancel = () => { handleReset() modalState.toggle() } const handleSubmit = () => { const company = modalState.data if(company !== null) { put(route('companies.update', company), { onSuccess: () => Promise.all([ handleReset(), modalState.toggle(), toast.success('The Data has been changed'), ]), }) return } post(route('companies.store'), { onSuccess: () => Promise.all([ handleReset(), modalState.toggle(), toast.success('The Data has been saved'), ]), }) } useEffect(() => { const company = modalState.data if (company !== null) { setData({ name: company?.name, short: company?.short, region_id: company?.region_id, }) } }, [modalState]) return (

Perusahaan

Simpan
Batal
) }