2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt odlux
4 * =================================================================================================
5 * Copyright (C) 2021 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
19 import React from 'react';
20 import { Button, FormControlLabel, Switch, Typography } from '@mui/material';
21 import makeStyles from '@mui/styles/makeStyles';
22 import { SettingsComponentProps } from '../../models/settings';
23 import { connect, Connect, IDispatcher } from '../../flux/connect';
24 import { IApplicationStoreState } from '../../store/applicationStore';
25 import { getGeneralSettingsAction, SetGeneralSettingsAction, updateGeneralSettingsAction } from '../../actions/settingsAction';
26 import { sendMessage, SettingsMessage } from '../../services/broadcastService';
29 type props = Connect<typeof mapProps, typeof mapDispatch> & SettingsComponentProps;
31 const mapProps = (state: IApplicationStoreState) => ({
32 settings: state.framework.applicationState.settings,
33 user: state.framework.authenticationState.user?.user
37 const mapDispatch = (dispatcher: IDispatcher) => ({
39 updateSettings :(activateNotifications: boolean) => dispatcher.dispatch(updateGeneralSettingsAction(activateNotifications)),
40 getSettings: () =>dispatcher.dispatch(getGeneralSettingsAction()),
43 const styles = makeStyles({
57 const General : React.FunctionComponent<props> = (props) =>{
59 const classes = styles();
61 const [areWebsocketsEnabled, setWebsocketsEnabled] = React.useState(props.settings.general.areNotificationsEnabled || false);
68 if(props.settings.general.areNotificationsEnabled!==null)
69 setWebsocketsEnabled(props.settings.general.areNotificationsEnabled)
72 const onWebsocketsChange = (event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>, newValue: boolean) =>{
73 setWebsocketsEnabled(newValue);
76 const onSave = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) =>{
79 const message: SettingsMessage = {key: 'general', enableNotifications: areWebsocketsEnabled, user: props.user!};
80 sendMessage(message, "odlux_settings");
81 props.updateSettings(areWebsocketsEnabled);
85 const onCancel = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) =>{
93 <Typography className={classes.sectionMargin} variant="body1" style={{ fontWeight: "bold" }} gutterBottom>
96 <FormControlLabel style={{ padding:5}}
98 control={<Switch color="secondary" aria-label="enable-notifications-button" aria-checked={areWebsocketsEnabled} checked={areWebsocketsEnabled} onChange={onWebsocketsChange} />}
99 label="Enable Notifications"
102 <div className={classes.buttonPosition}>
103 <Button aria-label="cancel-button" className={classes.elementMargin} variant="contained" color="primary" onClick={onCancel}>Cancel</Button>
104 <Button aria-label="save-button" className={classes.elementMargin} variant="contained" color="secondary" onClick={onSave}>Save</Button>
109 export const GeneralUserSettings = connect(mapProps, mapDispatch)(General);
110 export default GeneralUserSettings;