1
1
/**
2
2
* External dependencies
3
3
*/
4
- import { getHistory , getNewPath , getQuery } from '@woocommerce/navigation' ;
5
4
import {
6
5
createInterpolateElement ,
7
6
useEffect ,
8
7
useCallback ,
9
- useState ,
10
8
} from '@wordpress/element' ;
11
9
import { __ } from '@wordpress/i18n' ;
12
10
import { Button } from '@wordpress/components' ;
@@ -15,59 +13,41 @@ import { recordEvent } from '@woocommerce/tracks';
15
13
/**
16
14
* Internal dependencies
17
15
*/
18
- import { getCreateCampaignUrl } from '.~/utils/urls' ;
19
- import isWCTracksEnabled from '.~/utils/isWCTracksEnabled' ;
20
16
import AppModal from '.~/components/app-modal' ;
21
17
import GuidePageContent , {
22
18
ContentLink ,
23
19
} from '.~/components/guide-page-content' ;
24
- import CustomerEffortScorePrompt from '.~/components/customer-effort-score-prompt' ;
25
20
import { GUIDE_NAMES } from '.~/constants' ;
26
21
import headerImageURL from './header.svg' ;
27
22
import './index.scss' ;
23
+ import {
24
+ CTA_CREATE_ANOTHER_CAMPAIGN ,
25
+ CTA_CONFIRM ,
26
+ CTA_DISMISS ,
27
+ } from '../constants' ;
28
28
29
- const CTA_CREATE_ANOTHER_CAMPAIGN = 'create-another-campaign' ;
30
-
31
- const handleCloseWithAction = ( e , specifiedAction ) => {
32
- const action = specifiedAction || e . currentTarget . dataset . action ;
33
- const nextQuery = {
34
- ...getQuery ( ) ,
35
- guide : undefined ,
36
- } ;
37
- getHistory ( ) . replace ( getNewPath ( nextQuery ) ) ;
38
-
39
- if ( action === CTA_CREATE_ANOTHER_CAMPAIGN ) {
40
- getHistory ( ) . push ( getCreateCampaignUrl ( ) ) ;
41
- }
42
-
43
- recordEvent ( 'gla_modal_closed' , {
44
- context : GUIDE_NAMES . CAMPAIGN_CREATION_SUCCESS ,
45
- action,
46
- } ) ;
47
- } ;
48
-
49
- const handleRequestClose = ( e ) => handleCloseWithAction ( e , 'dismiss' ) ;
50
-
51
- const GuideImplementation = ( { isOpen, setCESPromptOpen } ) => {
52
- const handleGotItClick = useCallback (
53
- ( e ) => {
54
- handleCloseWithAction ( e ) ;
55
- setCESPromptOpen ( true ) ;
56
- } ,
57
- [ setCESPromptOpen ]
58
- ) ;
59
-
29
+ /**
30
+ * Modal window to prompt the user at Dashboard, after successful completing the campaign creation.
31
+ *
32
+ * Show this guide modal by visiting the path with a specific query `guide=campaign-creation-success`.
33
+ * For example: `/wp-admin/admin.php?page=wc-admin&path=%2Fgoogle%2Fdashboard&guide=campaign-creation-success`.
34
+ *
35
+ * @param {Object } props React component props.
36
+ * @param {Function } props.onGuideRequestClose The function to be called when the guide is closed.
37
+ */
38
+ export default function CampaignCreationSuccessGuide ( {
39
+ onGuideRequestClose = ( ) => { } ,
40
+ } ) {
60
41
useEffect ( ( ) => {
61
- if ( isOpen ) {
62
- recordEvent ( 'gla_modal_open' , {
63
- context : GUIDE_NAMES . CAMPAIGN_CREATION_SUCCESS ,
64
- } ) ;
65
- }
66
- } , [ isOpen ] ) ;
42
+ recordEvent ( 'gla_modal_open' , {
43
+ context : GUIDE_NAMES . CAMPAIGN_CREATION_SUCCESS ,
44
+ } ) ;
45
+ } , [ ] ) ;
67
46
68
- if ( ! isOpen ) {
69
- return null ;
70
- }
47
+ const handleRequestClose = useCallback (
48
+ ( e ) => onGuideRequestClose ( e , CTA_DISMISS ) ,
49
+ [ onGuideRequestClose ]
50
+ ) ;
71
51
72
52
return (
73
53
< AppModal
@@ -78,7 +58,7 @@ const GuideImplementation = ( { isOpen, setCESPromptOpen } ) => {
78
58
key = "0"
79
59
isTertiary
80
60
data-action = { CTA_CREATE_ANOTHER_CAMPAIGN }
81
- onClick = { handleCloseWithAction }
61
+ onClick = { onGuideRequestClose }
82
62
>
83
63
{ __ (
84
64
'Create another campaign' ,
@@ -88,8 +68,8 @@ const GuideImplementation = ( { isOpen, setCESPromptOpen } ) => {
88
68
< Button
89
69
key = "1"
90
70
isPrimary
91
- data-action = "confirm"
92
- onClick = { handleGotItClick }
71
+ data-action = { CTA_CONFIRM }
72
+ onClick = { onGuideRequestClose }
93
73
>
94
74
{ __ ( 'Got it' , 'google-listings-and-ads' ) }
95
75
</ Button > ,
@@ -129,35 +109,4 @@ const GuideImplementation = ( { isOpen, setCESPromptOpen } ) => {
129
109
</ GuidePageContent >
130
110
</ AppModal >
131
111
) ;
132
- } ;
133
-
134
- /**
135
- * Modal window to prompt the user at Dashboard, after successful completing the campaign creation.
136
- *
137
- * Show this guide modal by visiting the path with a specific query `guide=campaign-creation-success`.
138
- * For example: `/wp-admin/admin.php?page=wc-admin&path=%2Fgoogle%2Fdashboard&guide=campaign-creation-success`.
139
- */
140
- export default function CampaignCreationSuccessGuide ( ) {
141
- const [ isCESPromptOpen , setCESPromptOpen ] = useState ( false ) ;
142
-
143
- const isOpen = getQuery ( ) ?. guide === GUIDE_NAMES . CAMPAIGN_CREATION_SUCCESS ;
144
- const wcTracksEnabled = isWCTracksEnabled ( ) ;
145
-
146
- return (
147
- < >
148
- < GuideImplementation
149
- isOpen = { isOpen }
150
- setCESPromptOpen = { setCESPromptOpen }
151
- />
152
- { isCESPromptOpen && wcTracksEnabled && (
153
- < CustomerEffortScorePrompt
154
- label = { __ (
155
- 'How easy was it to create a Google Ad campaign?' ,
156
- 'google-listings-and-ads'
157
- ) }
158
- eventContext = { GUIDE_NAMES . CAMPAIGN_CREATION_SUCCESS }
159
- />
160
- ) }
161
- </ >
162
- ) ;
163
112
}
0 commit comments