1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-10-18 11:14:57 +02:00
unleash.unleash/frontend/src/component/admin/maintenance/MaintenanceToggle.tsx
Thomas Heartman b2c58102dd
chore(unl-204): remove uses of toast text and confetti (#8941)
As of PR #8935, we no longer support both text and title, and confetti
has been removed.

This PR:
- removes `confetti` from the toast interface
- merges `text` and `title` into `text` and updates its uses across the
codebase.
- readjusts the text where necessary.
2024-12-10 13:38:04 +00:00

92 lines
3.0 KiB
TypeScript

import {
Box,
FormControlLabel,
styled,
Switch,
Typography,
} from '@mui/material';
import { useMaintenance } from 'hooks/api/getters/useMaintenance/useMaintenance';
import { useMaintenanceApi } from 'hooks/api/actions/useMaintenanceApi/useMaintenanceApi';
import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
import useToast from 'hooks/useToast';
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
const StyledContainer = styled('div')(({ theme }) => ({
display: 'flex',
flexDirection: 'column',
padding: theme.spacing(3),
border: `1px solid ${theme.palette.divider}`,
borderRadius: theme.shape.borderRadiusLarge,
}));
const CardTitleRow = styled(Box)({
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
});
const CardDescription = styled(Box)(({ theme }) => ({
color: theme.palette.text.secondary,
fontSize: theme.fontSizes.smallBody,
marginTop: theme.spacing(2),
}));
const SwitchLabel = styled(Typography)(({ theme }) => ({
fontSize: theme.fontSizes.smallBody,
}));
export const MaintenanceToggle = () => {
const { enabled, refetchMaintenance } = useMaintenance();
const { refetch: refetchUiConfig } = useUiConfig();
const { toggleMaintenance } = useMaintenanceApi();
const { trackEvent } = usePlausibleTracker();
const { setToastData } = useToast();
const updateEnabled = async () => {
setToastData({
type: 'success',
text: `Maintenance mode has been successfully ${
enabled ? 'disabled' : 'enabled'
}`,
});
trackEvent('maintenance', {
props: {
eventType: `maintenance ${enabled ? 'de' : ''}activated`,
},
});
await toggleMaintenance({ enabled: !enabled });
refetchMaintenance();
refetchUiConfig();
};
return (
<StyledContainer>
<CardTitleRow>
<b>Maintenance Mode</b>
<FormControlLabel
sx={{ margin: 0 }}
control={
<Switch
onChange={updateEnabled}
value={enabled}
name='enabled'
checked={enabled}
/>
}
label={
<SwitchLabel>
{enabled ? 'Enabled' : 'Disabled'}
</SwitchLabel>
}
/>
</CardTitleRow>
<CardDescription>
Maintenance Mode is useful when you want to freeze your system
so nobody can do any changes during this time. When enabled it
will show a banner at the top of the applications and only an
admin can enable it or disable it.
</CardDescription>
</StyledContainer>
);
};