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 { HiFilter, 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' import ThSort from './ThSortComponent' import ModalFilter from './ModalFilter' import ModalDelete from './ModalDelete' export default function Index(props) { const { query: { links, data }, auth, location, profile, stats, _search, _sortBy, _sortOrder, } = props const [search, setSearch] = useState({ q: _search, sortBy: _sortBy, sortOrder: _sortOrder, }) const preValue = usePrevious(search) const confirmModal = useModalState() const bulkDeleteModal = useModalState() const filterModal = useModalState() const handleDeleteClick = (voucher) => { confirmModal.setData(voucher) confirmModal.toggle() } const onDelete = () => { if (confirmModal.data !== null) { router.delete(route('voucher.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', }) } useEffect(() => { if (preValue) { router.get(route(route().current(), [location, profile]), search, { replace: true, preserveState: true, }) } }, [search]) const canCreate = hasPermission(auth, 'create-voucher') const canUpdate = hasPermission(auth, 'update-voucher') const canDelete = hasPermission(auth, 'delete-voucher') const canBulkDelete = hasPermission(auth, 'bulk-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 && (
)}
{canBulkDelete && (
)}
Kode Profile Kuota Comment Created At Terjual {data.map((voucher, index) => ( ))}
No Lokasi
{index + 1} { voucher.location_profile .location.name } {voucher.username} { voucher.location_profile .name } { voucher.location_profile .quota } {voucher.comment} { voucher.created_at_formated }
{voucher.status.text}
{canUpdate && (
Ubah
)} {canDelete && ( handleDeleteClick( voucher ) } >
Hapus
)}
) }