-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathskip-button.js
81 lines (71 loc) · 2.6 KB
/
skip-button.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
/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { useState } from '@wordpress/element';
import { noop } from 'lodash';
/**
* Internal dependencies
*/
import useGoogleAdsAccount from '~/hooks/useGoogleAdsAccount';
import useGoogleAdsAccountBillingStatus from '~/hooks/useGoogleAdsAccountBillingStatus';
import AppButton from '~/components/app-button';
import SkipPaidAdsConfirmationModal from './skip-paid-ads-confirmation-modal';
import { recordGlaEvent } from '~/utils/tracks';
/**
* Clicking on the skip paid ads button to complete the onboarding flow.
* The 'unknown' value of properties may means:
* - the final status has not yet been resolved when recording this event
* - the status is not available, for example, the billing status is unknown if Google Ads account is not yet connected
*
* @event gla_onboarding_complete_button_click
* @property {string} google_ads_account_status The connection status of merchant's Google Ads addcount, e.g. 'connected', 'disconnected', 'incomplete'
* @property {string} billing_method_status The status of billing method of merchant's Google Ads addcount e.g. 'unknown', 'pending', 'approved', 'cancelled'
* @property {string} campaign_form_validation Whether the entered paid campaign form data are valid, e.g. 'unknown', 'valid', 'invalid'
*/
export default function SkipButton( {
isValidForm,
onSkipCreatePaidAds = noop,
loading,
disabled,
} ) {
const [
showSkipPaidAdsConfirmationModal,
setShowSkipPaidAdsConfirmationModal,
] = useState( false );
const { googleAdsAccount } = useGoogleAdsAccount();
const { billingStatus } = useGoogleAdsAccountBillingStatus();
const handleOnSkipClick = () => {
setShowSkipPaidAdsConfirmationModal( true );
};
const handleCancelSkipPaidAdsClick = () => {
setShowSkipPaidAdsConfirmationModal( false );
};
const handleSkipCreatePaidAds = () => {
setShowSkipPaidAdsConfirmationModal( false );
const eventProps = {
google_ads_account_status: googleAdsAccount?.status,
billing_method_status: billingStatus?.status || 'unknown',
campaign_form_validation: isValidForm ? 'valid' : 'invalid',
};
recordGlaEvent( 'gla_onboarding_complete_button_click', eventProps );
onSkipCreatePaidAds();
};
return (
<>
<AppButton
isTertiary
text={ __( 'Skip ads creation', 'google-listings-and-ads' ) }
loading={ loading }
disabled={ disabled }
onClick={ handleOnSkipClick }
/>
{ showSkipPaidAdsConfirmationModal && (
<SkipPaidAdsConfirmationModal
onRequestClose={ handleCancelSkipPaidAdsClick }
onSkipCreatePaidAds={ handleSkipCreatePaidAds }
/>
) }
</>
);
}