import React, { useEffect, useState } from 'react'
import { Link, router } from '@inertiajs/react'
import { usePrevious } from 'react-use'
import { Head } from '@inertiajs/react'
import { Button, Dropdown } from 'flowbite-react'
import { HiFilter, HiOutlineFilter, HiPencil, HiTrash } from 'react-icons/hi'
import { useModalState } from '@/hooks'
import { hasPermission, formatIDR } from '@/utils'
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout'
import Pagination from '@/Components/Pagination'
import ModalConfirm from '@/Components/ModalConfirm'
import SearchInput from '@/Components/SearchInput'
import ThSort from '@/Components/ThSortComponent'
import ModalFilter from './ModalFilter'
import ModalDelete from './ModalDelete'
export default function Index(props) {
const {
query: { links, data },
auth,
location,
profile,
stats,
_search,
_sortBy,
_sortOrder,
} = props
const [search, setSearch] = useState({
q: _search,
sortBy: _sortBy,
sortOrder: _sortOrder,
})
const preValue = usePrevious(search)
const confirmModal = useModalState()
const bulkDeleteModal = useModalState()
const filterModal = useModalState()
const handleDeleteClick = (voucher) => {
confirmModal.setData(voucher)
confirmModal.toggle()
}
const onDelete = () => {
if (confirmModal.data !== null) {
router.delete(route('voucher.destroy', confirmModal.data.id))
}
}
const handleSearchChange = (e) => {
setSearch({
...search,
q: e.target.value,
})
}
const sort = (key, sort = null) => {
if (sort !== null) {
setSearch({
...search,
sortBy: key,
sortRule: sort,
})
return
}
setSearch({
...search,
sortBy: key,
sortRule: search.sortRule == 'asc' ? 'desc' : 'asc',
})
}
useEffect(() => {
if (preValue) {
router.get(route(route().current(), [location, profile]), search, {
replace: true,
preserveState: true,
})
}
}, [search])
const canCreate = hasPermission(auth, 'create-voucher')
const canUpdate = hasPermission(auth, 'update-voucher')
const canDelete = hasPermission(auth, 'delete-voucher')
const canBulkDelete = hasPermission(auth, 'bulk-delete-voucher')
return (
No | Lokasi | |||||||
---|---|---|---|---|---|---|---|---|
{index + 1} | { voucher.location_profile .location.name } | {voucher.username} | { voucher.location_profile .name } | { voucher.location_profile .quota } | {voucher.comment} | { voucher.created_at_formated } |
{voucher.status.text}
|
Ubah
Hapus
|