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 (
Admin
+62
} name="phone_wa" value={data.phone_wa} onChange={handleOnChange} error={errors.phone_wa} formClassName={'pl-10'} label="Whatsapp" /> {data.role !== null && ( <> setData('role_id', id) } error={errors.role_id} /> )} setData('photo', e.target.files[0]) } error={errors.photo} preview={ isEmpty(data.photo_url) === false && ( preview ) } />
) }