source: imaps-frontend/src/components/Report/Report.jsx@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 2.8 KB
Line 
1import React, { useState } from "react";
2import styles from "./Report.module.css";
3import report_icon from "../../assets/report_icon.png";
4import {useAppContext} from "../AppContext/AppContext.jsx";
5import HttpService from "../../scripts/net/HttpService.js";
6import config from "../../scripts/net/netconfig.js";
7
8const 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
80export default Report;
Note: See TracBrowser for help on using the repository browser.