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 { hasPermission, formatIDR } from '@/utils' import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout' import Pagination from '@/Components/Pagination' import ModalConfirm from '@/Components/ModalConfirm' import SearchInput from '@/Components/SearchInput' export default function Index(props) { const { query: { links, data }, auth, location, profile, stats, } = props const [search, setSearch] = useState('') const preValue = usePrevious(`${search}`) const confirmModal = useModalState() const handleDeleteClick = (voucher) => { confirmModal.setData(voucher) confirmModal.toggle() } const onDelete = () => { if (confirmModal.data !== null) { router.delete(route('voucher.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-voucher') const canUpdate = hasPermission(auth, 'update-voucher') const canDelete = hasPermission(auth, 'delete-voucher') return (
Total Voucher
{formatIDR(stats.count_voucher_total)} PCS
Total Voucher
Rp. {formatIDR(stats.sum_voucher_total)}
Total Voucher sudah terjual
{formatIDR(stats.count_voucher_sold)} PCS
Jumlah Voucher sudah terjual
Rp. {formatIDR(stats.sum_voucher_sold)}
Total Voucher belum terjual
{formatIDR(stats.count_voucher_unsold)} PCS
Jumlah Voucher belum terjual
Rp. {formatIDR(stats.sum_voucher_unsold)}
{canCreate && (
)}
setSearch(e.target.value)} value={search} />
{data.map((voucher, index) => ( ))}
No Lokasi Kode Profile Kuota Comment Created At Terjual
{index + 1} { voucher.profile.location .name } {voucher.username} {voucher.profile.name} {voucher.profile.quota} {voucher.comment} { voucher.created_at_formated }
{voucher.status.text}
{canUpdate && (
Ubah
)} {canDelete && ( handleDeleteClick( voucher ) } >
Hapus
)}
) }