import React, { useEffect, useState } from "react"; import styles from "./ListReports.module.css"; import HttpService from "../../scripts/net/HttpService.js"; import config from "../../scripts/net/netconfig.js"; import {Link} from "react-router-dom"; const ListReports = () => { const [isModalOpen, setIsModalOpen] = useState(false); const [reports, setReports] = useState([]); useEffect(() => { const loadReports = async () => { try { const httpService = new HttpService(true); httpService.setAuthenticated(); const respReports = await httpService.get(config.admin.load_reports); const sortedReports = respReports.sort( (a, b) => new Date(b.date) - new Date(a.date) ); setReports(sortedReports); } catch (error) { console.error("Error loading reports:", error); } }; loadReports(); }, []); const handleButtonClick = () => { setIsModalOpen(true); }; const handleCloseModal = () => { setIsModalOpen(false); }; return (
{isModalOpen && (
e.stopPropagation()}>
Reports
{reports.length > 0 ? ( reports.map((report, index) => (
{report.subject}
{report.content}
User: {report.username}
Map: {report.mapName}
Submitted: {new Date(report.date).toLocaleDateString()}
)) ) : (

No reports available

)}
)}
); }; export default ListReports;