// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import React from 'react';
import {savePreference} from 'utils/async_client.jsx';
import PreferenceStore from 'stores/preference_store.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: React.PropTypes.string.isRequired,
updateSection: React.PropTypes.func.isRequired,
enableEmail: React.PropTypes.bool.isRequired,
onChange: React.PropTypes.func.isRequired,
onSubmit: React.PropTypes.func.isRequired,
serverError: React.PropTypes.string
};
constructor(props) {
super(props);
this.submit = this.submit.bind(this);
this.expand = this.expand.bind(this);
this.collapse = this.collapse.bind(this);
this.state = {
emailInterval: PreferenceStore.getInt(Preferences.CATEGORY_NOTIFICATIONS, Preferences.EMAIL_INTERVAL, Preferences.INTERVAL_IMMEDIATE)
};
}
handleChange(enableEmail, emailInterval) {
this.props.onChange(enableEmail);
this.setState({emailInterval});
}
submit() {
// 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());
this.props.onSubmit();
}
expand() {
this.props.updateSection('email');
}
collapse() {
this.props.updateSection('');
}
render() {
if (this.props.activeSection !== 'email') {
let description;
if (this.props.enableEmail) {
switch (this.state.emailInterval) {
case Preferences.INTERVAL_IMMEDIATE:
description = (