芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/reginaeigbe.com/folder/admin/tmp/resources/js/Admin/Pages/Users/Index.jsx
import AdminLayouts from "@/Admin/Layouts/AdminLayouts"; import { Head, Link } from "@inertiajs/react"; import { createOutline, mailOpenOutline, peopleOutline, search, } from "ionicons/icons"; import { IonIcon } from "@ionic/react"; import moment from "moment"; import { useState } from "react"; import { router } from "@inertiajs/react"; import ThSortable from "@/Admin/Components/Table/ThSortable"; import DropDownButton from "@/Admin/Components/Button/DropDownButton"; import { showAlert } from "@/Admin/Utils/SweetAlert.js"; import DeleteButton from "@/Admin/Components/Button/DeleteButton"; import hasPermission from "@/Admin/Utils/hasPermission"; export default function Index({ users, sort }) { const [searchQuery, setSearchQuery] = useState(""); const [selectedOption, setSelectedOption] = useState("Bulk Action"); const [isMarkAll, setIsMarkAll] = useState(false); const [markItems, setMarkItems] = useState([]); // handle search sort const getResults = (search) => { router.get( route("admin.users.index", { search: search ?? setSearchQuery, sort: sort, }), {}, { preserveState: true } ); }; // mark all const markAll = () => { if (isMarkAll) { setMarkItems([]); setIsMarkAll(false); } else { const items = users.data.map((user) => user.id); setMarkItems(items); setIsMarkAll(true); } }; // handle mark unmark const handleMark = (userId) => { const existsMark = markItems.some((item) => item === userId); if (existsMark) { const removeItem = markItems.filter((item) => item !== userId); setMarkItems(removeItem); } else { const addedItem = [...markItems, userId]; setMarkItems(addedItem); } }; // handle bulk action const handleBulkAction = () => { let confirmMessage = ""; let action = ""; if (selectedOption === "Delete") { confirmMessage = "You want to delete selected users?"; action = "admin.users.bulk.delete"; } setIsMarkAll([]); showAlert("Are you sure?", confirmMessage, selectedOption + "!", () => { router.delete(route(action, { ids: markItems.join(",") })); }); }; return ( <>
All users
users
setSelectedOption( "Delete" ) } className={`dropdown-item ${ selectedOption === "Delete" ? "active" : "" }`} href="#" > Delete
handleBulkAction() } className="btn btn-success btn-sm" > Apply
{ setSearchQuery( e.target.value ); getResults( e.target.value ); }} />
{hasPermission("users.create") && (
+
{" "} Create New )}
markAll() } style={{ width: "1%" }} >
getResults( searchQuery ) } column="name" > Name
getResults( searchQuery ) } column="email" > Email
getResults( searchQuery ) } column="role" > Role
getResults( searchQuery ) } column="created_at" > Created At
Action
{users.data.map( (user, index) => (
handleMark( user.id ) } >
item === user.id ) && "active" }`} />
{user.name}
{user.email}
{ user.role_title }
{moment( user.created_at ).format("ll")}
{hasPermission( "users.edit" ) && (
)} {hasPermission( "users.delete" ) && (
)}
) )}
{!users.data.length && (
No users found!
)}
{/* .yoo-card */} {users.total > 1 && (
{users.links.map((link, index) => (
))}
)}
> ); }