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 { Button, FormControlLabel, makeStyles, Switch, Typography } from '@material-ui/core';
20 import { SettingsComponentProps } from '../../models/settings';
21 import * as React from 'react';
22 import connect, { Connect, IDispatcher } from '../../flux/connect';
23 import { IApplicationStoreState } from '../../store/applicationStore';
24 import { getGeneralSettingsAction, SetGeneralSettingsAction, updateGeneralSettingsAction } from '../../actions/settingsAction';
25 import { sendMessage, SettingsMessage } from '../../services/broadcastService';
28 type props = Connect<typeof mapProps, typeof mapDispatch> & SettingsComponentProps;
30 const mapProps = (state: IApplicationStoreState) => ({
31 settings: state.framework.applicationState.settings,
32 user: state.framework.authenticationState.user?.user
36 const mapDispatch = (dispatcher: IDispatcher) => ({
38 updateSettings :(activateNotifications: boolean) => dispatcher.dispatch(updateGeneralSettingsAction(activateNotifications)),
39 getSettings: () =>dispatcher.dispatch(getGeneralSettingsAction()),
42 const styles = makeStyles({
56 const General : React.FunctionComponent<props> = (props) =>{
58 const classes = styles();
60 const [areWebsocketsEnabled, setWebsocketsEnabled] = React.useState(props.settings.general.areNotificationsEnabled || false);
67 if(props.settings.general.areNotificationsEnabled!==null)
68 setWebsocketsEnabled(props.settings.general.areNotificationsEnabled)
71 const onWebsocketsChange = (event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>, newValue: boolean) =>{
72 setWebsocketsEnabled(newValue);
75 const onSave = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) =>{
78 const message: SettingsMessage = {key: 'general', enableNotifications: areWebsocketsEnabled, user: props.user!};
79 sendMessage(message, "odlux_settings");
80 props.updateSettings(areWebsocketsEnabled);
84 const onCancel = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) =>{
92 <Typography className={classes.sectionMargin} variant="body1" style={{ fontWeight: "bold" }} gutterBottom>
95 <FormControlLabel style={{ padding:5}}
97 control={<Switch color="secondary" checked={areWebsocketsEnabled} onChange={onWebsocketsChange} />}
98 label="Enable Notifications"
101 <div className={classes.buttonPosition}>
102 <Button className={classes.elementMargin} variant="contained" color="primary" onClick={onCancel}>Cancel</Button>
103 <Button className={classes.elementMargin} variant="contained" color="secondary" onClick={onSave}>Save</Button>
108 export const GeneralUserSettings = connect(mapProps, mapDispatch)(General);
109 export default GeneralUserSettings;