// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import React from 'react'; import Constants from 'utils/constants.jsx'; import * as Utils from 'utils/utils.jsx'; import AdminSettings from './admin_settings.jsx'; import DropdownSetting from './dropdown_setting.jsx'; import {FormattedMessage, FormattedHTMLMessage} from 'react-intl'; import SettingsGroup from './settings_group.jsx'; import TextSetting from './text_setting.jsx'; const PUSH_NOTIFICATIONS_OFF = 'off'; const PUSH_NOTIFICATIONS_MHPNS = 'mhpns'; const PUSH_NOTIFICATIONS_MTPNS = 'mtpns'; const PUSH_NOTIFICATIONS_CUSTOM = 'custom'; export default class PushSettings extends AdminSettings { constructor(props) { super(props); this.canSave = this.canSave.bind(this); this.handleAgreeChange = this.handleAgreeChange.bind(this); this.getConfigFromState = this.getConfigFromState.bind(this); this.renderSettings = this.renderSettings.bind(this); let pushNotificationServerType = PUSH_NOTIFICATIONS_CUSTOM; let agree = false; if (!props.config.EmailSettings.SendPushNotifications) { pushNotificationServerType = PUSH_NOTIFICATIONS_OFF; } else if (props.config.EmailSettings.PushNotificationServer === Constants.MHPNS && global.window.mm_license.IsLicensed === 'true' && global.window.mm_license.MHPNS === 'true') { pushNotificationServerType = PUSH_NOTIFICATIONS_MHPNS; agree = true; } else if (props.config.EmailSettings.PushNotificationServer === Constants.MTPNS) { pushNotificationServerType = PUSH_NOTIFICATIONS_MTPNS; } else { pushNotificationServerType = PUSH_NOTIFICATIONS_CUSTOM; } let pushNotificationServer = this.props.config.EmailSettings.PushNotificationServer; if (pushNotificationServerType === PUSH_NOTIFICATIONS_MTPNS) { pushNotificationServer = Constants.MTPNS; } else if (pushNotificationServerType === PUSH_NOTIFICATIONS_MHPNS) { pushNotificationServer = Constants.MHPNS; } this.state = Object.assign(this.state, { pushNotificationServerType, pushNotificationServer, pushNotificationContents: props.config.EmailSettings.PushNotificationContents, agree }); } canSave() { return this.state.pushNotificationServerType !== PUSH_NOTIFICATIONS_MHPNS || this.state.agree; } handleAgreeChange(e) { this.setState({ agree: e.target.checked }); } handleChange(id, value) { if (id === 'pushNotificationServerType') { this.setState({ agree: false }); if (value === PUSH_NOTIFICATIONS_MHPNS) { this.setState({ pushNotificationServer: Constants.MHPNS }); } else if (value === PUSH_NOTIFICATIONS_MTPNS) { this.setState({ pushNotificationServer: Constants.MTPNS }); } } super.handleChange(id, value); } getConfigFromState(config) { config.EmailSettings.SendPushNotifications = this.state.pushNotificationServerType !== PUSH_NOTIFICATIONS_OFF; config.EmailSettings.PushNotificationServer = this.state.pushNotificationServer.trim(); config.EmailSettings.PushNotificationContents = this.state.pushNotificationContents; return config; } renderTitle() { return (