-
Notifications
You must be signed in to change notification settings - Fork 21
/
claim-account-button.js
60 lines (51 loc) · 1.89 KB
/
claim-account-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
/**
* External dependencies
*/
import { noop } from 'lodash';
/**
* Internal dependencies
*/
import AppButton from '~/components/app-button';
import getWindowFeatures from '~/utils/getWindowFeatures';
import { FILTER_ONBOARDING } from '~/utils/tracks';
import useGoogleAdsAccountStatus from '~/hooks/useGoogleAdsAccountStatus';
import useEventPropertiesFilter from '~/hooks/useEventPropertiesFilter';
/**
* Clicking on the button to open the invitation page for claiming the newly created Google Ads account.
*
* @event gla_open_ads_account_claim_invitation_button_click
* @property {string} [context] Indicates the place where the button is located.
* @property {string} [step] Indicates the step in the onboarding process.
*/
/**
* Renders a button for opening a pop-up window to claim the newly created Google Ads account.
*
* @fires gla_open_ads_account_claim_invitation_button_click When the user clicks on the button to claim the account.
*
* @param {Object} props React props.
* @param {Function} [props.onClick] Function called back when the button is clicked.
* @param {Object} props.restProps Props to be forwarded to AppButton.
*/
const ClaimAccountButton = ( { onClick = noop, ...restProps } ) => {
const { inviteLink } = useGoogleAdsAccountStatus();
const getEventProps = useEventPropertiesFilter( FILTER_ONBOARDING );
const handleClaimAccountClick = ( event ) => {
const { defaultView } = event.target.ownerDocument;
const features = getWindowFeatures( defaultView, 600, 800 );
defaultView.open( inviteLink, '_blank', features );
onClick( event );
};
// If there is no invite link, we don't render the button.
if ( ! inviteLink ) {
return null;
}
return (
<AppButton
{ ...restProps }
eventName="gla_open_ads_account_claim_invitation_button_click"
eventProps={ getEventProps() }
onClick={ handleClaimAccountClick }
/>
);
};
export default ClaimAccountButton;