cache reset

master
Tudor Stanciu 2023-05-07 00:51:04 +03:00
parent 2ab22b2113
commit 31ba727f9b
7 changed files with 51 additions and 14 deletions

View File

@ -98,7 +98,8 @@
}, },
"Cache": { "Cache": {
"Title": "Cache settings", "Title": "Cache settings",
"Reset": "Reset" "Reset": "Reset",
"ResetInfo": "Cache reset"
}, },
"Appearance": { "Appearance": {
"Title": "Appearance settings" "Title": "Appearance settings"

View File

@ -89,7 +89,8 @@
}, },
"Cache": { "Cache": {
"Title": "Setări cache", "Title": "Setări cache",
"Reset": "Resetați" "Reset": "Resetați",
"ResetInfo": "Cache resetat"
}, },
"Appearance": { "Appearance": {
"Title": "Appearance settings" "Title": "Appearance settings"

View File

@ -1,4 +1,5 @@
import React from "react"; import React from "react";
import PropTypes from "prop-types";
import { Paper, Button } from "@material-ui/core"; import { Paper, Button } from "@material-ui/core";
import { makeStyles } from "@material-ui/core/styles"; import { makeStyles } from "@material-ui/core/styles";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
@ -13,7 +14,7 @@ const useStyles = makeStyles(theme => ({
} }
})); }));
const ResetCacheComponent = () => { const CacheSettingsComponent = ({ onResetCache }) => {
const classes = useStyles(); const classes = useStyles();
const { t } = useTranslation(); const { t } = useTranslation();
const { sysAdmin } = usePermissions(); const { sysAdmin } = usePermissions();
@ -22,7 +23,12 @@ const ResetCacheComponent = () => {
<Paper variant="outlined"> <Paper variant="outlined">
<PaperTitle text={t("Settings.Cache.Title")} /> <PaperTitle text={t("Settings.Cache.Title")} />
<div className={classes.content}> <div className={classes.content}>
<Button variant="outlined" color="secondary" disabled={!sysAdmin}> <Button
variant="outlined"
color="secondary"
disabled={!sysAdmin}
onClick={onResetCache}
>
{t("Settings.Cache.Reset")} {t("Settings.Cache.Reset")}
</Button> </Button>
</div> </div>
@ -30,4 +36,8 @@ const ResetCacheComponent = () => {
); );
}; };
export default ResetCacheComponent; CacheSettingsComponent.propTypes = {
onResetCache: PropTypes.func.isRequired
};
export default CacheSettingsComponent;

View File

@ -0,0 +1,22 @@
import React, { useCallback } from "react";
import CacheSettingsComponent from "./CacheSettingsComponent";
import { useTranslation } from "react-i18next";
import { routes, post } from "utils/api";
import { info } from "utils/toast";
const CacheSettingsContainer = () => {
const { t } = useTranslation();
const handleResetCache = useCallback(async () => {
await post(
routes.resetCache,
{},
{
onCompleted: () => info(t("Settings.Cache.ResetInfo"))
}
);
}, [t]);
return <CacheSettingsComponent onResetCache={handleResetCache} />;
};
export default CacheSettingsContainer;

View File

@ -1,8 +1,8 @@
import React from "react"; import React from "react";
import ResetCacheComponent from "./ResetCacheComponent"; import CacheSettingsContainer from "./CacheSettingsContainer";
const SystemContainer = () => { const SystemContainer = () => {
return <ResetCacheComponent />; return <CacheSettingsContainer />;
}; };
export default SystemContainer; export default SystemContainer;

View File

@ -1,10 +1,4 @@
import { toast } from "react-toastify"; import { info, success, warning, error, dark } from "utils/toast";
const info = message => toast.info(message);
const success = message => toast.success(message);
const warning = message => toast.warning(message);
const error = message => toast.error(message);
const dark = message => toast.dark(message);
export const useToast = () => { export const useToast = () => {
return { info, success, warning, error, dark }; return { info, success, warning, error, dark };

9
src/utils/toast.js Normal file
View File

@ -0,0 +1,9 @@
import { toast } from "react-toastify";
const info = message => toast.info(message);
const success = message => toast.success(message);
const warning = message => toast.warning(message);
const error = message => toast.error(message);
const dark = message => toast.dark(message);
export { info, success, warning, error, dark };