import React, { useEffect } from 'react'
import { Head, useForm } from '@inertiajs/react'
import { isEmpty } from 'lodash'
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout'
import FormInput from '@/Components/FormInput'
import FormFile from '@/Components/FormFile'
import FormInputWith from '@/Components/FormInputWith'
import Button from '@/Components/Button'
import RoleSelectionInput from '../Role/SelectionInput'
import FormInputTime from '@/Components/FormInputTime'
export default function Form(props) {
const { location } = props
const { data, setData, post, processing, errors } = useForm({
name: '',
address: '',
phone: '',
gmap_url: '',
image: null,
image_url: '',
open_hour: '00:00',
close_hour: '00:00',
is_active: 0,
})
const handleOnChange = (event) => {
setData(
event.target.name,
event.target.type === 'checkbox'
? event.target.checked
? 1
: 0
: event.target.value
)
}
const handleSubmit = () => {
if (isEmpty(location) === false) {
post(route('deposit-location.update', location))
return
}
post(route('deposit-location.store'))
}
useEffect(() => {
if (isEmpty(location) === false) {
setData({
name: location.name,
address: location.address,
phone: location.phone,
gmap_url: location.gmap_url,
image_url: location.image_url,
open_hour: location.open_hour,
close_hour: location.close_hour,
is_active: location.is_active,
})
}
}, [location])
return (