diff --git a/modules/ppcp-settings/resources/js/Components/App.js b/modules/ppcp-settings/resources/js/Components/App.js index 74e20bd87..e32f705ce 100644 --- a/modules/ppcp-settings/resources/js/Components/App.js +++ b/modules/ppcp-settings/resources/js/Components/App.js @@ -8,6 +8,8 @@ import OnboardingScreen from './Screens/Onboarding'; import SettingsScreen from './Screens/Settings'; import { getQuery, cleanUrlQueryParams } from '../utils/navigation'; +import { initializeTracking } from '../services/tracking'; + const SettingsApp = () => { const { isReady: onboardingIsReady, completed: onboardingCompleted } = OnboardingHooks.useSteps(); @@ -16,6 +18,10 @@ const SettingsApp = () => { merchant: { isSendOnlyCountry }, } = CommonHooks.useMerchantInfo(); + useEffect( () => { + initializeTracking(); + }, [] ); + // Disable the "Changes you made might not be saved" browser warning. useEffect( () => { const suppressBeforeUnload = ( event ) => { diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Components/ConnectionButton.js b/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Components/ConnectionButton.js index 55932143c..54f64724f 100644 --- a/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Components/ConnectionButton.js +++ b/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Components/ConnectionButton.js @@ -1,8 +1,9 @@ import { Button } from '@wordpress/components'; -import { useEffect } from '@wordpress/element'; +import { useEffect, useCallback } from '@wordpress/element'; import classNames from 'classnames'; import { OpenSignup } from '../../../ReusableComponents/Icons'; import { useHandleOnboardingButton } from '../../../../hooks/useHandleConnections'; +import { OnboardingHooks } from '../../../../data/onboarding/hooks'; import BusyStateWrapper from '../../../ReusableComponents/BusyStateWrapper'; /** @@ -10,12 +11,13 @@ import BusyStateWrapper from '../../../ReusableComponents/BusyStateWrapper'; * placeholder button looks identical to the working button, but has no href, target, or * custom connection attributes. * - * @param {Object} props - * @param {string} props.className - * @param {string} props.variant - * @param {boolean} props.showIcon - * @param {?string} props.href - * @param {Element} props.children + * @param {Object} props + * @param {string} props.className + * @param {string} props.variant + * @param {boolean} props.showIcon + * @param {?string} props.href + * @param {Element} props.children + * @param {Function} props.onClick */ const ButtonOrPlaceholder = ( { className, @@ -23,11 +25,13 @@ const ButtonOrPlaceholder = ( { showIcon, href, children, + onClick, } ) => { const buttonProps = { className, variant, icon: showIcon ? OpenSignup : null, + onClick, }; if ( href ) { @@ -52,12 +56,28 @@ const ConnectionButton = ( { setCompleteHandler, removeCompleteHandler, } = useHandleOnboardingButton( isSandbox ); + + const { connectionButtonClicked, setConnectionButtonClicked } = + OnboardingHooks.useConnectionButton(); + const buttonClassName = classNames( 'ppcp-r-connection-button', className, { 'ppcp--mode-sandbox': isSandbox, 'ppcp--mode-live': ! isSandbox, + 'ppcp--button-clicked': connectionButtonClicked, } ); const environment = isSandbox ? 'sandbox' : 'production'; + const handleButtonClick = useCallback( () => { + setConnectionButtonClicked( true ); + }, [ setConnectionButtonClicked ] ); + + // Reset button clicked state when onboardingUrl becomes available. + useEffect( () => { + if ( onboardingUrl && connectionButtonClicked ) { + setConnectionButtonClicked( false ); + } + }, [ onboardingUrl, connectionButtonClicked, setConnectionButtonClicked ] ); + useEffect( () => { if ( scriptLoaded && onboardingUrl ) { window.PAYPAL.apps.Signup.render(); @@ -82,6 +102,7 @@ const ConnectionButton = ( { variant={ variant } showIcon={ showIcon } href={ onboardingUrl } + onClick={ handleButtonClick } > { title } diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Components/ManualConnectionForm.js b/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Components/ManualConnectionForm.js index 2c65e21e8..2c9d54ed5 100644 --- a/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Components/ManualConnectionForm.js +++ b/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Components/ManualConnectionForm.js @@ -17,6 +17,7 @@ import { useSandboxConnection, } from '../../../../hooks/useHandleConnections'; import { OnboardingHooks } from '../../../../data'; +import { useManualConnection } from '../../../../data/common/hooks'; const FORM_ERRORS = { noClientId: __( @@ -43,14 +44,19 @@ const ManualConnectionForm = () => { manualClientSecret, setManualClientSecret, } = OnboardingHooks.useManualConnectionForm(); - const { - handleDirectAuthentication, - isManualConnectionMode, - setManualConnectionMode, - } = useDirectAuthentication(); + + const { handleDirectAuthentication } = useDirectAuthentication(); + + const { isManualConnectionMode, setManualConnectionMode } = + useManualConnection(); + const refClientId = useRef( null ); const refClientSecret = useRef( null ); + const handleToggle = ( isEnabled ) => { + setManualConnectionMode( isEnabled, 'user' ); + }; + // Form data validation and sanitation. const getManualConnectionDetails = useCallback( () => { const checks = [ @@ -148,7 +154,7 @@ const ManualConnectionForm = () => { ) } description={ advancedUsersDescription } isToggled={ !! isManualConnectionMode } - setToggled={ setManualConnectionMode } + setToggled={ handleToggle } > { const { isSandboxMode, setSandboxMode } = useSandboxConnection(); + const handleToggle = ( isEnabled ) => { + setSandboxMode( isEnabled, 'user' ); + }; + return ( { 'woocommerce-paypal-payments' ) } isToggled={ !! isSandboxMode } - setToggled={ setSandboxMode } + setToggled={ handleToggle } > { return; } - setIsCasualSeller( BUSINESS_TYPES.CASUAL_SELLER === businessChoice ); + setIsCasualSeller( + BUSINESS_TYPES.CASUAL_SELLER === businessChoice, + 'user' + ); }, [ businessChoice, setIsCasualSeller ] ); const { canUseSubscriptions } = OnboardingHooks.useFlags(); diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Steps/StepPaymentMethods.js b/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Steps/StepPaymentMethods.js index 1863944bf..d32f145eb 100644 --- a/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Steps/StepPaymentMethods.js +++ b/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Steps/StepPaymentMethods.js @@ -47,6 +47,10 @@ const StepPaymentMethods = () => { }, ]; + const handleMethodChange = ( value ) => { + setOptionalMethods( value, 'user' ); + }; + return (
{ diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Steps/StepProducts.js b/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Steps/StepProducts.js index 5497787fb..a961551bc 100644 --- a/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Steps/StepProducts.js +++ b/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Steps/StepProducts.js @@ -38,7 +38,7 @@ const StepProducts = () => { }; initChoices(); - }, [ canUseSubscriptions, optionState, products, setProducts ] ); + }, [ canUseSubscriptions, isCasualSeller ] ); const handleChange = ( key, checked ) => { const getNewValue = () => { @@ -48,7 +48,7 @@ const StepProducts = () => { return products.filter( ( val ) => val !== key ); }; - setProducts( getNewValue() ); + setProducts( getNewValue(), 'user' ); }; const productChoicesFull = [ { diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Steps/StepWelcome.js b/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Steps/StepWelcome.js index 47b846889..c8d8c8de4 100644 --- a/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Steps/StepWelcome.js +++ b/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Steps/StepWelcome.js @@ -14,7 +14,6 @@ import { usePaymentConfig } from '../hooks/usePaymentConfig'; const StepWelcome = ( { setStep, currentStep } ) => { const { storeCountry, ownBrandOnly } = CommonHooks.useWooSettings(); const { canUseCardPayments, canUseFastlane } = OnboardingHooks.useFlags(); - const { isCasualSeller } = OnboardingHooks.useBusiness(); const { icons } = usePaymentConfig( storeCountry, @@ -34,6 +33,11 @@ const StepWelcome = ( { setStep, currentStep } ) => { 'woocommerce-paypal-payments' ); + const handleActivatePayPal = () => { + const nextStep = currentStep + 1; + setStep( nextStep, 'user' ); + }; + return (
{