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'
export default function Form(props) {
const { user } = props
const { data, setData, post, processing, errors } = useForm({
name: '',
email: '',
password: '',
role_id: null,
role: '',
username: '',
phone_wa: '',
photo: null,
photo_url: '',
})
const handleOnChange = (event) => {
setData(
event.target.name,
event.target.type === 'checkbox'
? event.target.checked
? 1
: 0
: event.target.value
)
}
const handleSubmit = () => {
if (isEmpty(user) === false) {
post(route('user.update', user), {
onSuccess: () => handleClose(),
})
return
}
post(route('user.store'), {
onSuccess: () => handleClose(),
})
}
useEffect(() => {
if (isEmpty(user) === false) {
setData({
name: user.name,
email: user.email,
role_id: user.role_id,
role: user.role,
username: user.username,
phone_wa: user.phone_wa,
photo: null,
photo_url: user.photo_url,
})
}
}, [user])
return (