import { Card, LoadingPlaceholder } from '@automattic/components'; import { ToggleControl } from '@wordpress/components'; import { localize } from 'i18n-calypso'; import { get } from 'lodash'; import { Component } from 'react'; import { connect } from 'react-redux'; import FormSectionHeading from 'calypso/components/forms/form-section-heading'; import Main from 'calypso/components/main'; import NavigationHeader from 'calypso/components/navigation-header'; import PageViewTracker from 'calypso/lib/analytics/page-view-tracker'; import twoStepAuthorization from 'calypso/lib/two-step-authorization'; import ReauthRequired from 'calypso/me/reauth-required'; import { fetchSettings, toggleWPcomEmailSetting, saveSettings, } from 'calypso/state/notification-settings/actions'; import { getNotificationSettings, isFetchingNotificationsSettings, } from 'calypso/state/notification-settings/selectors'; import hasJetpackSites from 'calypso/state/selectors/has-jetpack-sites'; import Navigation from '../navigation'; import SubscriptionManagementBackButton from '../subscription-management-back-button'; import EmailCategory from './email-category'; import './style.scss'; /** * Module variables for wpcom */ const options = { marketing: 'marketing', research: 'research', community: 'community', promotion: 'promotion', news: 'news', digest: 'digest', reports: 'reports', news_developer: 'news_developer', scheduled_updates: 'scheduled_updates', }; /** * Module variables for jetpack */ const jetpackOptions = { jetpack_marketing: 'jetpack_marketing', jetpack_research: 'jetpack_research', jetpack_promotion: 'jetpack_promotion', jetpack_news: 'jetpack_news', jetpack_reports: 'jetpack_reports', }; class WPCOMNotifications extends Component { static displayName = 'WPCOMNotifications'; // TODO: Add propTypes componentDidMount() { this.props.fetchSettings(); } unsubscribeFromAll = ( productOptions ) => ( toggleValue ) => { const toggledSettings = {}; Object.keys( productOptions ).forEach( ( option ) => { if ( this.props.settings[ option ] !== toggleValue ) { toggledSettings[ option ] = toggleValue; this.props.toggleWPcomEmailSetting( option ); } } ); this.props.saveSettings( 'wpcom', toggledSettings ); }; toggleShouldBeOff = ( productOptions ) => { return Object.keys( productOptions ).some( ( key ) => key in this.props.settings && this.props.settings[ key ] === true ); }; renderWpcomPreferences = () => { const { settings, translate } = this.props; return (

{ translate( "We'll always send important emails regarding your account, security, " + 'privacy, and purchase transactions, but you can get some helpful extras, too.' ) }

{ this.props.translate( 'Email from WordPress.com' ) } { this.props.hasJetpackSites && ( <> { this.props.translate( 'Email from Jetpack' ) }

{ this.props.translate( 'Jetpack is a suite of tools connected to your WordPress site, like backups, security, and performance reports.' ) }

) }
); }; renderPlaceholder = () => { return ; }; render() { return (
{ this.props.settings ? this.renderWpcomPreferences() : this.renderPlaceholder() }
); } } export default connect( ( state ) => ( { settings: getNotificationSettings( state, 'wpcom' ), hasJetpackSites: hasJetpackSites( state ), isFetching: isFetchingNotificationsSettings( state ), } ), { fetchSettings, toggleWPcomEmailSetting, saveSettings } )( localize( WPCOMNotifications ) );