forked from woocommerce/google-listings-and-ads
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
155 lines (147 loc) · 5.25 KB
/
index.js
File metadata and controls
155 lines (147 loc) · 5.25 KB
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
/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { createInterpolateElement } from '@wordpress/element';
/**
* Internal dependencies
*/
import useJetpackAccount from '.~/hooks/useJetpackAccount';
import useGoogleAccount from '.~/hooks/useGoogleAccount';
import useGoogleMCAccount from '.~/hooks/useGoogleMCAccount';
import AppButton from '.~/components/app-button';
import AppSpinner from '.~/components/app-spinner';
import StepContent from '.~/components/stepper/step-content';
import StepContentHeader from '.~/components/stepper/step-content-header';
import StepContentFooter from '.~/components/stepper/step-content-footer';
import Section from '.~/wcdl/section';
import AppDocumentationLink from '.~/components/app-documentation-link';
import VerticalGapLayout from '.~/components/vertical-gap-layout';
import WPComAccountCard from '.~/components/wpcom-account-card';
import GoogleAccountCard from '.~/components/google-account-card';
import GoogleMCAccountCard from '.~/components/google-mc-account-card';
import Faqs from './faqs';
import './index.scss';
/**
* Renders the disclaimer of Comparison Shopping Service (CSS).
*
* @fires gla_documentation_link_click with `{ context: 'setup-mc-accounts', link_id: 'comparison-shopping-services', href: 'https://support.google.com/merchants/topic/9080307' }`
* @fires gla_documentation_link_click with `{ context: 'setup-mc-accounts', link_id: 'comparison-shopping-partners-find-a-partner', href: 'https://comparisonshoppingpartners.withgoogle.com/find_a_partner/' }`
*/
const GoogleMCDisclaimer = () => {
return (
<>
<p>
{ createInterpolateElement(
__(
'If you are in the European Economic Area or Switzerland, your Merchant Center account must be associated with a Comparison Shopping Service (CSS). Please find more information at <link>Google Merchant Center Help</link> website.',
'google-listings-and-ads'
),
{
link: (
<AppDocumentationLink
context="setup-mc-accounts"
linkId="comparison-shopping-services"
href="https://support.google.com/merchants/topic/9080307"
/>
),
}
) }
</p>
<p>
{ createInterpolateElement(
__(
'If you create a new Merchant Center account through this application, it will be associated with Google Shopping, Google’s CSS, by default. You can change the CSS associated with your account at any time. Please find more information about our CSS Partners <link>here</link>.',
'google-listings-and-ads'
),
{
link: (
<AppDocumentationLink
context="setup-mc-accounts"
linkId="comparison-shopping-partners-find-a-partner"
href="https://comparisonshoppingpartners.withgoogle.com/find_a_partner/"
/>
),
}
) }
</p>
<p>
{ __(
'Once you have set up your Merchant Center account you can use our onboarding tool regardless of which CSS you use.',
'google-listings-and-ads'
) }
</p>
</>
);
};
const SetupAccounts = ( props ) => {
const { onContinue = () => {} } = props;
const { jetpack } = useJetpackAccount();
const { google, scope } = useGoogleAccount();
const { googleMCAccount, isPreconditionReady: isGMCPreconditionReady } =
useGoogleMCAccount();
/**
* When jetpack is loading, or when google account is loading,
* or when GMC account is loading, we display the AppSpinner.
*
* The account loading is in sequential manner, one after another.
*
* Note that we can't use hasFinishedResolution here.
* If we do, when GMC account is connected, resolution would be fired again,
* and the whole page would display this AppSpinner, which is not desired.
*/
const isLoadingJetpack = ! jetpack;
const isLoadingGoogle = jetpack?.active === 'yes' && ! google;
const isLoadingGoogleMCAccount =
google?.active === 'yes' && scope.gmcRequired && ! googleMCAccount;
if ( isLoadingJetpack || isLoadingGoogle || isLoadingGoogleMCAccount ) {
return <AppSpinner />;
}
const isGoogleAccountDisabled = jetpack?.active !== 'yes';
const isContinueButtonDisabled = googleMCAccount?.status !== 'connected';
return (
<StepContent>
<StepContentHeader
title={ __(
'Set up your accounts',
'google-listings-and-ads'
) }
description={ __(
'Connect the accounts required to use Google Listings & Ads.',
'google-listings-and-ads'
) }
/>
<Section
className="gla-wp-google-accounts-section"
title={ __( 'Connect accounts', 'google-listings-and-ads' ) }
description={ __(
'The following accounts are required to use the Google Listings & Ads plugin.',
'google-listings-and-ads'
) }
>
<VerticalGapLayout size="large">
<WPComAccountCard jetpack={ jetpack } />
<GoogleAccountCard disabled={ isGoogleAccountDisabled } />
</VerticalGapLayout>
</Section>
<Section
className="gla-google-mc-account-section"
description={ <GoogleMCDisclaimer /> }
disabledLeft={ ! isGMCPreconditionReady }
>
<GoogleMCAccountCard />
<Faqs />
</Section>
<StepContentFooter>
<AppButton
isPrimary
disabled={ isContinueButtonDisabled }
onClick={ onContinue }
>
{ __( 'Continue', 'google-listings-and-ads' ) }
</AppButton>
</StepContentFooter>
</StepContent>
);
};
export default SetupAccounts;