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' 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('customer.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 (
Basic
{formatIDR(stats.basic_count)} Orang
Silver
{formatIDR(stats.silver_count)} Orang
Gold
{formatIDR(stats.gold_count)} Orang
Platinum
{formatIDR(stats.platinum_count)} Orang
{canCreate && ( )}
setLevel(id) } placeholder={'filter level'} />
setLocation(id) } placeholder={'filter lokasi'} />
Deposit Poin {data.map((customer) => ( ))}
Nama Level Sisa Saldo Hutang Limit Hutang Referral Code Lokasi Whatsapp 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} {canUpdate && (
Ubah
)} {canDelete && ( handleDeleteClick( customer ) } >
Hapus
)}
) }