import React, { useEffect } from 'react' import { isEmpty } from 'lodash' import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout' import FormInput from '@/Components/FormInput' import Button from '@/Components/Button' import { Head, useForm } from '@inertiajs/react' import FormInputWith from '@/Components/FormInputWith' import LocationSelectionInput from '../Location/SelectionInput' export default function Form(props) { const { voucher } = props const { data, setData, post, processing, errors } = useForm({ username: '', password: '', discount: 0, display_price: 0, quota: '', profile: '', comment: '', expired: '', expired_unit: 'Hari', location_id: null, }) const handleOnChange = (event) => { setData( event.target.name, event.target.type === 'checkbox' ? event.target.checked ? 1 : 0 : event.target.value ) } const handleSubmit = () => { if (isEmpty(voucher) === false) { post(route('voucher.update', voucher)) return } post(route('voucher.store')) } useEffect(() => { if (isEmpty(voucher) === false) { setData({ username: voucher.username, password: voucher.password, discount: voucher.discount, display_price: voucher.display_price, quota: voucher.quota, profile: voucher.profile, comment: voucher.comment, expired: voucher.expired, expired_unit: voucher.expired_unit, location_id: voucher.location_id, }) } }, [voucher]) return (
Voucher
setData('location_id', id)} error={errors.location_id} />
%
} name="discount" value={data.discount} onChange={handleOnChange} error={errors.discount} formClassName={'pr-10'} label="Discount" max={100} min={0} />
) }