Files
Checkmate/client/src/Pages/Settings/SettingsStats.jsx
T

85 lines
2.2 KiB
React
Raw Normal View History

2025-05-09 13:28:44 -07:00
import Box from "@mui/material/Box";
import Typography from "@mui/material/Typography";
import Button from "@mui/material/Button";
import Stack from "@mui/material/Stack";
2025-09-27 14:54:55 -07:00
import ConfigBox from "@/Components/v1/ConfigBox/index.jsx";
import TextInput from "@/Components/v1/Inputs/TextInput/index.jsx";
import Dialog from "@/Components/v1/Dialog/index.jsx";
2025-05-09 13:28:44 -07:00
// Utils
import { useTheme } from "@emotion/react";
import { PropTypes } from "prop-types";
import { useTranslation } from "react-i18next";
import { useState } from "react";
const SettingsStats = ({ isAdmin, HEADING_SX, handleChange, settingsData, errors }) => {
2025-05-09 13:28:44 -07:00
const theme = useTheme();
const { t } = useTranslation();
const [isOpen, setIsOpen] = useState(false);
if (!isAdmin) {
return null;
}
2025-05-09 13:28:44 -07:00
return (
<ConfigBox>
<Box>
<Typography
component="h1"
2025-05-18 20:35:55 -04:00
variant="h2"
2025-05-09 13:28:44 -07:00
sx={HEADING_SX}
>
2025-06-24 14:30:14 +08:00
{t("settingsPage.statsSettings.title")}
2025-05-09 13:28:44 -07:00
</Typography>
<Typography sx={{ mt: theme.spacing(2) }}>
2025-06-24 14:30:14 +08:00
{t("settingsPage.statsSettings.description")}
2025-05-09 13:28:44 -07:00
</Typography>
</Box>
<Stack gap={theme.spacing(20)}>
<Box>
2025-06-24 14:30:14 +08:00
<Typography>
{t("settingsPage.statsSettings.clearAllStatsDescription")}
</Typography>
2025-05-09 13:28:44 -07:00
<Button
variant="contained"
color="error"
onClick={() => setIsOpen(true)}
sx={{ mt: theme.spacing(4) }}
>
2025-06-24 14:30:14 +08:00
{t("settingsPage.statsSettings.clearAllStatsButton")}
2025-05-09 13:28:44 -07:00
</Button>
</Box>
</Stack>
<Dialog
open={isOpen}
theme={theme}
2025-06-24 14:30:14 +08:00
title={t("settingsPage.statsSettings.clearAllStatsDialogTitle")}
description={t("settingsPage.statsSettings.clearAllStatsDialogDescription")}
2025-05-09 13:28:44 -07:00
onCancel={() => setIsOpen(false)}
2025-06-24 14:30:14 +08:00
confirmationButtonLabel={t(
"settingsPage.statsSettings.clearAllStatsDialogConfirm"
)}
2025-05-09 13:28:44 -07:00
onConfirm={() => {
const syntheticEvent = {
target: {
name: "deleteStats",
},
};
handleChange(syntheticEvent);
setIsOpen(false);
}}
isLoading={false}
/>
</ConfigBox>
);
};
SettingsStats.propTypes = {
isAdmin: PropTypes.bool,
2025-05-09 13:28:44 -07:00
HEADING_SX: PropTypes.object,
handleChange: PropTypes.func,
2025-05-09 14:54:28 -07:00
settingsData: PropTypes.object,
2025-05-09 13:28:44 -07:00
errors: PropTypes.object,
};
export default SettingsStats;