-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathindex.js
219 lines (205 loc) · 5.86 KB
/
index.js
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
/**
* External dependencies
*/
import { getHistory } from '@woocommerce/navigation';
import {
createInterpolateElement,
useEffect,
useCallback,
} from '@wordpress/element';
import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import Guide from '~/components/external/wordpress/guide';
import GuidePageContent, { ContentLink } from '~/components/guide-page-content';
import AppButton from '~/components/app-button';
import AddPaidCampaignButton from '~/components/paid-ads/add-paid-campaign-button';
import { glaData, GUIDE_NAMES, LOCAL_STORAGE_KEYS } from '~/constants';
import localStorage from '~/utils/localStorage';
import { getProductFeedUrl } from '~/utils/urls';
import wooLogoURL from '~/images/logo/woocommerce-logo.svg';
import googleLogoURL from '~/images/logo/google-logo.svg';
import { recordGlaEvent } from '~/utils/tracks';
import './index.scss';
const EVENT_NAME = 'gla_modal_closed';
const image = (
<div className="gla-submission-success-guide__logo-block">
<div className="gla-submission-success-guide__logo-item gla-submission-success-guide__logo-item--woocommerce">
<img
src={ wooLogoURL }
alt={ __( 'WooCommerce Logo', 'google-listings-and-ads' ) }
width="187.5"
/>
</div>
<div className="gla-submission-success-guide__logo-separator-line" />
<div className="gla-submission-success-guide__logo-item">
<img
src={ googleLogoURL }
alt={ __( 'Google Logo', 'google-listings-and-ads' ) }
width="85"
/>
</div>
</div>
);
const pages = [
{
image,
content: (
<GuidePageContent
title={ __(
'You’ve successfully set up Google for WooCommerce! 🎉',
'google-listings-and-ads'
) }
>
<p>
{ __(
'Your products are being synced and reviewed. Google reviews product listings in 3-5 days.',
'google-listings-and-ads'
) }
</p>
<p>
{ glaData.adsSetupComplete
? __(
'No ads will launch yet and you won’t be charged until Google approves your listings. Updates are available in your WooCommerce dashboard.',
'google-listings-and-ads'
)
: createInterpolateElement(
__(
'<productFeedLink>Manage and edit your product feed in WooCommerce.</productFeedLink> We will also notify you of any product feed issues to ensure your products get approved and perform well on Google.',
'google-listings-and-ads'
),
{
productFeedLink: (
<ContentLink
href={ getProductFeedUrl() }
context="product-feed"
/>
),
}
) }
</p>
</GuidePageContent>
),
},
{
image,
content: (
<GuidePageContent
title={ __(
'Spend $500 to get $500 in Google Ads credits',
'google-listings-and-ads'
) }
>
<p>
{ __(
'New to Google Ads? Get $500 in ad credit when you spend $500 within your first 60 days* You can edit or cancel your campaign at any time.',
'google-listings-and-ads'
) }
</p>
<cite>
{ createInterpolateElement(
__(
'*Full terms and conditions <link>here</link>.',
'google-listings-and-ads'
),
{
link: (
<ContentLink
href="https://www.google.com/ads/coupons/terms/"
context="terms-of-ads-coupons"
/>
),
}
) }
</cite>
</GuidePageContent>
),
},
];
if ( glaData.adsSetupComplete ) {
pages.pop();
}
const handleGuideFinish = ( e ) => {
getHistory().replace( getProductFeedUrl() );
// Since there is no built-in way to distinguish the modal/guide is closed by what action,
// here is a workaround by identifying the close button's data-aciton attribute.
let action = 'dismiss';
if ( e ) {
const target = e.currentTarget || e.target;
action = target.dataset.action || action;
}
recordGlaEvent( EVENT_NAME, {
context: GUIDE_NAMES.SUBMISSION_SUCCESS,
action,
} );
};
/**
* Modal window to greet the user at Product Feed, after successful completion of onboarding.
*
* Show this guide modal by visiting the path with a specific query `guide=submission-success`.
* For example: `/wp-admin/admin.php?page=wc-admin&path=%2Fgoogle%2Fproduct-feed&guide=submission-success`.
*
* @fires gla_modal_closed with `action: 'create-paid-campaign' | 'maybe-later' | 'view-product-feed' | 'dismiss'`
* @fires gla_modal_open with `context: GUIDE_NAMES.SUBMISSION_SUCCESS`
*/
const SubmissionSuccessGuide = () => {
useEffect( () => {
recordGlaEvent( 'gla_modal_open', {
context: GUIDE_NAMES.SUBMISSION_SUCCESS,
} );
// Set a flag in local storage to indicate the CES prompt can be shown
// when the user enters product feed for the first time after setting up.
localStorage.set(
LOCAL_STORAGE_KEYS.CAN_ONBOARDING_SETUP_CES_PROMPT_OPEN,
true
);
}, [] );
const renderFinish = useCallback( () => {
if ( glaData.adsSetupComplete ) {
return (
<AppButton
isPrimary
data-action="view-product-feed"
onClick={ handleGuideFinish }
>
{ __( 'View product feed', 'google-listings-and-ads' ) }
</AppButton>
);
}
return (
<>
<div className="gla-submission-success-guide__space_holder" />
<AppButton
isSecondary
data-action="maybe-later"
onClick={ handleGuideFinish }
>
{ __( 'Maybe later', 'google-listings-and-ads' ) }
</AppButton>
<AddPaidCampaignButton
isPrimary
isSecondary={ false }
isSmall={ false }
eventName={ EVENT_NAME }
eventProps={ {
context: GUIDE_NAMES.SUBMISSION_SUCCESS,
action: 'create-paid-campaign',
} }
>
{ __( 'Create campaign', 'google-listings-and-ads' ) }
</AddPaidCampaignButton>
</>
);
}, [] );
return (
<Guide
className="gla-submission-success-guide"
backButtonText={ __( 'Back', 'google-listings-and-ads' ) }
pages={ pages }
renderFinish={ renderFinish }
onFinish={ handleGuideFinish }
/>
);
};
export default SubmissionSuccessGuide;