import React from 'react'; import PureRenderMixin from 'react-addons-pure-render-mixin'; import Flux from '../lib/flux'; import lodash from 'lodash'; import NoticeStore from '../stores/NoticeStore'; import ChannelStore from '../stores/ChannelStore'; import UserStore from '../stores/UserStore'; import SelectedChannelStore from '../stores/SelectedChannelStore'; import { UserSettingsSections, DetectedPlatformAccountsDisplayTypes, NoticeTypes, CreateGuildModalScreens, } from '../Constants'; import ModalActionCreators from '../actions/ModalActionCreators'; import NoticeActionCreators from '../actions/NoticeActionCreators'; import StatusPageActionCreators from '../actions/StatusPageActionCreators'; import UserSettingsModalActionCreators from '../actions/UserSettingsModalActionCreators'; import SelectedChannelActionCreators from '../actions/SelectedChannelActionCreators'; import CreateGuildModalActionCreators from '../actions/CreateGuildModalActionCreators'; import StreamerModeActionCreators from '../actions/StreamerModeActionCreators'; import PlatformAccountsActionCreators from '../actions/PlatformAccountsActionCreators'; import HelpdeskUtils from '../utils/HelpdeskUtils'; import DownloadApps from './DownloadApps'; import DownloadMobileAppsModal from './DownloadMobileAppsModal'; import Platforms from '../lib/Platforms'; import i18n from '../i18n'; import '../styles/notice.styl'; import DisableSilence from './warnings/DisableSilence'; const Notice = React.createClass({ mixins: [Flux.StoreListenerMixin(NoticeStore, UserStore), PureRenderMixin], getStateFromStores() { const notice = NoticeStore.getNotice(); return { currentUser: UserStore.getCurrentUser(), ...notice, }; }, getInitialState() { return { requestingNotifications: false, }; }, handleDownload() { ModalActionCreators.push(DownloadApps, {source: 'Top Bar Nag'}); }, handleClaimAccount() { UserSettingsModalActionCreators.open(UserSettingsSections.ACCOUNT); }, handleDismiss() { NoticeActionCreators.dismiss(); }, handleIgnorePlatformAccounts() { this.handleDismiss(); PlatformAccountsActionCreators.ignore(); }, handleDismissSilenceWarning() { this.handleDismiss(); ModalActionCreators.push(DisableSilence); }, handleDismissVoiceDisconnected() { const channelId = SelectedChannelStore.getVoiceChannelId(); if (channelId != null) { SelectedChannelActionCreators.clearVoiceChannel(); } this.handleDismiss(); }, handleVoiceReconnect() { const channelId = SelectedChannelStore.getVoiceChannelId(); if (channelId != null) { const channel = ChannelStore.getChannel(channelId); if (channel != null) { SelectedChannelActionCreators.selectVoiceChannel(channel['guild_id'], channelId); } } }, handleDismissScheduledMaintenance() { StatusPageActionCreators.ackScheduledMaintenance(); }, handleDisableStreamerMode() { StreamerModeActionCreators.setEnabled(false); }, handleOpenAuthorizedApps() { UserSettingsModalActionCreators.open(UserSettingsSections.AUTHORIZED_APPS); }, handleShowDetectedAccounts() { PlatformAccountsActionCreators.changeDisplayType(DetectedPlatformAccountsDisplayTypes.MODAL); }, handleCreateServer() { CreateGuildModalActionCreators.open(CreateGuildModalScreens.CreateGuild, 'Notice'); }, handleLaunchSurvey() { window.open('https://www.surveymonkey.com/r/6CCXTPS', '_blank'); this.handleDismiss(); }, handleOpenDownloadMobileApps() { this.handleDismiss(); ModalActionCreators.push(DownloadMobileAppsModal); }, render() { switch (this.state.type) { case NoticeTypes.GENERIC: return (
{this.state.message}
); case NoticeTypes.VOICE_DISABLED: return (
{i18n.Messages.NOTICE_CONNECTION_CONFLICT}
); case NoticeTypes.UNCLAIMED_ACCOUNT: return (
{i18n.Messages.NOTICE_UNCLAIMED_ACCOUNT}
); case NoticeTypes.DOWNLOAD_NAG: return (
{i18n.Messages.NOTICE_NATIVE_APPS}
); case NoticeTypes.SCHEDULED_MAINTENANCE: return (
{i18n.Messages.NOTICE_SCHEDULED_MAINTENANCE.format(this.state.metadata)} {i18n.Messages.LEARN_MORE}
); case NoticeTypes.NO_INPUT_DETECTED: return (
{i18n.Messages.NOTICE_NO_INPUT_DETECTED} {i18n.Messages.NOTICE_NO_INPUT_DETECTED_HELP_LINK_TEXT}
); case NoticeTypes.STREAMER_MODE: return (
{i18n.Messages.NOTICE_STREAMER_MODE_TEXT}
); case NoticeTypes.RPC_CONNECTIONS: return (
{i18n.Messages.NOTICE_RPC_CONNECTIONS_TEXT.format(this.state.metadata)}
); case NoticeTypes.DETECTED_PLATFORM_ACCOUNTS: const platforms = lodash.uniq(this.state.metadata.map(account => Platforms.get(account.type))); const platformNames = platforms.map(platform => platform.name); const [a, b, c] = platformNames; let body; if (platformNames.length === 1) { body = i18n.Messages.NOTICE_ONE_PLATFORM_ACCOUNT.format({a}); } else if (platformNames.length === 2) { body = i18n.Messages.NOTICE_TWO_PLATFORM_ACCOUNTS.format({a, b}); } else if (platformNames.length === 3) { body = i18n.Messages.NOTICE_THREE_PLATFORM_ACCOUNTS.format({a, b, c}); } else { body = i18n.Messages.NOTICE_FOUR_OR_MORE_PLATFORM_ACCOUNTS.format({a, b, c}); } return (
{platforms.map(platform => )} {body}
); case NoticeTypes.DOWNLOAD_MOBILE_APPS: return (
{i18n.Messages.NOTICE_DOWNLOAD_MOBILE_APPS}
); case NoticeTypes.SURVEY: return (
{i18n.Messages.NOTICE_SURVEY_PROMPT}
); case NoticeTypes.CORRUPT_INSTALLATION: return (
{i18n.Messages.NOTICE_CORRUPT_INSTALLATION} {i18n.Messages.NOTICE_CORRUPT_INSTALLATION_HELP_LINK_TEXT}
); default: return null; } }, }); export default Notice; // WEBPACK FOOTER // // ./discord_app/components/Notice.js