// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import React from 'react'; import PropTypes from 'prop-types'; import {savePreference} from 'actions/user_actions.jsx'; import {localizeMessage} from 'utils/utils.jsx'; import {FormattedMessage} from 'react-intl'; import SettingItemMin from 'components/setting_item_min.jsx'; import SettingItemMax from 'components/setting_item_max.jsx'; import {Preferences} from 'utils/constants.jsx'; export default class EmailNotificationSetting extends React.Component { static propTypes = { activeSection: PropTypes.string.isRequired, updateSection: PropTypes.func.isRequired, enableEmail: PropTypes.bool.isRequired, emailInterval: PropTypes.number.isRequired, onSubmit: PropTypes.func.isRequired, onCancel: PropTypes.func.isRequired, serverError: PropTypes.string }; constructor(props) { super(props); this.state = { enableEmail: props.enableEmail, emailInterval: props.emailInterval }; } componentWillReceiveProps(nextProps) { if (nextProps.enableEmail !== this.props.enableEmail || nextProps.emailInterval !== this.props.emailInterval) { this.setState({ enableEmail: nextProps.enableEmail, emailInterval: nextProps.emailInterval }); } } handleChange = (enableEmail, emailInterval) => { this.setState({ enableEmail, emailInterval }); } handleSubmit = () => { // until the rest of the notification settings are moved to preferences, we have to do this separately savePreference(Preferences.CATEGORY_NOTIFICATIONS, Preferences.EMAIL_INTERVAL, this.state.emailInterval.toString()); const {enableEmail} = this.state; this.props.onSubmit({enableEmail}); } handleExpand = () => { this.props.updateSection('email'); } handleCancel = (e) => { this.setState({ enableEmail: this.props.enableEmail, emailInterval: this.props.emailInterval }); this.props.onCancel(e); } render() { if (global.window.mm_config.SendEmailNotifications !== 'true' && this.props.activeSection === 'email') { const inputs = []; inputs.push(