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