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
106 lines (97 loc) · 2.67 KB
/
index.js
File metadata and controls
106 lines (97 loc) · 2.67 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
/**
* External dependencies
*/
import { Stepper } from '@woocommerce/components';
import { __ } from '@wordpress/i18n';
import { useState } from '@wordpress/element';
/**
* Internal dependencies
*/
import SetupAccounts from './setup-accounts';
import AdsCampaign from '.~/components/paid-ads/ads-campaign';
import SetupBilling from './setup-billing';
import { recordGlaEvent } from '.~/utils/tracks';
/**
* @param {Object} props React props
* @param {Object} props.formProps Form props forwarded from `Form` component.
* @fires gla_setup_ads with `{ triggered_by: 'step1-continue-button' | 'step2-continue-button' , action: 'go-to-step2' | 'go-to-step3' }`.
* @fires gla_setup_ads with `{ triggered_by: 'stepper-step1-button' | 'stepper-step2-button', action: 'go-to-step1' | 'go-to-step2' }`.
*/
const AdsStepper = ( { formProps } ) => {
const [ step, setStep ] = useState( '1' );
// Allow the users to go backward only, not forward.
// Users can only go forward by clicking on the Continue button.
const handleStepClick = ( value ) => {
if ( value < step ) {
recordGlaEvent( 'gla_setup_ads', {
triggered_by: `stepper-step${ value }-button`,
action: `go-to-step${ value }`,
} );
setStep( value );
}
};
/**
* Handles "onContinue" callback to set the current step and record event tracking.
*
* @param {string} to The next step to go to.
*/
const continueStep = ( to ) => {
const from = step;
recordGlaEvent( 'gla_setup_ads', {
triggered_by: `step${ from }-continue-button`,
action: `go-to-step${ to }`,
} );
setStep( to );
};
const handleSetupAccountsContinue = () => {
continueStep( '2' );
};
const handleCreateCampaignContinue = () => {
continueStep( '3' );
};
return (
// This Stepper with this class name
// should be refactored into separate shared component.
// It is also used in the Setup MC flow.
<Stepper
className="gla-setup-stepper"
currentStep={ step }
steps={ [
{
key: '1',
label: __(
'Set up your accounts',
'google-listings-and-ads'
),
content: (
<SetupAccounts
onContinue={ handleSetupAccountsContinue }
/>
),
onClick: handleStepClick,
},
{
key: '2',
label: __(
'Create your paid campaign',
'google-listings-and-ads'
),
content: (
<AdsCampaign
trackingContext="setup-ads"
onContinue={ handleCreateCampaignContinue }
/>
),
onClick: handleStepClick,
},
{
key: '3',
label: __( 'Set up billing', 'google-listings-and-ads' ),
content: <SetupBilling formProps={ formProps } />,
onClick: handleStepClick,
},
] }
/>
);
};
export default AdsStepper;