[79a0317] | 1 | import React, { useEffect, useState } from "react";
|
---|
| 2 | import styles from "./ListReports.module.css";
|
---|
| 3 | import HttpService from "../../scripts/net/HttpService.js";
|
---|
| 4 | import config from "../../scripts/net/netconfig.js";
|
---|
| 5 | import {Link} from "react-router-dom";
|
---|
| 6 |
|
---|
| 7 | const ListReports = () => {
|
---|
| 8 | const [isModalOpen, setIsModalOpen] = useState(false);
|
---|
| 9 | const [reports, setReports] = useState([]);
|
---|
| 10 |
|
---|
| 11 | useEffect(() => {
|
---|
| 12 | const loadReports = async () => {
|
---|
| 13 | try {
|
---|
| 14 | const httpService = new HttpService(true);
|
---|
| 15 | httpService.setAuthenticated();
|
---|
| 16 |
|
---|
| 17 | const respReports = await httpService.get(config.admin.load_reports);
|
---|
| 18 |
|
---|
| 19 | const sortedReports = respReports.sort(
|
---|
| 20 | (a, b) => new Date(b.date) - new Date(a.date)
|
---|
| 21 | );
|
---|
| 22 |
|
---|
| 23 | setReports(sortedReports);
|
---|
| 24 | } catch (error) {
|
---|
| 25 | console.error("Error loading reports:", error);
|
---|
| 26 | }
|
---|
| 27 | };
|
---|
| 28 | loadReports();
|
---|
| 29 | }, []);
|
---|
| 30 |
|
---|
| 31 | const handleButtonClick = () => {
|
---|
| 32 | setIsModalOpen(true);
|
---|
| 33 | };
|
---|
| 34 |
|
---|
| 35 | const handleCloseModal = () => {
|
---|
| 36 | setIsModalOpen(false);
|
---|
| 37 | };
|
---|
| 38 |
|
---|
| 39 | return (
|
---|
| 40 | <div>
|
---|
| 41 | <button className={styles.openButton} onClick={handleButtonClick}>
|
---|
| 42 | View Reports
|
---|
| 43 | </button>
|
---|
| 44 |
|
---|
| 45 | {isModalOpen && (
|
---|
| 46 | <div className={styles.modalBackground} onClick={handleCloseModal}>
|
---|
| 47 | <div className={styles.modalContent} onClick={(e) => e.stopPropagation()}>
|
---|
| 48 | <div className={styles.heading}>Reports</div>
|
---|
| 49 | <div className={styles.cardContainer}>
|
---|
| 50 | {reports.length > 0 ? (
|
---|
| 51 | reports.map((report, index) => (
|
---|
| 52 | <div key={index} className={styles.card}>
|
---|
| 53 | <div className={styles.cardTitle}>{report.subject}</div>
|
---|
| 54 | <div className={styles.cardContent}>{report.content}</div>
|
---|
| 55 | <small className={styles.cardFooter}>
|
---|
| 56 | User: {report.username} <br/>
|
---|
| 57 | Map: <Link to={`/myMaps/View/${report.mapName}`}>{report.mapName}</Link>
|
---|
| 58 | <br/>
|
---|
| 59 | Submitted: {new Date(report.date).toLocaleDateString()}
|
---|
| 60 | </small>
|
---|
| 61 | </div>
|
---|
| 62 | ))
|
---|
| 63 | ) : (
|
---|
| 64 | <p className={styles.noReports}>No reports available</p>
|
---|
| 65 | )}
|
---|
| 66 | </div>
|
---|
| 67 | <button className={styles.closeButton} onClick={handleCloseModal}>
|
---|
| 68 | Close
|
---|
| 69 | </button>
|
---|
| 70 | </div>
|
---|
| 71 | </div>
|
---|
| 72 | )}
|
---|
| 73 | </div>
|
---|
| 74 | );
|
---|
| 75 | };
|
---|
| 76 |
|
---|
| 77 | export default ListReports;
|
---|