diff --git a/src/components/dashboard/BlockManager.tsx b/src/components/dashboard/BlockManager.tsx index c8a90de..2321475 100644 --- a/src/components/dashboard/BlockManager.tsx +++ b/src/components/dashboard/BlockManager.tsx @@ -1,31 +1,51 @@ -import React from 'react'; -import { Typography, TextField, Button, Paper, Grid, Snackbar, Alert, List, ListItem, ListItemText, ListItemSecondaryAction, IconButton, Box } from '@mui/material'; -import DeleteIcon from '@mui/icons-material/Delete'; -import { Divider } from '@mui/material'; +import React from "react"; +import { + Typography, + TextField, + Button, + Paper, + Grid, + Snackbar, + Alert, + List, + ListItem, + ListItemText, + ListItemSecondaryAction, + IconButton, + Box, +} from "@mui/material"; +import DeleteIcon from "@mui/icons-material/Delete"; +import { Divider } from "@mui/material"; import HelpModal from "@components/HelpModal"; -import useBlackListRPC from '@hooks/backend/honeypotService/useBlackListRPC'; -import { useTranslation } from 'react-i18next'; -import { NightModeContext } from '@contexts/NightModeContext'; +import useBlackListRPC from "@hooks/backend/honeypotService/useBlackListRPC"; +import { useTranslation } from "react-i18next"; +import { NightModeContext } from "@contexts/NightModeContext"; import { useContext } from "react"; const BlockManager = () => { - const { blacklist, putBlackList, putWhiteList, blockCountry, getBlockedCountries } = useBlackListRPC(); - const [ip, setIp] = React.useState(''); - const [country, setCountry] = React.useState(''); + const { + blacklist, + putBlackList, + putWhiteList, + blockCountry, + getBlockedCountries, + } = useBlackListRPC(); + const [ip, setIp] = React.useState(""); + const [country, setCountry] = React.useState(""); const [open, setOpen] = React.useState(false); - const [alertText, setAlertText] = React.useState(''); + const [alertText, setAlertText] = React.useState(""); const [blockedCountries, setBlockedCountries] = React.useState([]); const { t } = useTranslation(); const { isNightMode } = useContext(NightModeContext); - const nightModeBgColor1 = 'color1ForNightMode'; - const nightModeBgColor2 = 'color2ForNightMode'; - const textFieldStyle = isNightMode - ? { - InputLabelProps: { style: { color: 'white' } }, - inputProps: { style: { color: 'white' } }, - sx: { borderBottom: '1px solid white' } - } - : {}; + const nightModeBgColor1 = "color1ForNightMode"; + const nightModeBgColor2 = "color2ForNightMode"; + const textFieldStyle = isNightMode + ? { + InputLabelProps: { style: { color: "white" } }, + inputProps: { style: { color: "white" } }, + sx: { borderBottom: "1px solid white" }, + } + : {}; const handleClose = React.useCallback(() => { setOpen(false); }, []); @@ -34,43 +54,30 @@ const BlockManager = () => { e.preventDefault(); try { await putBlackList(ip); - setIp(''); - setAlertText(t('blockManager.blockSuccess')); + setIp(""); + setAlertText(t("blockManager.blockSuccess")); setOpen(true); } catch (error) { - console.error(error); + console.error(error); } }; const handleUnblock = async (ip) => { try { await putWhiteList(ip); - setAlertText(t('blockManager.unblockSuccess')); + setAlertText(t("blockManager.unblockSuccess")); setOpen(true); } catch (error) { - console.error(error); + console.error(error); } }; - // React.useEffect(() => { - // const fetchBlockedCountries = async () => { - // try { - // const countries = await getBlockedCountries(); - // setBlockedCountries(countries); - // } catch (error) { - // console.error('Error fetching blocked countries:', error); - // } - // }; - - // fetchBlockedCountries(); - // }, [getBlockedCountries]); - const refreshBlockedCountries = async () => { try { const countries = await getBlockedCountries(); setBlockedCountries(countries); } catch (error) { - console.error('Error fetching blocked countries:', error); + console.error("Error fetching blocked countries:", error); } }; @@ -78,8 +85,8 @@ const BlockManager = () => { e.preventDefault(); try { await blockCountry(country); - setCountry(''); - setAlertText(t('blockManager.blockCountrySuccess')); + setCountry(""); + setAlertText(t("blockManager.blockCountrySuccess")); setOpen(true); refreshBlockedCountries(); } catch (error) { @@ -90,136 +97,195 @@ const BlockManager = () => { React.useEffect(() => { refreshBlockedCountries(); }, [refreshBlockedCountries]); - return ( - - - {t('blockManager.ipManagement')} - + - - - - - - {t('blockManager.blockACountry')} - - - setCountry(e.target.value)} - {...textFieldStyle} - /> + + {t("blockManager.ipManagement")} + - + - - {t('blockManager.currentlyBlockedCountries')} - - - {blockedCountries.length > 0 ? ( - blockedCountries.map((country, index) => ( - - - {/* Ajouter des actions pour chaque pays si nécessaire */} - - )) - ) : ( - {t('blockManager.noBlockedCountries')} - )} - - - - {/* Séparateur */} - - - {t('blockManager.blockAnIP')} - - - setIp(e.target.value)} - {...textFieldStyle} - /> - - - + *': { + marginBottom: '16px', // Add a margin to each child + }, + }} + > + + + {t("blockManager.blockACountry")} + + + + setCountry(e.target.value)} + {...textFieldStyle} + /> + + + + + - + - {t('blockManager.currentlyBlocked')} + {t("blockManager.currentlyBlockedCountries")} - - - - {alertText} - - - - - - - {blacklist && blacklist.map((blacklistedIP, index) => ( - - - - handleUnblock(blacklistedIP)}> - - - - {index !== blacklist.length - 1 && } - - ))} + {blockedCountries.length > 0 ? ( + blockedCountries.map((country, index) => ( + + + {/* Ajouter des actions pour chaque pays si nécessaire */} + + )) + ) : ( + + {t("blockManager.noBlockedCountries")} + + )} - + + + + {t("blockManager.blockAnIP")} + + + + setIp(e.target.value)} + {...textFieldStyle} + /> + + + + + + + {t("blockManager.currentlyBlocked")} + + + + + {alertText} + + + + + + + + {blacklist && + blacklist.map((blacklistedIP, index) => ( + + + + handleUnblock(blacklistedIP)} + > + + + + {index !== blacklist.length - 1 && } + + ))} + + + + ); diff --git a/src/components/dashboard/ContainerManager.tsx b/src/components/dashboard/ContainerManager.tsx index 7a85e29..17f6f20 100644 --- a/src/components/dashboard/ContainerManager.tsx +++ b/src/components/dashboard/ContainerManager.tsx @@ -120,16 +120,16 @@ const ContainerManager: React.FC = () => { - *': { - marginBottom: '16px', // Add a margin to each child - }, - }} - > + *': { + marginBottom: '16px', // Add a margin to each child + }, + }} + > {containers && containers.map((container, index) => (