diff --git a/src/pages/Dashboard.js b/src/pages/Dashboard.js index b3813f198d39391390924f6b9340b09b6070b38d..f0da60f9b558592600ecc4a0356d1efe92018d25 100644 --- a/src/pages/Dashboard.js +++ b/src/pages/Dashboard.js @@ -170,9 +170,9 @@ const Dashboard = () => { return ( <Grid container spacing={1}> <Title title={translate('dashboard.welcome')} /> - <AccountsPanel data={data} /> - <ProductsAlertsPanel data={data} /> - <StatisticsPanel /> + {localStorage.getItem("dash.showAccounts") !== "false" && <AccountsPanel data={data} />} + {localStorage.getItem("dash.showAlerts") !== "false" && <ProductsAlertsPanel data={data} />} + {localStorage.getItem("dash.showGraphs") !== "false" && <StatisticsPanel />} </Grid > ); }; diff --git a/src/resources/Profile.js b/src/resources/Profile.js index 25394ba31280c0175d9c0ee29f8f1fa85736c15c..4e6884bc62dc9d8689de79f066f1309067a96f3d 100644 --- a/src/resources/Profile.js +++ b/src/resources/Profile.js @@ -1,4 +1,4 @@ -import { Button as MuiButton, Dialog, DialogActions as MuiDialogActions, DialogContent as MuiDialogContent, DialogTitle, Grid, IconButton, Typography, withStyles } from '@material-ui/core'; +import { Button as MuiButton, Dialog, DialogActions as MuiDialogActions, DialogContent as MuiDialogContent, DialogTitle, FormControlLabel, FormGroup, Grid, IconButton, Switch, Typography, withStyles } from '@material-ui/core'; import { makeStyles, styled } from "@material-ui/core/styles"; import { fade } from '@material-ui/core/styles/colorManipulator'; import AddIcon from '@material-ui/icons/Add'; @@ -11,7 +11,7 @@ import SecurityIcon from '@material-ui/icons/Security'; import VpnKeyIcon from '@material-ui/icons/VpnKey'; import { spacing } from "@material-ui/system"; import axios from 'axios'; -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import { ArrayField, Button, ChipField, Datagrid, Edit, Labeled, ReferenceArrayField, SaveButton, SimpleForm, SingleFieldList, TextField, TextInput, Toolbar, useAuthProvider, useDeleteWithConfirmController, useNotify, useRecordContext, useRedirect, useRefresh, useTranslate, useUpdateLoading } from 'react-admin'; import DateField from '../components/DateField'; const StyledButton = styled(Button)(spacing); @@ -262,6 +262,40 @@ const ProfileEditToolbar = (props) => { ); }; +const DashboardSettings = (props) => { + const [showAccounts, setShowAccounts] = useState(localStorage.getItem("dash.showAccounts") !== "false"); + const [showAlerts, setShowAlerts] = useState(localStorage.getItem("dash.showAlerts") !== "false"); + const [showGraphs, setShowGraphs] = useState(localStorage.getItem("dash.showGraphs") !== "false"); + + useEffect(() => localStorage.setItem("dash.showAccounts", showAccounts), [showAccounts]); + useEffect(() => localStorage.setItem("dash.showAlerts", showAlerts), [showAlerts]); + useEffect(() => localStorage.setItem("dash.showGraphs", showGraphs), [showGraphs]); + + return ( + <StyledGrid container mt={2} mb={2} alignItems="center"> + <Grid item xs={12}> + <Typography variant="h5" component="h2">Accueil</Typography> + </Grid> + <Grid item xs={12}> + <FormGroup column> + <FormControlLabel + control={<Switch color="primary" checked={showAccounts} onChange={() => setShowAccounts(!showAccounts)} name="showAccounts" />} + label="Afficher les comptes" + /> + <FormControlLabel + control={<Switch color="primary" checked={showAlerts} onChange={() => setShowAlerts(!showAlerts)} name="showAccounts" />} + label="Afficher les alertes de stock" + /> + <FormControlLabel + control={<Switch color="primary" checked={showGraphs} onChange={() => setShowGraphs(!showGraphs)} name="showAccounts" />} + label="Afficher les graphiques" + /> + </FormGroup> + </Grid> + </StyledGrid> + ); +} + const ProfileEdit = ({ staticContext, ...props }) => { const translate = useTranslate(); const notify = useNotify(); @@ -302,6 +336,7 @@ const ProfileEdit = ({ staticContext, ...props }) => { <><Typography variant="h5" component="h2">{translate('resources.profile.2fa.title')}</Typography></> <TwoFactorAuthField source="two_factor" /> <TokensField /> + <DashboardSettings /> </SimpleForm> </Edit> );