import React, { useEffect, useRef } from 'react'
import { Link, Head, useForm, usePage } from '@inertiajs/react'
import { toast } from 'react-toastify'
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout'
import PrimaryButton from '@/Components/PrimaryButton'
import InputLabel from '@/Components/InputLabel'
import TextInput from '@/Components/TextInput'
import InputError from '@/Components/InputError'
import InputFile from '@/Components/InputFile'
export default function FormDocument(props) {
const inputDocument = useRef()
const { types, categories, doc }= props
const { props: {auth: { user }} } = usePage()
const { data, setData, post, processing, errors } = useForm({
no_doc: '',
name: '',
company_name: '',
type_id: '',
category_id: '',
publisher: '',
description: '',
publish_date: '',
due_date: '',
status: 0,
type: 0,
group: user.group,
region: user.region,
document: null,
document_name: '',
});
useEffect(() => {
if(doc !== undefined) {
setData({
no_doc: doc.no_doc,
name: doc.name,
company_name: doc.company_name,
type_id: doc.type_id,
category_id: doc.category_id,
publisher: doc.publisher,
description: doc.description,
publish_date: doc.publish_date,
due_date: doc.due_date,
status: doc.status,
type: doc.type,
group: doc.group,
region: doc.region,
document: null,
document_name: doc.document,
})
}
}, [doc]);
const onHandleChange = (event) => {
setData(event.target.name, event.target.type === 'checkbox' ? event.target.checked : event.target.value);
};
const submit = (e) => {
e.preventDefault();
if(doc !== undefined) {
post(route('docs.update', doc), {
onError: () => toast.error('please recheck the data')
});
return
}
post(route('docs.store'), {
onError: () => toast.error('please recheck the data')
});
};
return (
Dokumen