import React, { useEffect, useState } from 'react' import { usePrevious } from 'react-use' import { Head, Link } from '@inertiajs/react' import { router } from '@inertiajs/react' import { toast } from 'react-toastify' import { useModalState } from '@/Hooks' import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout' import Pagination from '@/Components/Pagination' import ModalConfirm from '@/Components/ModalConfirm' import { IconMenu } from '@/Icons' import { formatDate, hasPermission } from '@/utils' import ModalImport from './ModalImport' export default function Document(props) { const { data: docs, links } = props.docs const [search, setSearch] = useState({ q: '', status: 0 }) const preValue = usePrevious(search) const importModal = useModalState(false) const confirmModal = useModalState(false) const handleDelete = (doc) => { confirmModal.setData(doc) confirmModal.toggle() } const onDelete = () => { const doc = confirmModal.data if (doc != null) { router.delete(route('docs.destroy', doc), { onSuccess: () => toast.success('The Data has been deleted'), }) } } const handleFilter = (filter) => { setSearch({ ...search, ...filter, }) } const sort = (key) => { setSearch({ ...search, sortBy: key, sortRule: search.sortRule == 'asc' ? 'desc' : 'asc', }) } useEffect(() => { if (preValue) { router.get(route(route().current()), search, { replace: true, preserveState: true, }) } }, [search]) const canCreate = hasPermission('create-document', props.auth.user) const canUpdate = hasPermission('update-document', props.auth.user) const canDelete = hasPermission('delete-document', props.auth.user) const canImport = hasPermission('import-document', props.auth.user) const canExport = hasPermission('export-document', props.auth.user) return (
{canCreate && ( Tambah )} {canImport && (
Import
)}
handleFilter({ q: e.target.value }) } placeholder="Search" />
  • handleFilter({ status: 0, }) } > Semua
  • handleFilter({ status: 1, }) } > Jatuh Tempo
  • handleFilter({ status: 2, }) } > Mendekati Jatuh Tempo
{canExport && ( )}
{docs?.map((doc) => ( ))}
Perusahaan sort('type_id')} > Jenis sort('category_id')} > Ketegori No Dokumen Nama Dokumen sort('publish_date')} > Tanggal Terbit sort('due_date')} > Tanggal Berakhir Catatan
{doc.company.short} ( {doc.company.region.name}) {doc.variety.name} {doc.category.name} {doc.no_doc} {doc.name} {doc.publish_date !== null ? formatDate( doc.publish_date ) : ''} {doc.due_date !== null ? formatDate(doc.due_date) : ''} {doc.due_status}
  • Detail
  • {canUpdate && (
  • Edit
  • )} {canDelete && (
  • handleDelete( doc ) } className="bg-error " >
    Delete
  • )}
) }