2
2
* External dependencies
3
3
*/
4
4
import { getHistory , getNewPath , getQuery } from '@woocommerce/navigation' ;
5
- import { createInterpolateElement , useEffect } from '@wordpress/element' ;
5
+ import {
6
+ createInterpolateElement ,
7
+ useEffect ,
8
+ useCallback ,
9
+ useState ,
10
+ } from '@wordpress/element' ;
6
11
import { __ } from '@wordpress/i18n' ;
7
12
import { Button } from '@wordpress/components' ;
8
13
import { recordEvent } from '@woocommerce/tracks' ;
14
+ import PropTypes from 'prop-types' ;
9
15
10
16
/**
11
17
* Internal dependencies
12
18
*/
13
19
import { getCreateCampaignUrl } from '.~/utils/urls' ;
20
+ import isWCTracksEnabled from '.~/utils/isWCTracksEnabled' ;
14
21
import AppModal from '.~/components/app-modal' ;
15
22
import GuidePageContent , {
16
23
ContentLink ,
17
24
} from '.~/components/guide-page-content' ;
25
+ import CustomerEffortScorePrompt from '.~/components/customer-effort-score-prompt' ;
18
26
import { GUIDE_NAMES } from '.~/constants' ;
19
27
import headerImageURL from './header.svg' ;
20
28
import './index.scss' ;
@@ -41,12 +49,26 @@ const handleCloseWithAction = ( e, specifiedAction ) => {
41
49
42
50
const handleRequestClose = ( e ) => handleCloseWithAction ( e , 'dismiss' ) ;
43
51
44
- const GuideImplementation = ( ) => {
52
+ const GuideImplementation = ( { isOpen, setCESPromptOpen } ) => {
53
+ const handleGotItClick = useCallback (
54
+ ( e ) => {
55
+ handleCloseWithAction ( e ) ;
56
+ setCESPromptOpen ( true ) ;
57
+ } ,
58
+ [ setCESPromptOpen ]
59
+ ) ;
60
+
45
61
useEffect ( ( ) => {
46
- recordEvent ( 'gla_modal_open' , {
47
- context : GUIDE_NAMES . CAMPAIGN_CREATION_SUCCESS ,
48
- } ) ;
49
- } , [ ] ) ;
62
+ if ( isOpen ) {
63
+ recordEvent ( 'gla_modal_open' , {
64
+ context : GUIDE_NAMES . CAMPAIGN_CREATION_SUCCESS ,
65
+ } ) ;
66
+ }
67
+ } , [ isOpen ] ) ;
68
+
69
+ if ( ! isOpen ) {
70
+ return null ;
71
+ }
50
72
51
73
return (
52
74
< AppModal
@@ -68,7 +90,7 @@ const GuideImplementation = () => {
68
90
key = "1"
69
91
isPrimary
70
92
data-action = "confirm"
71
- onClick = { handleCloseWithAction }
93
+ onClick = { handleGotItClick }
72
94
>
73
95
{ __ ( 'Got it' , 'google-listings-and-ads' ) }
74
96
</ Button > ,
@@ -110,17 +132,44 @@ const GuideImplementation = () => {
110
132
) ;
111
133
} ;
112
134
135
+ GuideImplementation . propTypes = {
136
+ /**
137
+ * Whether the campaign creation success guide must be shown
138
+ */
139
+ isOpen : PropTypes . bool . isRequired ,
140
+ /**
141
+ * Function to enable or disable the CES prompt
142
+ */
143
+ setCESPromptOpen : PropTypes . func . isRequired ,
144
+ } ;
145
+
113
146
/**
114
147
* Modal window to prompt the user at Dashboard, after successful completing the campaign creation.
115
148
*
116
149
* Show this guide modal by visiting the path with a specific query `guide=campaign-creation-success`.
117
150
* For example: `/wp-admin/admin.php?page=wc-admin&path=%2Fgoogle%2Fdashboard&guide=campaign-creation-success`.
118
151
*/
119
152
export default function CampaignCreationSuccessGuide ( ) {
153
+ const [ isCESPromptOpen , setCESPromptOpen ] = useState ( false ) ;
154
+
120
155
const isOpen = getQuery ( ) . guide === GUIDE_NAMES . CAMPAIGN_CREATION_SUCCESS ;
156
+ const wcTracksEnabled = isWCTracksEnabled ( ) ;
121
157
122
- if ( ! isOpen ) {
123
- return null ;
124
- }
125
- return < GuideImplementation /> ;
158
+ return (
159
+ < >
160
+ < GuideImplementation
161
+ isOpen = { isOpen }
162
+ setCESPromptOpen = { setCESPromptOpen }
163
+ />
164
+ { isCESPromptOpen && wcTracksEnabled && (
165
+ < CustomerEffortScorePrompt
166
+ label = { __ (
167
+ 'How easy was it to create a Google Ad campaign?' ,
168
+ 'google-listings-and-ads'
169
+ ) }
170
+ eventContext = "create-ad-campaign"
171
+ />
172
+ ) }
173
+ </ >
174
+ ) ;
126
175
}
0 commit comments