|
| 1 | +/** |
| 2 | + * External dependencies |
| 3 | + */ |
| 4 | +import { __ } from '@wordpress/i18n'; |
| 5 | +import { createInterpolateElement, useState } from '@wordpress/element'; |
| 6 | +import { CheckboxControl } from '@wordpress/components'; |
| 7 | + |
| 8 | +/** |
| 9 | + * Internal dependencies |
| 10 | + */ |
| 11 | +import { glaData } from '.~/constants'; |
| 12 | +import AccountCard, { APPEARANCE } from '.~/components/account-card'; |
| 13 | +import AppButton from '.~/components/app-button'; |
| 14 | +import readMoreLink from '../google-account-card/read-more-link'; |
| 15 | +import useGoogleConnectFlow from '../google-account-card/use-google-connect-flow'; |
| 16 | +import AppDocumentationLink from '../app-documentation-link'; |
| 17 | +import './connect-google-combo-account-card.scss'; |
| 18 | + |
| 19 | +/** |
| 20 | + * @param {Object} props React props |
| 21 | + * @param {boolean} props.disabled |
| 22 | + * @fires gla_google_account_connect_button_click with `{ action: 'authorization', context: 'reconnect' }` |
| 23 | + * @fires gla_google_account_connect_button_click with `{ action: 'authorization', context: 'setup-mc' }` |
| 24 | + * @fires gla_documentation_link_click with `{ context: 'setup-mc-accounts', link_id: 'required-google-permissions', href: 'https://woocommerce.com/document/google-for-woocommerce/get-started/setup-and-configuration/#required-google-permissions' }` |
| 25 | + * @fires gla_documentation_link_click with `{ context: 'setup-mc-accounts', link_id: 'google-mc-terms-of-service', href: 'https://support.google.com/merchants/answer/160173' }` |
| 26 | + * @fires gla_documentation_link_click with `{ context: 'setup-ads', link_id: 'google-ads-terms-of-service', href: 'https://support.google.com/adspolicy/answer/54818' }` |
| 27 | + */ |
| 28 | +const ConnectGoogleComboAccountCard = ( { disabled } ) => { |
| 29 | + const pageName = glaData.mcSetupComplete ? 'reconnect' : 'setup-mc'; |
| 30 | + const [ handleConnect, { loading, data } ] = |
| 31 | + useGoogleConnectFlow( pageName ); |
| 32 | + const [ termsAccepted, setTermsAccepted ] = useState( false ); |
| 33 | + |
| 34 | + return ( |
| 35 | + <AccountCard |
| 36 | + appearance={ APPEARANCE.GOOGLE } |
| 37 | + className="gla-connect-google-combo-account-card" |
| 38 | + disabled={ disabled } |
| 39 | + alignIcon="top" |
| 40 | + description={ |
| 41 | + <> |
| 42 | + <p> |
| 43 | + { __( |
| 44 | + 'Required to sync with Google Merchant Center and Google Ads.', |
| 45 | + 'google-listings-and-ads' |
| 46 | + ) } |
| 47 | + </p> |
| 48 | + <CheckboxControl |
| 49 | + label={ createInterpolateElement( |
| 50 | + __( |
| 51 | + 'I accept the terms and conditions of <linkMerchant>Merchant Center</linkMerchant> and <linkAds>Google Ads</linkAds>', |
| 52 | + 'google-listings-and-ads' |
| 53 | + ), |
| 54 | + { |
| 55 | + linkMerchant: ( |
| 56 | + <AppDocumentationLink |
| 57 | + context="setup-mc-accounts" |
| 58 | + linkId="google-mc-terms-of-service" |
| 59 | + href="https://support.google.com/merchants/answer/160173" |
| 60 | + /> |
| 61 | + ), |
| 62 | + linkAds: ( |
| 63 | + <AppDocumentationLink |
| 64 | + context="setup-ads" |
| 65 | + linkId="google-ads-terms-of-service" |
| 66 | + href="https://support.google.com/adspolicy/answer/54818" |
| 67 | + /> |
| 68 | + ), |
| 69 | + } |
| 70 | + ) } |
| 71 | + checked={ termsAccepted } |
| 72 | + onChange={ setTermsAccepted } |
| 73 | + disabled={ disabled } |
| 74 | + /> |
| 75 | + </> |
| 76 | + } |
| 77 | + helper={ createInterpolateElement( |
| 78 | + __( |
| 79 | + 'You will be prompted to give WooCommerce access to your Google account. Please check all the checkboxes to give WooCommerce all required permissions. <link>Read more</link>', |
| 80 | + 'google-listings-and-ads' |
| 81 | + ), |
| 82 | + { |
| 83 | + link: readMoreLink, |
| 84 | + } |
| 85 | + ) } |
| 86 | + alignIndicator="top" |
| 87 | + indicator={ |
| 88 | + <AppButton |
| 89 | + isSecondary |
| 90 | + disabled={ disabled || ! termsAccepted } |
| 91 | + loading={ loading || data } |
| 92 | + eventName="gla_google_account_connect_button_click" |
| 93 | + eventProps={ { |
| 94 | + context: pageName, |
| 95 | + action: 'authorization', |
| 96 | + } } |
| 97 | + text={ __( 'Connect', 'google-listings-and-ads' ) } |
| 98 | + onClick={ handleConnect } |
| 99 | + /> |
| 100 | + } |
| 101 | + /> |
| 102 | + ); |
| 103 | +}; |
| 104 | + |
| 105 | +export default ConnectGoogleComboAccountCard; |
0 commit comments