芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/reginaeigbe.com/folder/admin/tmp/resources/js/Admin/Pages/Pages/Index.jsx
import AdminLayouts from "@/Admin/Layouts/AdminLayouts"; import { Head, Link } from "@inertiajs/react"; import { fileTray, newspaperOutline, search } from "ionicons/icons"; import { IonIcon } from "@ionic/react"; import { trashOutline, createOutline, eyeOutline } from "ionicons/icons"; 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({ pages, 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.pages.index", { search: search ?? setSearchQuery, sort: sort, }), {}, { preserveState: true } ); }; // mark all const markAll = () => { if (isMarkAll) { setMarkItems([]); setIsMarkAll(false); } else { const items = pages.data.map((page) => page.id); setMarkItems(items); setIsMarkAll(true); } }; // handle mark unmark const handleMark = (pageId) => { const existsMark = markItems.some((item) => item === pageId); if (existsMark) { const removeItem = markItems.filter((item) => item !== pageId); setMarkItems(removeItem); } else { const addedItem = [...markItems, pageId]; setMarkItems(addedItem); } }; // handle bulk action const handleBulkAction = () => { let confirmMessage = ""; let action = ""; if (selectedOption === "Delete") { confirmMessage = "You want to delete selected pages?"; action = "admin.pages.bulk.delete"; } setIsMarkAll([]); showAlert("Are you sure?", confirmMessage, selectedOption + "!", () => { router.delete(route(action, { ids: markItems.join(",") })); }); }; return ( <>
All pages
pages
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("pages.create") && (
+
{" "} Create New )}
markAll() } style={{ width: "1%" }} >
getResults( searchQuery ) } column="title" > Title
getResults( searchQuery ) } column="created_at" > Created At
Action
{pages.data.map( (page, index) => (
handleMark( page.id ) } >
item === page.id ) && "active" }`} />
{page.title}
{moment( page.created_at ).format("ll")}
{hasPermission( "pages.edit" ) && (
)} {page.slug !== "/" && hasPermission( "pages.show" ) && (
)} {page.type !== "custom" && hasPermission( "pages.delete" ) && (
)}
) )}
{!pages.data.length && (
No pages found!
)}
{/* .yoo-card */} {pages.total > 1 && (
{pages.links.map((link, index) => (
))}
)}
> ); }