-
Notifications
You must be signed in to change notification settings - Fork 2k
/
main.jsx
344 lines (317 loc) · 12.5 KB
/
main.jsx
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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
import config from '@automattic/calypso-config';
import { Button } from '@automattic/components';
import { localizeUrl } from '@automattic/i18n-utils';
import { useQueryClient } from '@tanstack/react-query';
import { ExternalLink } from '@wordpress/components';
import { useTranslate } from 'i18n-calypso';
import { useEffect, useState } from 'react';
import { connect, useSelector } from 'react-redux';
import SiteIcon from 'calypso/blocks/site-icon';
import AsyncLoad from 'calypso/components/async-load';
import DocumentHead from 'calypso/components/data/document-head';
import QuerySiteChecklist from 'calypso/components/data/query-site-checklist';
import EmptyContent from 'calypso/components/empty-content';
import { JetpackConnectionHealthBanner } from 'calypso/components/jetpack/connection-health';
import Main from 'calypso/components/main';
import NavigationHeader from 'calypso/components/navigation-header';
import Notice from 'calypso/components/notice';
import NoticeAction from 'calypso/components/notice/notice-action';
import useDomainDiagnosticsQuery from 'calypso/data/domains/diagnostics/use-domain-diagnostics-query';
import { useGetDomainsQuery } from 'calypso/data/domains/use-get-domains-query';
import useHomeLayoutQuery, { getCacheKey } from 'calypso/data/home/use-home-layout-query';
import PageViewTracker from 'calypso/lib/analytics/page-view-tracker';
import TrackComponentView from 'calypso/lib/analytics/track-component-view';
import { setDomainNotice } from 'calypso/lib/domains/set-domain-notice';
import { preventWidows } from 'calypso/lib/formatting';
import { getQueryArgs } from 'calypso/lib/query-args';
import { SET_UP_EMAIL_AUTHENTICATION_FOR_YOUR_DOMAIN } from 'calypso/lib/url/support';
import Primary from 'calypso/my-sites/customer-home/locations/primary';
import Secondary from 'calypso/my-sites/customer-home/locations/secondary';
import Tertiary from 'calypso/my-sites/customer-home/locations/tertiary';
import WooCommerceHomePlaceholder from 'calypso/my-sites/customer-home/wc-home-placeholder';
import { domainManagementEdit } from 'calypso/my-sites/domains/paths';
import { bumpStat, composeAnalytics, recordTracksEvent } from 'calypso/state/analytics/actions';
import { verifyIcannEmail } from 'calypso/state/domains/management/actions';
import { withJetpackConnectionProblem } from 'calypso/state/jetpack-connection-health/selectors/is-jetpack-connection-problem';
import {
getPluginOnSite,
isRequesting as isRequestingInstalledPlugins,
} from 'calypso/state/plugins/installed/selectors';
import getRequest from 'calypso/state/selectors/get-request';
import { getSelectedEditor } from 'calypso/state/selectors/get-selected-editor';
import isFetchingJetpackModules from 'calypso/state/selectors/is-fetching-jetpack-modules';
import isJetpackModuleActive from 'calypso/state/selectors/is-jetpack-module-active';
import isUserRegistrationDaysWithinRange from 'calypso/state/selectors/is-user-registration-days-within-range';
import { getDomainsBySiteId } from 'calypso/state/sites/domains/selectors';
import { launchSite } from 'calypso/state/sites/launch/actions';
import { isSiteOnWooExpressEcommerceTrial } from 'calypso/state/sites/plans/selectors';
import {
canCurrentUserUseCustomerHome,
getSitePlan,
getSiteOption,
} from 'calypso/state/sites/selectors';
import isJetpackSite from 'calypso/state/sites/selectors/is-jetpack-site';
import { getSelectedSite, getSelectedSiteId } from 'calypso/state/ui/selectors';
import CelebrateLaunchModal from './components/celebrate-launch-modal';
import './style.scss';
const Home = ( {
canUserUseCustomerHome,
hasWooCommerceInstalled,
isJetpack,
isPossibleJetpackConnectionProblem,
isRequestingSitePlugins,
isSiteLaunching,
site,
siteId,
trackViewSiteAction,
isSiteWooExpressEcommerceTrial,
ssoModuleActive,
fetchingJetpackModules,
handleVerifyIcannEmail,
} ) => {
const [ celebrateLaunchModalIsOpen, setCelebrateLaunchModalIsOpen ] = useState( false );
const [ launchedSiteId, setLaunchedSiteId ] = useState( null );
const queryClient = useQueryClient();
const translate = useTranslate();
const { data: layout, isLoading, error: homeLayoutError } = useHomeLayoutQuery( siteId );
const { data: allDomains = [], isSuccess } = useGetDomainsQuery( site?.ID ?? null, {
retry: false,
} );
const siteDomains = useSelector( ( state ) => getDomainsBySiteId( state, siteId ) );
const customDomains = siteDomains?.filter( ( domain ) => ! domain.isWPCOMDomain );
const customDomain = customDomains?.length ? customDomains[ 0 ] : undefined;
const primaryDomain = customDomains?.find( ( domain ) => domain.isPrimary );
const {
data: domainDiagnosticData,
isFetching: isFetchingDomainDiagnostics,
refetch: refetchDomainDiagnosticData,
} = useDomainDiagnosticsQuery( primaryDomain?.name, {
staleTime: 5 * 60 * 1000,
gcTime: 5 * 60 * 1000,
enabled: primaryDomain !== undefined && primaryDomain.isMappedToAtomicSite,
} );
const emailDnsDiagnostics = domainDiagnosticData?.email_dns_records;
const [ dismissedEmailDnsDiagnostics, setDismissedEmailDnsDiagnostics ] = useState( false );
useEffect( () => {
if ( getQueryArgs().celebrateLaunch === 'true' && isSuccess ) {
setCelebrateLaunchModalIsOpen( true );
}
}, [ isSuccess ] );
useEffect( () => {
if ( ! isSiteLaunching && launchedSiteId === siteId ) {
queryClient.invalidateQueries( { queryKey: getCacheKey( siteId ) } );
setLaunchedSiteId( null );
}
}, [ isSiteLaunching, launchedSiteId, queryClient, siteId ] );
useEffect( () => {
if ( isSiteLaunching ) {
setLaunchedSiteId( siteId );
}
}, [ isSiteLaunching, siteId ] );
useEffect( () => {
if ( emailDnsDiagnostics?.dismissed_email_dns_issues_notice ) {
setDismissedEmailDnsDiagnostics( true );
}
}, [ emailDnsDiagnostics ] );
if ( ! canUserUseCustomerHome ) {
const title = translate( 'This page is not available on this site.' );
return (
<EmptyContent
title={ preventWidows( title ) }
illustration="/calypso/images/illustrations/error.svg"
/>
);
}
// Ecommerce Plan's Home redirects to WooCommerce Home, so we show a placeholder
// while doing the redirection.
if (
isSiteWooExpressEcommerceTrial &&
( isRequestingSitePlugins || hasWooCommerceInstalled ) &&
( fetchingJetpackModules || ssoModuleActive )
) {
return <WooCommerceHomePlaceholder />;
}
const headerActions = (
<>
<Button href={ site.URL } onClick={ trackViewSiteAction } target="_blank">
{ config.isEnabled( 'layout/dotcom-nav-redesign' ) &&
'wp-admin' === site?.options?.wpcom_admin_interface
? translate( 'View site' )
: translate( 'Visit site' ) }
</Button>
</>
);
const header = (
<div className="customer-home__heading">
<NavigationHeader
compactBreadcrumb={ false }
navigationItems={ [] }
mobileItem={ null }
title={ translate( 'My Home' ) }
subtitle={ translate( 'Your hub for next steps, support center, and quick links.' ) }
>
{ headerActions }
</NavigationHeader>
<div className="customer-home__site-content">
<SiteIcon site={ site } size={ 58 } />
<div className="customer-home__site-info">
<div className="customer-home__site-title">{ site.name }</div>
<ExternalLink
href={ site.URL }
className="customer-home__site-domain"
onClick={ trackViewSiteAction }
>
<span className="customer-home__site-domain-text">{ site.domain }</span>
</ExternalLink>
</div>
</div>
</div>
);
const renderUnverifiedEmailNotice = () => {
if ( customDomain?.isPendingIcannVerification ) {
return (
<Notice
text={ translate(
'You must respond to the ICANN email to verify your domain email address or your domain will stop working. Please check your inbox and respond to the email.'
) }
icon="cross-circle"
showDismiss={ false }
status="is-warning"
>
<NoticeAction onClick={ () => handleVerifyIcannEmail( customDomain.name ) }>
{ translate( 'Resend Email' ) }
</NoticeAction>
</Notice>
);
}
return null;
};
const renderDnsSettingsDiagnosticNotice = () => {
if (
dismissedEmailDnsDiagnostics ||
isFetchingDomainDiagnostics ||
! emailDnsDiagnostics ||
emailDnsDiagnostics.code === 'domain_not_mapped_to_atomic_site' ||
emailDnsDiagnostics.all_essential_email_dns_records_are_correct
) {
return null;
}
return (
<Notice
text={ translate(
"There are some issues with your domain's email DNS settings. {{diagnosticLink}}Click here{{/diagnosticLink}} to see the full diagnostic for your domain. {{supportLink}}Learn more{{/supportLink}}.",
{
components: {
diagnosticLink: (
<a
href={ domainManagementEdit( siteId, primaryDomain.name, null, {
diagnostics: true,
} ) }
/>
),
supportLink: (
<a href={ localizeUrl( SET_UP_EMAIL_AUTHENTICATION_FOR_YOUR_DOMAIN ) } />
),
},
}
) }
icon="cross-circle"
showDismiss={ true }
onDismissClick={ () => {
setDismissedEmailDnsDiagnostics( true );
setDomainNotice( primaryDomain.name, 'email-dns-records-diagnostics', 'ignored', () => {
refetchDomainDiagnosticData();
} );
} }
status="is-warning"
/>
);
};
return (
<Main wideLayout className="customer-home__main">
<PageViewTracker path="/home/:site" title={ translate( 'My Home' ) } />
<DocumentHead title={ translate( 'My Home' ) } />
{ siteId && <QuerySiteChecklist siteId={ siteId } /> }
{ siteId && isJetpack && isPossibleJetpackConnectionProblem && (
<JetpackConnectionHealthBanner siteId={ siteId } />
) }
{ header }
{ ! isLoading && ! layout && homeLayoutError ? (
<TrackComponentView
eventName="calypso_customer_home_my_site_view_layout_error"
eventProperties={ {
site_id: siteId,
error: homeLayoutError?.message ?? 'Layout is not available.',
} }
/>
) : null }
{ renderUnverifiedEmailNotice() }
{ renderDnsSettingsDiagnosticNotice() }
{ isLoading && <div className="customer-home__loading-placeholder"></div> }
{ ! isLoading && layout && ! homeLayoutError ? (
<>
<Primary cards={ layout?.primary } />
<div className="customer-home__layout">
<div className="customer-home__layout-col customer-home__layout-col-left">
<Secondary cards={ layout?.secondary } siteId={ siteId } />
</div>
<div className="customer-home__layout-col customer-home__layout-col-right">
<Tertiary cards={ layout?.tertiary } />
</div>
</div>
</>
) : null }
{ celebrateLaunchModalIsOpen && (
<CelebrateLaunchModal
setModalIsOpen={ setCelebrateLaunchModalIsOpen }
site={ site }
allDomains={ allDomains }
/>
) }
<AsyncLoad require="calypso/lib/analytics/track-resurrections" placeholder={ null } />
</Main>
);
};
const mapStateToProps = ( state ) => {
const siteId = getSelectedSiteId( state );
const isClassicEditor = getSelectedEditor( state, siteId ) === 'classic';
const installedWooCommercePlugin = getPluginOnSite( state, siteId, 'woocommerce' );
return {
site: getSelectedSite( state ),
sitePlan: getSitePlan( state, siteId ),
siteId,
isJetpack: isJetpackSite( state, siteId ),
isNew7DUser: isUserRegistrationDaysWithinRange( state, null, 0, 7 ),
canUserUseCustomerHome: canCurrentUserUseCustomerHome( state, siteId ),
isStaticHomePage:
! isClassicEditor && 'page' === getSiteOption( state, siteId, 'show_on_front' ),
hasWooCommerceInstalled: !! ( installedWooCommercePlugin && installedWooCommercePlugin.active ),
isRequestingSitePlugins: isRequestingInstalledPlugins( state, siteId ),
isSiteWooExpressEcommerceTrial: isSiteOnWooExpressEcommerceTrial( state, siteId ),
ssoModuleActive: !! isJetpackModuleActive( state, siteId, 'sso' ),
fetchingJetpackModules: !! isFetchingJetpackModules( state, siteId ),
isSiteLaunching: getRequest( state, launchSite( siteId ) )?.isLoading ?? false,
};
};
const trackViewSiteAction = ( isStaticHomePage ) =>
composeAnalytics(
recordTracksEvent( 'calypso_customer_home_my_site_view_site_click', {
is_static_home_page: isStaticHomePage,
} ),
bumpStat( 'calypso_customer_home', 'my_site_view_site' )
);
const mapDispatchToProps = {
trackViewSiteAction,
verifyIcannEmail,
};
const mergeProps = ( stateProps, dispatchProps, ownProps ) => {
const { isStaticHomePage } = stateProps;
return {
...ownProps,
...stateProps,
trackViewSiteAction: () => dispatchProps.trackViewSiteAction( isStaticHomePage ),
handleVerifyIcannEmail: dispatchProps.verifyIcannEmail,
};
};
const connectHome = connect( mapStateToProps, mapDispatchToProps, mergeProps );
export default connectHome( withJetpackConnectionProblem( Home ) );