File size: 11,500 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
import { WPCOM_FEATURES_SITE_PREVIEW_LINKS } from '@automattic/calypso-products';
import { FormLabel } from '@automattic/components';
import clsx from 'clsx';
import { useTranslate } from 'i18n-calypso';
import QuerySiteDomains from 'calypso/components/data/query-site-domains';
import FormInputCheckbox from 'calypso/components/forms/form-checkbox';
import FormFieldset from 'calypso/components/forms/form-fieldset';
import FormRadio from 'calypso/components/forms/form-radio';
import FormSettingExplanation from 'calypso/components/forms/form-setting-explanation';
import InlineSupportLink from 'calypso/components/inline-support-link';
import SitePreviewLinks from 'calypso/components/site-preview-links';
import { useDispatch, useSelector } from 'calypso/state';
import { recordGoogleEvent } from 'calypso/state/analytics/actions';
import getPrimaryDomainBySiteId from 'calypso/state/selectors/get-primary-domain-by-site-id';
import siteHasFeature from 'calypso/state/selectors/site-has-feature';
import { useSiteGlobalStylesStatus } from 'calypso/state/sites/hooks/use-site-global-styles-status';
import {
	getSelectedSite,
	getSelectedSiteId,
	getSelectedSiteSlug,
} from 'calypso/state/ui/selectors';
import {
	SiteSettingPrivacyPremiumStylesNotice,
	SiteSettingsPrivacyDiscourageSearchEnginesNotice,
} from './notice';
import type { Fields } from './index';

interface SiteSettingPrivacyFormProps {
	fields: Fields;
	updateFields: ( fields: Fields ) => void;
	isAtomicAndEditingToolkitDeactivated: boolean;
	isComingSoon: boolean;
	isRequestingSettings: boolean;
	isSavingSettings: boolean;
	isUnlaunchedSite: boolean;
	isWPForTeamsSite: boolean | null;
	isWpcomStagingSite: boolean;
	siteIsAtomic: boolean | null;
	siteIsJetpack: boolean | null;
}

const SiteSettingPrivacyForm = ( {
	fields,
	siteIsAtomic,
	siteIsJetpack,
	updateFields,
	isAtomicAndEditingToolkitDeactivated,
	isComingSoon,
	isRequestingSettings,
	isSavingSettings,
	isUnlaunchedSite,
	isWPForTeamsSite,
	isWpcomStagingSite,
}: SiteSettingPrivacyFormProps ) => {
	const dispatch = useDispatch();
	const translate = useTranslate();
	const selectedSite = useSelector( getSelectedSite );
	const siteId = useSelector( getSelectedSiteId ) || -1;
	const siteSlug = useSelector( getSelectedSiteSlug );
	const hasSitePreviewLink = useSelector( ( state ) =>
		siteHasFeature( state, siteId, WPCOM_FEATURES_SITE_PREVIEW_LINKS )
	);

	const primaryDomain = useSelector( ( state ) => getPrimaryDomainBySiteId( state, siteId ) );

	const { globalStylesInUse, shouldLimitGlobalStyles } = useSiteGlobalStylesStatus( siteId );

	const blogPublic = Number( fields.blog_public );
	const wpcomComingSoon = 1 === Number( fields.wpcom_coming_soon );
	const wpcomPublicComingSoon = 1 === Number( fields.wpcom_public_coming_soon );
	const wpcomDataSharingOptOut = !! fields.wpcom_data_sharing_opt_out;
	// isPrivateAndUnlaunched means it is an unlaunched coming soon v1 site
	const isPrivateAndUnlaunched = -1 === blogPublic && isUnlaunchedSite;
	const isNonAtomicJetpackSite = siteIsJetpack && ! siteIsAtomic;
	const isAnyComingSoonEnabled =
		( 0 === blogPublic && wpcomPublicComingSoon ) || isPrivateAndUnlaunched || wpcomComingSoon;
	const isComingSoonDisabled = isRequestingSettings || isAtomicAndEditingToolkitDeactivated;
	const isPublicChecked =
		( wpcomPublicComingSoon && blogPublic === 0 && isComingSoonDisabled ) ||
		( blogPublic === 0 && ! wpcomPublicComingSoon ) ||
		blogPublic === 1;

	const showPreviewLink = isComingSoon && hasSitePreviewLink;
	const shouldShowPremiumStylesNotice = globalStylesInUse && shouldLimitGlobalStyles;

	const discourageSearchChecked =
		( wpcomPublicComingSoon && blogPublic === 0 && isComingSoonDisabled ) ||
		( 0 === blogPublic && ! wpcomPublicComingSoon ) ||
		primaryDomain?.isWpcomStagingDomain;

	const recordEvent = ( message: string ) => {
		dispatch( recordGoogleEvent( 'Site Settings', message ) );
	};

	const handleVisibilityOptionChange = ( {
		blog_public,
		wpcom_coming_soon,
		wpcom_public_coming_soon,
		wpcom_data_sharing_opt_out,
	}: Fields ) => {
		recordEvent( `Set blog_public to ${ blog_public }` );
		recordEvent( `Set wpcom_coming_soon to ${ wpcom_coming_soon }` );
		recordEvent( `Set wpcom_public_coming_soon to ${ wpcom_public_coming_soon }` );
		recordEvent( `Set wpcom_data_sharing_opt_out to ${ wpcom_data_sharing_opt_out }` );
		updateFields( {
			blog_public,
			wpcom_coming_soon,
			wpcom_public_coming_soon,
			wpcom_data_sharing_opt_out,
		} );
	};

	return (
		<form>
			{ siteId && <QuerySiteDomains siteId={ siteId } /> }
			<FormFieldset>
				{ ! isNonAtomicJetpackSite &&
					! isWPForTeamsSite &&
					! isAtomicAndEditingToolkitDeactivated && (
						<>
							{ shouldShowPremiumStylesNotice && (
								<SiteSettingPrivacyPremiumStylesNotice
									selectedSite={ selectedSite }
									siteSlug={ siteSlug }
								/>
							) }
							<FormLabel
								className={ clsx( 'site-settings__visibility-label is-coming-soon', {
									'is-coming-soon-disabled': isComingSoonDisabled,
								} ) }
							>
								<FormRadio
									className={ undefined }
									name="blog_public"
									value="0"
									checked={ isAnyComingSoonEnabled }
									onChange={ () =>
										handleVisibilityOptionChange( {
											blog_public: 0,
											wpcom_coming_soon: 0,
											wpcom_public_coming_soon: 1,
											wpcom_data_sharing_opt_out: false,
										} )
									}
									disabled={ isComingSoonDisabled }
									onClick={ () => {
										recordEvent( 'Clicked Site Visibility Radio Button' );
									} }
									label={ translate( 'Coming Soon' ) }
								/>
							</FormLabel>
							<FormSettingExplanation>
								{ translate(
									'Your site is hidden from visitors behind a "Coming Soon" notice until it is ready for viewing.'
								) }
							</FormSettingExplanation>
							{ showPreviewLink && selectedSite && (
								<div className="site-settings__visibility-label is-checkbox">
									<SitePreviewLinks
										siteUrl={ selectedSite.URL }
										siteId={ siteId }
										disabled={ ! isAnyComingSoonEnabled || isSavingSettings }
										forceOff={ ! isAnyComingSoonEnabled }
										source="privacy-settings"
									/>
								</div>
							) }
						</>
					) }
				{ ! isNonAtomicJetpackSite && (
					<>
						<FormLabel className="site-settings__visibility-label is-public">
							<FormRadio
								className={ undefined }
								name="blog_public"
								value="1"
								checked={ isPublicChecked }
								onChange={ () =>
									handleVisibilityOptionChange( {
										blog_public: isWpcomStagingSite ? 0 : 1,
										wpcom_coming_soon: 0,
										wpcom_public_coming_soon: 0,
										wpcom_data_sharing_opt_out: false,
									} )
								}
								disabled={ isRequestingSettings }
								onClick={ () => {
									recordEvent( 'Clicked Site Visibility Radio Button' );
								} }
								label={ translate( 'Public' ) }
							/>
						</FormLabel>
						<FormSettingExplanation>
							{ isWpcomStagingSite
								? translate(
										'Your site is visible to everyone, but search engines are discouraged from indexing staging sites.'
								  )
								: translate( 'Your site is visible to everyone.' ) }
						</FormSettingExplanation>
					</>
				) }

				{ isPublicChecked && ! isWpcomStagingSite && (
					<>
						<FormLabel className="site-settings__visibility-label is-checkbox is-hidden">
							<FormInputCheckbox
								name="blog_public"
								value="0"
								checked={ discourageSearchChecked }
								onChange={ () =>
									handleVisibilityOptionChange( {
										blog_public: wpcomPublicComingSoon || blogPublic !== 0 ? 0 : 1,
										wpcom_coming_soon: 0,
										wpcom_public_coming_soon: 0,
										wpcom_data_sharing_opt_out: true,
									} )
								}
								// See https://github.com/Automattic/wp-calypso/issues/101828.
								disabled={ isRequestingSettings || primaryDomain?.isWpcomStagingDomain }
								onClick={ () => {
									recordEvent( 'Clicked Site Visibility Radio Button' );
								} }
							/>
							<span>{ translate( 'Discourage search engines from indexing this site' ) }</span>
							<FormSettingExplanation>
								{ translate(
									'This option does not block access to your site — it is up to search engines to honor your request.'
								) }
							</FormSettingExplanation>
							{ primaryDomain?.isWpcomStagingDomain && (
								<SiteSettingsPrivacyDiscourageSearchEnginesNotice
									selectedSite={ selectedSite }
									siteSlug={ siteSlug }
								/>
							) }
						</FormLabel>
						{ ! isNonAtomicJetpackSite && (
							<FormLabel className="site-settings__visibility-label is-checkbox is-hidden">
								<FormInputCheckbox
									name="wpcom_data_sharing_opt_out"
									value="true"
									checked={
										( wpcomPublicComingSoon && wpcomDataSharingOptOut && isComingSoonDisabled ) ||
										( wpcomDataSharingOptOut && ! wpcomPublicComingSoon ) ||
										discourageSearchChecked
									}
									onChange={ () =>
										handleVisibilityOptionChange( {
											blog_public: wpcomPublicComingSoon || blogPublic !== 0 ? 1 : 0,
											wpcom_coming_soon: 0,
											wpcom_public_coming_soon: 0,
											wpcom_data_sharing_opt_out: ! wpcomDataSharingOptOut,
										} )
									}
									disabled={ isRequestingSettings || discourageSearchChecked }
									onClick={ () => recordEvent( 'Clicked Partnership Radio Button' ) }
								/>
								<span style={ { overflowWrap: 'anywhere' } }>
									{ translate( 'Prevent third-party sharing for %(siteName)s', {
										args: {
											siteName: siteSlug || '',
										},
									} ) }
								</span>
								<FormSettingExplanation>
									{ translate(
										'This option will prevent this site’s content from being shared with our licensed network of content and research partners, including those that train AI models. {{a}}Learn more{{/a}}.',
										{
											components: {
												a: (
													<InlineSupportLink
														showIcon={ false }
														supportContext="privacy-prevent-third-party-sharing"
													/>
												),
											},
										}
									) }
								</FormSettingExplanation>
							</FormLabel>
						) }
					</>
				) }
				{ ! isNonAtomicJetpackSite && (
					<>
						<FormLabel className="site-settings__visibility-label is-private">
							<FormRadio
								className={ undefined }
								name="blog_public"
								value="-1"
								checked={
									( -1 === blogPublic && ! wpcomComingSoon && ! isPrivateAndUnlaunched ) ||
									( wpcomComingSoon && isAtomicAndEditingToolkitDeactivated )
								}
								onChange={ () =>
									handleVisibilityOptionChange( {
										blog_public: -1,
										wpcom_coming_soon: 0,
										wpcom_public_coming_soon: 0,
										wpcom_data_sharing_opt_out: false,
									} )
								}
								disabled={ isRequestingSettings }
								onClick={ () => {
									recordEvent( 'Clicked Site Visibility Radio Button' );
								} }
								label={ translate( 'Private' ) }
							/>
						</FormLabel>
						<FormSettingExplanation>
							{ translate(
								'Your site is only visible to you and logged-in members you approve. Everyone else will see a log in screen.'
							) }
						</FormSettingExplanation>
					</>
				) }
			</FormFieldset>
		</form>
	);
};

export default SiteSettingPrivacyForm;