You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.9 KiB
React

1 year ago
import React, { useEffect } from 'react'
import { isEmpty } from 'lodash'
1 year ago
import { Head, useForm } from '@inertiajs/react'
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout'
1 year ago
import LocationProfileSelectionInput from '../LocationProfile/SelectionInput'
import FormInput from '@/Components/FormInput'
import Button from '@/Components/Button'
export default function Form(props) {
1 year ago
const { voucher } = props
const { data, setData, post, processing, errors } = useForm({
username: '',
1 year ago
location_profile_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,
location_profile_id: voucher.location_profile_id,
})
}
}, [voucher])
return (
1 year ago
<AuthenticatedLayout
page={'Voucher'}
action={'Form'}
parent={route('voucher.location')}
>
<Head title="Voucher" />
<div>
<div className="mx-auto sm:px-6 lg:px-8">
1 year ago
<div className="overflow-hidden p-4 shadow-sm sm:rounded-lg bg-white dark:bg-gray-800 flex flex-col min-h-[500px]">
<div className="text-xl font-bold mb-4">Voucher</div>
1 year ago
<LocationProfileSelectionInput
label="Profile Lokasi"
itemSelected={data.location_profile_id}
onItemSelected={(id) =>
setData('location_profile_id', id)
}
error={errors.location_profile_id}
/>
<div className="mt-2" />
<FormInput
name="username"
value={data.username}
onChange={handleOnChange}
1 year ago
label="Kode"
error={errors.username}
/>
<div className="mt-8">
<Button
onClick={handleSubmit}
processing={processing}
>
Simpan
</Button>
</div>
</div>
</div>
</div>
</AuthenticatedLayout>
)
}