File size: 2,672 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { Card } from '@automattic/components';
import { localize } from 'i18n-calypso';
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 SettingsForm from 'calypso/me/notification-settings/settings-form';
import ReauthRequired from 'calypso/me/reauth-required';
import { fetchSettings, toggle, saveSettings } from 'calypso/state/notification-settings/actions';
import {
	getNotificationSettings,
	hasUnsavedNotificationSettingsChanges,
} from 'calypso/state/notification-settings/selectors';
import Navigation from '../navigation';
import SubscriptionManagementBackButton from '../subscription-management-back-button';

import './style.scss';

class NotificationCommentsSettings extends Component {
	componentDidMount() {
		this.props.fetchSettings();
	}

	renderForm = () => {
		if ( this.props.settings ) {
			return (
				<SettingsForm
					sourceId="other"
					settings={ this.props.settings }
					settingKeys={ [ 'comment_like', 'comment_reply' ] }
					hasUnsavedChanges={ this.props.hasUnsavedChanges }
					onToggle={ ( source, stream, setting ) => this.props.toggle( source, stream, setting ) }
					onSave={ () => this.props.saveSettings( 'other', this.props.settings ) }
				/>
			);
		}

		return <p className="comment-settings__notification-settings-placeholder">&nbsp;</p>;
	};

	render() {
		const { path, translate } = this.props;

		return (
			<Main wideLayout className="comment-settings__main">
				<PageViewTracker
					path="/me/notifications/comments"
					title="Me > Notifications > Comments on other sites"
				/>
				<ReauthRequired twoStepAuthorization={ twoStepAuthorization } />

				<SubscriptionManagementBackButton />

				<NavigationHeader navigationItems={ [] } title={ translate( 'Notification Settings' ) } />

				<Navigation path={ path } />

				<Card>
					<FormSectionHeading>{ translate( 'Comments on other sites' ) }</FormSectionHeading>
					<p>{ translate( 'Manage notifications for comments you leave on other sites.' ) }</p>
					{ this.renderForm() }
				</Card>
			</Main>
		);
	}
}

export default connect(
	( state ) => ( {
		settings: getNotificationSettings( state, 'other' ),
		hasUnsavedChanges: hasUnsavedNotificationSettingsChanges( state, 'other' ),
	} ),
	{ fetchSettings, toggle, saveSettings }
)( localize( NotificationCommentsSettings ) );