import React, { useEffect } from 'react' import Modal from '@/Components/Modal' import { useForm, usePage } from '@inertiajs/react' import Button from '@/Components/Button' import FormInput from '@/Components/FormInput' import RoleSelectionInput from '../Role/SelectionInput' import { isEmpty } from 'lodash' export default function FormModal(props) { const { props: { levels }, } = usePage() const { modalState } = props const { data, setData, post, put, processing, errors, reset, clearErrors } = useForm({ amount_buy: 0, bonus_coin: 0, customer_level_id: null, }) const handleOnChange = (event) => { setData( event.target.name, event.target.type === 'checkbox' ? event.target.checked ? 1 : 0 : event.target.value ) } const handleReset = () => { modalState.setData(null) reset() clearErrors() } const handleClose = () => { handleReset() modalState.toggle() } const handleSubmit = () => { const reward = modalState.data if (reward !== null) { put(route('coin-reward.update', reward), { onSuccess: () => handleClose(), }) return } post(route('coin-reward.store'), { onSuccess: () => handleClose(), }) } useEffect(() => { const reward = modalState.data if (isEmpty(reward) === false) { setData({ amount_buy: reward.amount_buy, bonus_coin: reward.bonus_coin, customer_level_id: reward.customer_level_id, }) return } }, [modalState]) return (
Level
{errors.customer_level_id && (

{errors.customer_level_id}

)}
) }