2025-05-18 11:53:40 +02:00
|
|
|
"use client";
|
|
|
|
|
import Sidebar from "@/components/Sidebar";
|
|
|
|
|
import { Plus } from "lucide-react";
|
|
|
|
|
import AddSite from "@/components/dialogues/AddSite";
|
2025-05-18 12:06:21 +02:00
|
|
|
import Sites from "@/components/cards/Sites";
|
2025-05-18 12:17:18 +02:00
|
|
|
import axios from "axios";
|
2025-05-18 12:50:56 +02:00
|
|
|
import { useEffect, useState, useCallback } from "react";
|
2025-05-18 12:40:11 +02:00
|
|
|
import Pagination from "@/components/Pagination";
|
2025-05-18 11:53:40 +02:00
|
|
|
|
|
|
|
|
interface SitesPageProps {
|
|
|
|
|
username: string;
|
|
|
|
|
name: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default function SitesPage({ username, name }: SitesPageProps) {
|
2025-05-18 12:17:18 +02:00
|
|
|
const [sites, setSites] = useState([]);
|
2025-05-18 12:32:50 +02:00
|
|
|
const [currentPage, setCurrentPage] = useState(1);
|
|
|
|
|
const [itemPerPage, setItemPerPage] = useState(5);
|
|
|
|
|
const [total, setTotal] = useState(0);
|
2025-05-18 12:45:31 +02:00
|
|
|
const [search, setSearch] = useState("");
|
2025-05-18 12:32:50 +02:00
|
|
|
|
|
|
|
|
const handlePageChange = (page: number) => {
|
|
|
|
|
setCurrentPage(page);
|
|
|
|
|
};
|
2025-05-18 12:50:56 +02:00
|
|
|
|
|
|
|
|
const loadSites = useCallback(() => {
|
2025-05-18 12:32:50 +02:00
|
|
|
axios.get('/api/sites/get_all', {
|
|
|
|
|
params: {
|
|
|
|
|
currentPage,
|
|
|
|
|
itemPerPage,
|
2025-05-18 12:45:31 +02:00
|
|
|
search,
|
2025-05-18 12:32:50 +02:00
|
|
|
},
|
|
|
|
|
}).then((response) => {
|
2025-05-18 12:17:18 +02:00
|
|
|
setSites(response.data.sites);
|
2025-05-18 12:32:50 +02:00
|
|
|
setTotal(response.data.total);
|
2025-05-18 12:17:18 +02:00
|
|
|
});
|
2025-05-18 12:45:31 +02:00
|
|
|
}, [currentPage, itemPerPage, search]);
|
2025-05-18 12:50:56 +02:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
loadSites();
|
|
|
|
|
}, [loadSites]);
|
|
|
|
|
|
2025-05-18 11:53:40 +02:00
|
|
|
return (
|
|
|
|
|
<Sidebar
|
|
|
|
|
username={username}
|
|
|
|
|
fullName={name}
|
|
|
|
|
breadcrumbPath={['/', 'Dashboard', 'Ressources', 'Sites']}
|
|
|
|
|
>
|
|
|
|
|
<main>
|
|
|
|
|
<div className="flex gap-4 items-center">
|
|
|
|
|
<div className="flex-1">
|
|
|
|
|
<h1 className="text-2xl font-bold">Sites</h1>
|
|
|
|
|
<p className="text-sm opacity-70">Manage your sites. Sites are real-world locations where you can monitor your assets & add networks.</p>
|
|
|
|
|
</div>
|
|
|
|
|
<button className="btn btn-primary" onClick={() => document.getElementById('add_site')?.showModal()}>
|
|
|
|
|
<Plus className="w-5 h-5" />
|
|
|
|
|
Add Site
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
2025-05-18 12:50:56 +02:00
|
|
|
<AddSite onSiteAdded={loadSites} />
|
2025-05-18 12:20:33 +02:00
|
|
|
|
|
|
|
|
<div className="flex gap-2 items-center pt-4">
|
2025-05-18 12:45:31 +02:00
|
|
|
<input type="text" placeholder="Search..." className="input input-bordered w-full" onChange={(e) => setSearch(e.target.value)} />
|
2025-05-18 12:32:50 +02:00
|
|
|
<select defaultValue="Pick a font" className="select w-24" onChange={(e) => setItemPerPage(Number(e.target.value))}>
|
2025-05-18 12:20:33 +02:00
|
|
|
<option disabled={true}>Layout</option>
|
2025-05-18 12:32:50 +02:00
|
|
|
<option value={5}>List</option>
|
|
|
|
|
<option value={10}>Grid</option>
|
2025-05-18 12:20:33 +02:00
|
|
|
</select>
|
|
|
|
|
</div>
|
|
|
|
|
|
2025-05-18 12:32:50 +02:00
|
|
|
<div className={itemPerPage === 5 ? "flex flex-col gap-4 pt-4" : "grid grid-cols-1 md:grid-cols-2 gap-4 pt-4"}>
|
2025-05-18 12:17:18 +02:00
|
|
|
{sites.map((site: any) => (
|
|
|
|
|
<Sites key={site.id} id={site.id} name={site.name} description={site.description} networks={site.networks} />
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
2025-05-18 12:32:50 +02:00
|
|
|
|
2025-05-18 12:40:11 +02:00
|
|
|
<Pagination
|
|
|
|
|
currentPage={currentPage}
|
|
|
|
|
totalItems={total}
|
|
|
|
|
itemsPerPage={itemPerPage}
|
|
|
|
|
onPageChange={handlePageChange}
|
|
|
|
|
/>
|
2025-05-18 11:53:40 +02:00
|
|
|
</main>
|
|
|
|
|
</Sidebar>
|
|
|
|
|
)
|
|
|
|
|
}
|