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 } 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' export default function Index(props) { const { query: { links, data }, auth, } = props const [location, setLocation] = useState(null) const [search, setSearch] = useState('') const preValue = usePrevious(`${search}${location}`) const confirmModal = useModalState() const handleDeleteClick = (profile) => { confirmModal.setData(profile) confirmModal.toggle() } const onDelete = () => { if (confirmModal.data !== null) { router.delete( route('location-profile.destroy', confirmModal.data.id) ) } } const params = { q: search, location_id: location } useEffect(() => { if (preValue) { router.get( route(route().current()), { q: search, location_id: location }, { replace: true, preserveState: true, } ) } }, [search, location]) const canCreate = hasPermission(auth, 'create-location-profile') const canUpdate = hasPermission(auth, 'update-location-profile') const canDelete = hasPermission(auth, 'delete-location-profile') return (
{canCreate && (
)}
setLocation(id)} placeholder={'filter lokasi'} />
setSearch(e.target.value) } value={search} />
{data.map((profile, index) => ( ))}
Nama Lokasi Kuota Masa Aktif
{profile.name} {profile.location.name} {profile.quota} {profile.diplay_expired} {canUpdate && (
Ubah
)} {canDelete && ( handleDeleteClick( profile ) } >
Hapus
)}
) }