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 AuthenticatedLayout from '@/Layouts/AuthenticatedLayout' import Pagination from '@/Components/Pagination' import ModalConfirm from '@/Components/ModalConfirm' import SearchInput from '@/Components/SearchInput' import { hasPermission } from '@/utils' export default function Customer(props) { const { query: { links, data }, auth, } = props const [search, setSearch] = useState('') const preValue = usePrevious(search) 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 params = { q: search } useEffect(() => { if (preValue) { router.get( route(route().current()), { q: search }, { replace: true, preserveState: true, } ) } }, [search]) const canCreate = hasPermission(auth, 'create-customer') const canUpdate = hasPermission(auth, 'update-customer') const canDelete = hasPermission(auth, 'delete-customer') return (
{canCreate && ( )}
setSearch(e.target.value)} value={search} />
{data.map((customer) => ( ))}
Nama Level Deposit Coin Referal Code
{customer.name} {customer.level.name} {customer.display_deposit} {customer.display_coin} {customer.referral_code} {canUpdate && (
Ubah
)} {canDelete && ( handleDeleteClick( customer ) } >
Hapus
)}
) }