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 { HiPencil, HiTrash } from 'react-icons/hi'
import { useModalState } from '@/hooks'
import { formatIDR, hasPermission } from '@/utils'
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout'
import Pagination from '@/Components/Pagination'
import ModalConfirm from '@/Components/ModalConfirm'
import SearchInput from '@/Components/SearchInput'
import LocationSelectionInput from '../Location/SelectionInput'
import LevelSelectionInput from '../CustomerLevel/SelectionInput'
import ThSort from '@/Components/ThSortComponent'
import { HiEye } from 'react-icons/hi2'
export default function Customer(props) {
const {
query: { links, data },
stats,
auth,
_search,
_sortBy,
_sortOrder,
} = props
const [location, setLocation] = useState(null)
const [level, setLevel] = useState(null)
const [search, setSearch] = useState({
q: _search,
sortBy: _sortBy,
sortOrder: _sortOrder,
})
const preValue = usePrevious(`${search}${location}${level}`)
const confirmModal = useModalState()
const handleDeleteClick = (customer) => {
confirmModal.setData(customer)
confirmModal.toggle()
}
const onDelete = () => {
if (confirmModal.data !== null) {
router.delete(route('mitra.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',
})
}
const params = { q: search, location_id: location, level_id: level }
useEffect(() => {
if (preValue) {
router.get(
route(route().current()),
{ ...search, location_id: location, level_id: level },
{
replace: true,
preserveState: true,
}
)
}
}, [search, location, level])
const canCreate = hasPermission(auth, 'create-customer')
const canUpdate = hasPermission(auth, 'update-customer')
const canDelete = hasPermission(auth, 'delete-customer')
return (
Nama | Level | Sisa Saldo Hutang | Limit Hutang | Referral Code | Lokasi | Status | ||||
---|---|---|---|---|---|---|---|---|---|---|
{customer.name} | {customer.level.name} | {customer.display_deposit} | {customer.display_poin} | {formatIDR( customer.paylater_remain )} | {formatIDR( customer.paylater_limit )} | {customer.referral_code} |
{customer.location_favorites.map(
(location) => (
{location.name}
)
)}
|
{customer.phone !== null && ( +62{customer.phone} )} | {customer.status_text} |
Lihat
Hapus
|