Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LaunchpadSaveModal: Update action href based on experiment variation #39237

Merged
merged 15 commits into from
Sep 13, 2024
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: other

LaunchpadSaveModal: support launchpad experiment
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getRedirectUrl } from '@automattic/jetpack-components';
import { loadExperimentAssignment } from '@automattic/jetpack-explat';
import { getSiteFragment, useAnalytics } from '@automattic/jetpack-shared-extension-utils';
import apiFetch from '@wordpress/api-fetch';
import { Modal, Button, CheckboxControl } from '@wordpress/components';
Expand Down Expand Up @@ -40,6 +41,11 @@ const updateLaunchpadSaveModalBrowserConfig = config => {

export const settings = {
render: function LaunchpadSaveModal() {
const [ experimentVariationName, setExperimentVariationName ] = useState();
const sessionVariationName = window.sessionStorage.getItem(
bogiii marked this conversation as resolved.
Show resolved Hide resolved
'launchpad_removal_2024_experiment_variation'
);

const { isSavingSite, isSavingPost, isCurrentPostPublished, postLink, postType } = useSelect(
select => {
const { __experimentalGetDirtyEntityRecords, isSavingEntityRecord } = select( coreStore );
Expand All @@ -59,6 +65,17 @@ export const settings = {
}
);

// Fetch the experiment data once when the component mounts
useEffect( () => {
loadExperimentAssignment( 'calypso_onboarding_launchpad_removal_test_2024_08' ).then(
experiment => {
sessionVariationName
? setExperimentVariationName( sessionVariationName )
: setExperimentVariationName( experiment.variationName );
}
);
}, [ sessionVariationName ] );

const prevIsSavingSite = usePrevious( isSavingSite );
const prevIsSavingPost = usePrevious( isSavingPost );

Expand Down Expand Up @@ -87,6 +104,11 @@ export const settings = {
path: siteIntentOption,
query: `siteSlug=${ siteFragment }`,
} );
const calypsoHomeUrl = getRedirectUrl( 'calypso-home', {
site: siteFragment,
} );
const primaryActionHref =
experimentVariationName === 'treatment' ? calypsoHomeUrl : launchPadUrl;
const { tracks } = useAnalytics();

const recordTracksEvent = eventName =>
Expand All @@ -104,7 +126,7 @@ export const settings = {
'You are one step away from bringing your site to life. Check out the next steps that will help you to launch your site.',
'jetpack'
),
actionButtonHref: launchPadUrl,
actionButtonHref: primaryActionHref,
actionButtonTracksEvent: 'jetpack_launchpad_save_modal_next_steps',
actionButtonText: __( 'Next Steps', 'jetpack' ),
};
Expand Down
1 change: 1 addition & 0 deletions projects/plugins/jetpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"@automattic/jetpack-boost-score-api": "workspace:*",
"@automattic/jetpack-components": "workspace:*",
"@automattic/jetpack-connection": "workspace:*",
"@automattic/jetpack-explat": "workspace:*",
"@automattic/jetpack-licensing": "workspace:*",
"@automattic/jetpack-my-jetpack": "workspace:*",
"@automattic/jetpack-partner-coupon": "workspace:*",
Expand Down
7 changes: 7 additions & 0 deletions tools/js-tools/types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ declare module '*.module.scss' {
export default classes;
}

// Add the process declaration
declare const process: {
env: {
NODE_ENV: 'development' | 'production' | 'test';
};
};

type AvailableBlockProps =
| {
available?: boolean;
Expand Down
Loading