2022-09-15 03:58:47 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
2022-09-15 08:26:43 +00:00
|
|
|
import { useEffect, useRef } from '@wordpress/element';
|
|
|
|
import { recordEvent } from '@woocommerce/tracks';
|
2022-09-15 03:58:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { JetpackInstallationStepper } from '../components/JetpackInstallationStepper';
|
|
|
|
import { ModalContentLayoutWithTitle } from '../layouts/ModalContentLayoutWithTitle';
|
2022-09-15 08:26:43 +00:00
|
|
|
import {
|
|
|
|
useJetpackPluginState,
|
|
|
|
JetpackPluginStates,
|
|
|
|
} from '../components/useJetpackPluginState';
|
2022-09-15 03:58:47 +00:00
|
|
|
|
|
|
|
interface JetpackInstallStepperPageProps {
|
|
|
|
isReturningFromWordpressConnection: boolean;
|
2022-09-15 08:26:43 +00:00
|
|
|
isRetryingMagicLinkSend: boolean;
|
2022-09-15 03:58:47 +00:00
|
|
|
sendMagicLinkHandler: () => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const JetpackInstallStepperPage: React.FC<
|
|
|
|
JetpackInstallStepperPageProps
|
2022-09-15 08:26:43 +00:00
|
|
|
> = ( {
|
|
|
|
isReturningFromWordpressConnection,
|
|
|
|
sendMagicLinkHandler,
|
|
|
|
isRetryingMagicLinkSend,
|
|
|
|
} ) => {
|
|
|
|
const { state: jetpackPluginState } = useJetpackPluginState();
|
|
|
|
const jetpackPluginStateRef =
|
|
|
|
useRef< JetpackPluginStates >( jetpackPluginState );
|
|
|
|
|
|
|
|
useEffect( () => {
|
|
|
|
if (
|
|
|
|
// capture the jp state at the moment it has finished initializing, and not on subsequent changes
|
|
|
|
jetpackPluginStateRef.current ===
|
|
|
|
JetpackPluginStates.INITIALIZING &&
|
|
|
|
jetpackPluginState !== JetpackPluginStates.INITIALIZING
|
|
|
|
) {
|
|
|
|
jetpackPluginStateRef.current = jetpackPluginState;
|
|
|
|
if ( isReturningFromWordpressConnection ) {
|
|
|
|
recordEvent( 'magic_prompt_return_from_wp_connection' );
|
|
|
|
} else if ( ! isRetryingMagicLinkSend ) {
|
|
|
|
recordEvent( 'magic_prompt_view', {
|
|
|
|
jetpack_state: jetpackPluginStateRef.current,
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, [
|
|
|
|
isReturningFromWordpressConnection,
|
|
|
|
jetpackPluginState,
|
|
|
|
isRetryingMagicLinkSend,
|
|
|
|
] );
|
|
|
|
|
2022-09-15 03:58:47 +00:00
|
|
|
return (
|
|
|
|
<ModalContentLayoutWithTitle>
|
|
|
|
<div className="modal-subheader">
|
|
|
|
<h3>
|
|
|
|
{ __(
|
|
|
|
'Run your store from anywhere in two easy steps.',
|
|
|
|
'woocommerce'
|
|
|
|
) }
|
|
|
|
</h3>
|
|
|
|
</div>
|
|
|
|
<JetpackInstallationStepper
|
|
|
|
step={ isReturningFromWordpressConnection ? 'second' : 'first' }
|
|
|
|
sendMagicLinkHandler={ sendMagicLinkHandler }
|
|
|
|
/>
|
|
|
|
</ModalContentLayoutWithTitle>
|
|
|
|
);
|
|
|
|
};
|