Skip to content

Commit

Permalink
✨ Get Country currently blocked
Browse files Browse the repository at this point in the history
  • Loading branch information
AxelFTS committed Jan 30, 2024
1 parent ad6dd88 commit 10fce15
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 35 deletions.
82 changes: 51 additions & 31 deletions src/components/dashboard/BlockManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,27 @@ const BlockManager = () => {
}
};

React.useEffect(() => {
const fetchBlockedCountries = async () => {
try {
const countries = await getBlockedCountries();
setBlockedCountries(countries);
} catch (error) {
console.error('Error fetching blocked countries:', error);
}
};
// React.useEffect(() => {
// const fetchBlockedCountries = async () => {
// try {
// const countries = await getBlockedCountries();
// setBlockedCountries(countries);
// } catch (error) {
// console.error('Error fetching blocked countries:', error);
// }
// };

fetchBlockedCountries();
}, [getBlockedCountries]);
// fetchBlockedCountries();
// }, [getBlockedCountries]);


const refreshBlockedCountries = async () => {
try {
const countries = await getBlockedCountries();
setBlockedCountries(countries);
} catch (error) {
console.error('Error fetching blocked countries:', error);
}
};

const handleBlockCountry = async (e) => {
e.preventDefault();
Expand All @@ -74,11 +81,17 @@ const BlockManager = () => {
setCountry('');
setAlertText(t('blockManager.blockCountrySuccess'));
setOpen(true);
refreshBlockedCountries();
} catch (error) {
console.error(error);
}
};

React.useEffect(() => {
refreshBlockedCountries();
}, [refreshBlockedCountries]);


return (
<Grid container direction="column">
<Grid item>
Expand Down Expand Up @@ -115,25 +128,32 @@ const BlockManager = () => {
</Grid>
</Grid>
<Grid item xs>
<Typography variant="h6" component="h2" gutterBottom mt={2}>
{t('blockManager.currentlyBlockedCountries')}
</Typography>
<List>
{blockedCountries.map((country, index) => (
<ListItem key={index} sx={{
my: 1,
px: 2,
bgcolor: isNightMode
? (index % 2 === 0 ? nightModeBgColor1 : nightModeBgColor2)
: (index % 2 === 0 ? 'action.hover' : 'background.default'),
borderRadius: 1
}}>
<ListItemText primary={country} />
{/* Vous pouvez ajouter ici des actions comme un bouton pour débloquer le pays */}
</ListItem>
))}
</List>
</Grid>
<Typography variant="h6" component="h2" gutterBottom mt={2}>
{t('blockManager.currentlyBlockedCountries')}
</Typography>
<List>
{blockedCountries.length > 0 ? (
blockedCountries.map((country, index) => (
<ListItem key={index} sx={{
my: 1,
px: 2,
bgcolor: isNightMode
? (index % 2 === 0 ? nightModeBgColor1 : nightModeBgColor2)
: (index % 2 === 0 ? 'action.hover' : 'background.default'),
borderRadius: 1
}}>
<ListItemText primary={country} />
{/* Ajouter des actions pour chaque pays si nécessaire */}
</ListItem>
))
) : (
<Typography sx={{ px: 2 }}>{t('blockManager.noBlockedCountries')}</Typography>
)}
</List>
</Grid>

{/* Séparateur */}
<Divider sx={{ my: 4 }} />
<Grid item xs sx={{ marginBottom: 0.4 }}>
<Typography variant="h6" mb={2}>{t('blockManager.blockAnIP')}</Typography>
<Grid container spacing={2} direction="column" alignItems="stretch" component="form" onSubmit={handleSubmit}>
Expand Down
3 changes: 2 additions & 1 deletion src/locales/ch/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@
"blockACountry": "阻止一个国家",
"blockCountry": "阻止国家",
"countryCode": "国家代码",
"currentlyBlockedCountries": "目前被封鎖的國家"
"currentlyBlockedCountries": "目前被封鎖的國家",
"noBlockedCountries": "尚未有國家被封鎖"
},
"listConnections": {
"title": "传入连接",
Expand Down
3 changes: 2 additions & 1 deletion src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
"blockACountry": "Block a Country",
"blockCountry": "Block Country",
"countryCode": "Country Code",
"currentlyBlockedCountries": "Countries currently blocked"
"currentlyBlockedCountries": "Countries currently blocked",
"noBlockedCountries": "No country has yet been blocked."
},
"listConnections": {
"title": "Incoming Connections",
Expand Down
3 changes: 2 additions & 1 deletion src/locales/es/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@
"blockACountry": "Bloquear un País",
"blockCountry": "Bloquear País",
"countryCode": "Código del País",
"currentlyBlockedCountries": "Países actualmente bloqueados"
"currentlyBlockedCountries": "Países actualmente bloqueados",
"noBlockedCountries": "Ningún país ha sido bloqueado todavía."
},
"listConnections": {
"title": "Conexiones entrantes",
Expand Down
3 changes: 2 additions & 1 deletion src/locales/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
"blockACountry": "Bloquer un pays",
"blockCountry": "Bloquer le pays",
"countryCode": "Code du pays",
"currentlyBlockedCountries": "Pays actuellement bloqués"
"currentlyBlockedCountries": "Pays actuellement bloqués",
"noBlockedCountries": "Aucun pays n'a pour l'instant été bloqué."
},
"listConnections": {
"title": "Connexions entrantes",
Expand Down

0 comments on commit 10fce15

Please sign in to comment.