import React, { useEffect, useRef } from 'react' import { Link, Head, useForm } from '@inertiajs/inertia-react' import { toast } from 'react-toastify' import {statuses} from '@/utils' 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 { types, departments, doc }= props const { data, setData, post, processing, errors, reset } = useForm({ no_doc: '', email: '', type_doc_id: '1', department_id: '1', company_name: '', first_person_name: '', second_person_name: '', start_date: '', end_date: '', pic_name: '', note: '', document: null, document_name: '', status: 0, reminder: '' }); const inputDocument = useRef() useEffect(() => { if(doc !== undefined) { setData({ no_doc: doc.no_doc, email: doc.email, type_doc_id: doc.type_doc_id, department_id: doc.department_id, company_name: doc.company_name, first_person_name: doc.first_person_name, second_person_name: doc.second_person_name, start_date: doc.start_date, end_date: doc.end_date, pic_name: doc.pic_name, note: doc.note, document: null, document_name: doc.document, status: doc.status, }) } }, [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
) }