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, companies, doc }= props const { data, setData, post, processing, errors } = useForm({ no_doc: '', name: '', type_id: '', category_id: '', publisher: '', description: '', publish_date: '', due_date: '', status: 0, type: 0, company_id: '', document: null, document_name: '', }); useEffect(() => { if(doc !== undefined) { setData({ no_doc: doc.no_doc, name: doc.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, company_id: doc.company_id, 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

setData('document', e.target.files[0])} /> {doc !== undefined && (

file saved is found, reupload to replace

)}
Simpan Batal
) }