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 { data, setData, post, put, processing, errors, reset, clearErrors } = useForm({ name: '', }) 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 classification = modalState.data if(classification !== null) { put(route('classifications.update', classification), { onSuccess: () => Promise.all([ handleReset(), modalState.toggle(), toast.success('The Data has been changed'), ]), }) return } post(route('classifications.store'), { onSuccess: () => Promise.all([ handleReset(), modalState.toggle(), toast.success('The Data has been saved'), ]), }) } useEffect(() => { const classification = modalState.data if (classification !== null) { setData({ name: classification?.name, }) } }, [modalState]) return (

Klasifikasi

Simpan
Batal
) }