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 ModalFilter from './ModalFilter'
import ModalShare from './ModalShare'
import DocStatusItem from './DocStatusItem'
import { IconFilter, IconMenu } from '@/Icons'
import { formatDate } from '@/utils'
export default function Document(props) {
const { types, departments } = props
const { data: docs, links } = props.docs
const [search, setSearch] = useState({q: ''})
const preValue = usePrevious(search)
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 filterModal = useModalState(false)
const handleFilter = (filter) => {
setSearch({
...search,
...filter,
})
}
const shareModal = useModalState(false)
const handleShare = (doc) => {
shareModal.setData(doc)
shareModal.toggle()
}
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])
return (
sort('type_doc_id')}>Jenis | Nama Dokumen | Nama PIC | sort('end_date')}>Tanggal Berakhir | sort('status')}>Status | |
---|---|---|---|---|---|
{doc.type.name} | {doc.name} | {doc.pic_name} | {formatDate(doc.end_date)} |
|