import React from 'react'; import AppBar from '@mui/material/AppBar'; import Box from '@mui/material/Box'; import Button from '@mui/material/Button'; import Dialog from '@mui/material/Dialog'; import DialogActions from '@mui/material/DialogActions'; import DialogContent from '@mui/material/DialogContent'; import DialogContentText from '@mui/material/DialogContentText'; import DialogTitle from '@mui/material/DialogTitle'; import Toolbar from '@mui/material/Toolbar'; import Typography from '@mui/material/Typography'; import List from '@mui/material/List'; import Grid from '@mui/material/Grid'; import ListItem from '@mui/material/ListItem'; import ClearIcon from '@mui/icons-material/Clear'; import CheckIcon from '@mui/icons-material/Check'; import IconButton from '@mui/material/IconButton'; import './AppAdmin.css'; // https://encartes.aliens-lyon.fr/api/map/machin function FormatModeName(mode) { if (mode === "add_place_name") return "Ajouter un nom de salle" else if (mode === "del_place_name") return "Retirer un nom de salle" else if (mode === "add_room_user_name") return "Retirer un nom" else if (mode === "del_room_user_name") return "Retirer un nom" else return "Heeeeuh ya un prob la, 42" } function RenderRequestList() { const [data, setData] = React.useState(""); React.useEffect(() => { // Fetch the list of modifications to be accepted/denied // fetch("./propositions.json") // .then((response) => response.json()) // .then((data) => setData(data)); // }, []); fetch('https://encartes.aliens-lyon.fr/api/map/get_all_editions') .then((response) => response.json()) .then((data) => setData(data)); }, []); const removeElement = (index) => { // Removes an element from the displayed modifications (does not remove it from the DB) const newData = data.filter((_, i) => i !== index); setData(newData); }; const acceptRequest = (item) => { console.log("Proposition " + item.id + " acceptée."); fetch("https://encartes.aliens-lyon.fr/api/map/" + item.mode + "/" + item.placeId + "/" + item.editorValue); // Send the request to the DataBase fetch("https://encartes.aliens-lyon.fr/api/map/remove_edition/" + item.id); // Remove the edition } const denyRequest = (item) => { console.log("Proposition " + item.id + " rejetée.") fetch("https://encartes.aliens-lyon.fr/api/map/remove_edition/" + item.id); // Remove the edition, don't accept it } return Requêtes {data.length>0 &&
Index Modification ID de salle Noms de salle Valeur à ajouter/supprimer {data.map((item, index) => { return ( { removeElement(index); // Remove the display of this item acceptRequest(item); // Send the signal that it has been accepted }} aria-label="check" > { removeElement(index); // Remove the display of this item denyRequest(item); // Send the signal that it has been denied }} edge="end" aria-label="clear" > } key={item.id} > {index+1} {FormatModeName(item.mode)} {item.placeId} {item.placeNames.join(", ")} {item.editorValue} ); })}
} {data.length===0 &&
Aucune requête !
}
} function TopBar() { const [openAboutModal, setOpenAboutModal] = React.useState(false); const handleOpenAboutModal = () => { setOpenAboutModal(true); }; const handleCloseAboutModal = () => { setOpenAboutModal(false); }; return <> ENcarteS Admin {"À propos de ENcarteS Admin"} ENcarteS Admin permet d'accepter ou de refuser les requêtes de modification d'ENcarteS ! } export default function AppAdmin() { return <>
}