File size: 1,444 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
import { ToggleControl } from '@wordpress/components';
import PropTypes from 'prop-types';
import { Component } from 'react';
import { connect } from 'react-redux';
import { toggleWPcomEmailSetting, saveSettings } from 'calypso/state/notification-settings/actions';
import {
getNotificationSettings,
isFetchingNotificationsSettings,
} from 'calypso/state/notification-settings/selectors';
class EmailCategory extends Component {
static propTypes = {
name: PropTypes.string,
isEnabled: PropTypes.bool,
title: PropTypes.string,
description: PropTypes.string,
};
toggleSetting = ( toggleValue ) => {
this.props.toggleWPcomEmailSetting( this.props.name );
// settings is not updated immediately, so we need to save the settings manually
this.props.saveSettings( 'wpcom', {
...this.props.settings,
[ this.props.name ]: toggleValue,
} );
};
render() {
const { isEnabled, description, title } = this.props;
return (
<ToggleControl
__nextHasNoMarginBottom
checked={ isEnabled }
className="wpcom-settings__notification-settings-emailcategory"
help={ description }
label={ title }
onChange={ this.toggleSetting }
disabled={ this.props.isFetching }
/>
);
}
}
export default connect(
( state ) => ( {
settings: getNotificationSettings( state, 'wpcom' ),
isFetching: isFetchingNotificationsSettings( state ),
} ),
{ toggleWPcomEmailSetting, saveSettings }
)( EmailCategory );
|