import React, { useEffect, useState } from 'react'
import { usePrevious } from 'react-use'
import { Head, Link } from '@inertiajs/inertia-react'
import { Inertia } from '@inertiajs/inertia'
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'
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) {
Inertia.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) {
Inertia.get(
route(route().current()),
search,
{
replace: true,
preserveState: true,
}
)
}
}, [search])
return (
sort('type_doc_id')}>Jenis | Nama PIC | sort('end_date')}>Tanggal Berakhir | sort('status')}>Status | |
---|---|---|---|---|
{doc.type.name} | {doc.pic_name} | {doc.end_date} |
|