import React, { useEffect, useState } from 'react'; import { router } from '@inertiajs/react'; import { usePrevious } from 'react-use'; import { Head } from '@inertiajs/react'; import { Button, Dropdown } from 'flowbite-react'; import { HiEye, 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 { formatDate, formatIDR, hasPermission } from '@/utils'; export default function Sale(props) { const { query: { links, data }, auth } = props const [search, setSearch] = useState('') const preValue = usePrevious(search) const confirmModal = useModalState() const toggleFormModal = () => { router.get(route('sale.create')) } const viewDetail = (sale) => { router.get(route('sale.show', sale)) } const handleDeleteClick = (sale) => { confirmModal.setData(sale) confirmModal.toggle() } const onDelete = () => { if(confirmModal.data !== null) { router.delete(route('sale.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-sale') const canUpdate = hasPermission(auth, 'update-sale') const canDelete = hasPermission(auth, 'delete-sale') return (
{canCreate && ( )}
setSearch(e.target.value)} value={search} />
{data.map(sale => ( ))}
Kode Tanggal Pelanggan Total
{sale.code} {formatDate(sale.date)} {sale.customer?.name} {formatIDR(sale.total)} {canUpdate && ( viewDetail(sale)}>
Detail
)} {canDelete && ( handleDeleteClick(sale)}>
Hapus
)}
); }