[79a0317] | 1 | import React, { useState } from "react";
|
---|
| 2 | import styles from "./Report.module.css";
|
---|
| 3 | import report_icon from "../../assets/report_icon.png";
|
---|
| 4 | import {useAppContext} from "../AppContext/AppContext.jsx";
|
---|
| 5 | import HttpService from "../../scripts/net/HttpService.js";
|
---|
| 6 | import config from "../../scripts/net/netconfig.js";
|
---|
| 7 |
|
---|
| 8 | const Report = ({mapName}) => {
|
---|
| 9 | const [isModalOpen, setIsModalOpen] = useState(false);
|
---|
| 10 | const [topic, setTopic] = useState("");
|
---|
| 11 | const [description, setDescription] = useState("");
|
---|
| 12 | const {username} = useAppContext();
|
---|
| 13 |
|
---|
| 14 | const handleSubmit = async () => {
|
---|
| 15 | if (!topic.trim() || !description.trim()) {
|
---|
| 16 | alert("Please fill in both fields.");
|
---|
| 17 | return;
|
---|
| 18 | }
|
---|
| 19 |
|
---|
| 20 | let httpService = new HttpService(true);
|
---|
| 21 | let payload = {
|
---|
| 22 | username: username,
|
---|
| 23 | mapName: mapName,
|
---|
| 24 | subject: topic,
|
---|
| 25 | content: description,
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | let response = await httpService.post(config.view_maps.add_report, payload);
|
---|
| 29 |
|
---|
| 30 | setTopic("")
|
---|
| 31 | setDescription("")
|
---|
| 32 | setIsModalOpen(false)
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 |
|
---|
| 36 | const handleOutsideClick = (e) => {
|
---|
| 37 | if (e.target.classList.contains(styles.modalBackground)) {
|
---|
| 38 | setIsModalOpen(false);
|
---|
| 39 | }
|
---|
| 40 | };
|
---|
| 41 |
|
---|
| 42 | return (
|
---|
| 43 | <div>
|
---|
| 44 | <button className={styles.reportButton} onClick={() => setIsModalOpen(true)}>
|
---|
| 45 | <img src={report_icon} alt="Report Icon" className={styles.reportIcon} />
|
---|
| 46 | </button>
|
---|
| 47 |
|
---|
| 48 | {isModalOpen && (
|
---|
| 49 | <div className={styles.modalBackground} onClick={handleOutsideClick}>
|
---|
| 50 | <div className={styles.modalContent}>
|
---|
| 51 | <h2>Report Issue</h2>
|
---|
| 52 | <input
|
---|
| 53 | type="text"
|
---|
| 54 | placeholder="Topic"
|
---|
| 55 | value={topic}
|
---|
| 56 | onChange={(e) => setTopic(e.target.value)}
|
---|
| 57 | className={styles.inputField}
|
---|
| 58 | />
|
---|
| 59 | <textarea
|
---|
| 60 | placeholder="Description"
|
---|
| 61 | value={description}
|
---|
| 62 | onChange={(e) => setDescription(e.target.value)}
|
---|
| 63 | className={styles.textareaField}
|
---|
| 64 | ></textarea>
|
---|
| 65 | <div className={styles.buttonGroup}>
|
---|
| 66 | <button onClick={handleSubmit} className={styles.submitButton}>
|
---|
| 67 | Submit
|
---|
| 68 | </button>
|
---|
| 69 | <button onClick={() => setIsModalOpen(false)} className={styles.cancelButton}>
|
---|
| 70 | Cancel
|
---|
| 71 | </button>
|
---|
| 72 | </div>
|
---|
| 73 | </div>
|
---|
| 74 | </div>
|
---|
| 75 | )}
|
---|
| 76 | </div>
|
---|
| 77 | );
|
---|
| 78 | };
|
---|
| 79 |
|
---|
| 80 | export default Report;
|
---|