import React, { Component, Fragment } from 'react'; import PropTypes from 'prop-types'; import { withNamespaces, Trans } from 'react-i18next'; import Upstream from './Upstream'; import Dhcp from './Dhcp'; import Encryption from './Encryption'; import Checkbox from '../ui/Checkbox'; import Loading from '../ui/Loading'; import PageTitle from '../ui/PageTitle'; import Card from '../ui/Card'; import './Settings.css'; class Settings extends Component { settings = { filtering: { enabled: false, title: 'block_domain_use_filters_and_hosts', subtitle: 'filters_block_toggle_hint', }, safebrowsing: { enabled: false, title: 'use_adguard_browsing_sec', subtitle: 'use_adguard_browsing_sec_hint', }, parental: { enabled: false, title: 'use_adguard_parental', subtitle: 'use_adguard_parental_hint', }, safesearch: { enabled: false, title: 'enforce_safe_search', subtitle: 'enforce_save_search_hint', }, }; componentDidMount() { this.props.initSettings(this.settings); this.props.getDhcpStatus(); this.props.getDhcpInterfaces(); this.props.getTlsStatus(); } handleUpstreamChange = (value) => { this.props.handleUpstreamChange({ upstreamDns: value }); }; handleUpstreamSubmit = () => { this.props.setUpstream(this.props.dashboard.upstreamDns); }; handleUpstreamTest = () => { if (this.props.dashboard.upstreamDns.length > 0) { this.props.testUpstream(this.props.dashboard.upstreamDns); } else { this.props.addErrorToast({ error: this.props.t('no_servers_specified') }); } }; renderSettings = (settings) => { if (Object.keys(settings).length > 0) { return Object.keys(settings).map((key) => { const setting = settings[key]; const { enabled } = setting; return ( this.props.toggleSetting(key, enabled)} />); }); } return (
no_settings
); } render() { const { settings, t } = this.props; const { upstreamDns } = this.props.dashboard; return ( {settings.processing && } {!settings.processing &&
{this.renderSettings(settings.settingsList)}
}
); } } Settings.propTypes = { initSettings: PropTypes.func, settings: PropTypes.object, settingsList: PropTypes.object, toggleSetting: PropTypes.func, handleUpstreamChange: PropTypes.func, setUpstream: PropTypes.func, upstream: PropTypes.string, t: PropTypes.func, }; export default withNamespaces()(Settings);