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'
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 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)
return (
sort('type_id')}>Jenis | sort('category_id')}>Ketegori | No Dokumen | Nama Dokumen | sort('due_date')}>Tanggal Berakhir | Status | |
---|---|---|---|---|---|---|
{doc.type.name} | {doc.category.name} | {doc.no_doc} | {doc.name} | {formatDate(doc.due_date)} | Status |
|