import React, { useEffect, useState } from 'react' import { usePrevious } from 'react-use' import { Head, Link, router } 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 User(props) { const { data: { links, data }, auth, } = props const [search, setSearch] = useState('') const preValue = usePrevious(search) const confirmModal = useModalState() const handleDeleteClick = (user) => { confirmModal.setData(user) confirmModal.toggle() } const onDelete = () => { if (confirmModal.data !== null) { router.delete(route('user.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-user') const canUpdate = hasPermission(auth, 'update-user') const canDelete = hasPermission(auth, 'delete-user') return (
{canCreate && ( )}
setSearch(e.target.value)} value={search} />
{data.map((user) => ( ))}
Photo Nama Email Username Rule Whatsapp
photo profile {user.name} {user.email} {user.username} {user.role === null ? 'System' : user.role?.name} +62{user.phone_wa} {canUpdate && ( router.visit( route( 'user.edit', user ) ) } >
Ubah
)} {canDelete && ( handleDeleteClick( user ) } >
Hapus
)}
) }