import React, { useEffect, useState } from 'react'
import { Head, Link, router } from '@inertiajs/react'
import { usePrevious } from 'react-use'
import { HiEye } from 'react-icons/hi2'
import { formatIDR, hasPermission } from '@/utils'
import { DEPOSIT_STATUSES } from '@/constant'
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout'
import Pagination from '@/Components/Pagination'
import SearchInput from '@/Components/SearchInput'
import ThSort from '@/Components/ThSortComponent'
export default function Index(props) {
const {
deposits: { links, data },
auth,
_search,
_sortBy,
_sortRule,
} = props
const [search, setSearch] = useState({
q: _search,
sortBy: _sortBy,
sortRule: _sortRule,
})
const [status, setStatus] = useState('')
const preValue = usePrevious(`${search}${status}`)
const handleChangeSearch = (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',
})
}
const params = { ...search, status: status }
useEffect(() => {
if (preValue) {
router.get(
route(route().current()),
{ ...search, status: status },
{
replace: true,
preserveState: true,
}
)
}
}, [search, status])
const canUpdate = hasPermission(auth, 'update-paylater-repayment')
return (
{deposit.description} | {deposit.customer.name} | {deposit.amount} | {deposit.format_created_at} | {deposit.status.text} | {deposit.editor?.name} |
{canUpdate && (
Lihat
)}
|