Skip to content

Commit

Permalink
Add a catch-all return to LYS hub after user exits essential task (#4…
Browse files Browse the repository at this point in the history
…7606)

* Add redirect to LYS on homescreen when lysTaskOpen is present

* Typos

* Fix lint issues

* Fix lint issues

* Add changelog

* Fix lint issues

* Fix lint issues

* Use isDashboardShown in effect

This required adding a check to ensure query is not an empty object

* Imporve the jankiness by moving catch-all logic to layout

* use an effect to set the session value to no

* lint

* lint

* Fix tests

* Try preventing redirects from WP menu click

* Revert "Try preventing redirects from WP menu click"

This reverts commit 8ef6dcf.
  • Loading branch information
adrianduffell committed May 22, 2024
1 parent 6c136e4 commit 501272c
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 8 deletions.
2 changes: 1 addition & 1 deletion plugins/woocommerce-admin/client/homescreen/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const Layout = ( {
const shouldShowWCPayFeature = taskListComplete || isTaskListHidden;
const hasTwoColumnContent =
shouldShowStoreLinks || window.wcAdminFeatures.analytics;
const isDashboardShown = ! query.task; // ?&task=<x> query param is used to show tasks instead of the homescreen
const isDashboardShown = Object.keys( query ).length > 0 && ! query.task; // ?&task=<x> query param is used to show tasks instead of the homescreen
const activeSetupTaskList = useActiveSetupTasklist();

const twoColumns =
Expand Down
10 changes: 5 additions & 5 deletions plugins/woocommerce-admin/client/homescreen/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe( 'Homescreen Layout', () => {
requestingTaskList={ false }
taskListComplete
hasTaskList={ true }
query={ {} }
query={ { page: 'wc-admin' } }
updateOptions={ () => {} }
/>
);
Expand Down Expand Up @@ -92,7 +92,7 @@ describe( 'Homescreen Layout', () => {
<Layout
requestingTaskList={ false }
hasTaskList={ false }
query={ {} }
query={ { page: 'wc-admin' } }
updateOptions={ () => {} }
/>
);
Expand All @@ -107,7 +107,7 @@ describe( 'Homescreen Layout', () => {
requestingTaskList={ false }
hasTaskList={ true }
taskListComplete
query={ {} }
query={ { page: 'wc-admin' } }
updateOptions={ () => {} }
/>
);
Expand Down Expand Up @@ -195,7 +195,7 @@ describe( 'Homescreen Layout', () => {
requestingTaskList={ false }
taskListComplete
hasTaskList={ true }
query={ {} }
query={ { page: 'wc-admin' } }
updateOptions={ () => {} }
/>
);
Expand Down Expand Up @@ -238,7 +238,7 @@ describe( 'Homescreen Layout', () => {
taskListComplete
hasTaskList={ true }
isTaskListHidden={ true }
query={ {} }
query={ { page: 'wc-admin' } }
updateOptions={ () => {} }
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* External dependencies
*/
import { useMachine } from '@xstate5/react';
import React from 'react';
import React, { useEffect } from 'react';
import classnames from 'classnames';

/**
Expand Down Expand Up @@ -34,6 +34,9 @@ export type LaunchYourStoreComponentProps = {

const LaunchStoreController = () => {
useFullScreen( [ 'woocommerce-launch-your-store' ] );
useEffect( () => {
window.sessionStorage.setItem( 'lysWaiting', 'no' );
}, [] );
const { xstateV5Inspector: inspect } = useXStateInspect( 'V5' );

const [ mainContentState, sendToMainContent, mainContentMachineService ] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export function taskClickedAction( event: {
} ) {
const recentlyActionedTasks = getRecentlyActionedTasks() ?? [];
saveRecentlyActionedTask( [ ...recentlyActionedTasks, event.task.id ] );
window.sessionStorage.setItem( 'lysWaiting', 'yes' );

const { setWithExpiry: saveTaskReferral } = accessTaskReferralStorage(
{ taskId: event.task.id, referralLifetime: 60 * 60 * 24 } // 24 hours
Expand Down
20 changes: 19 additions & 1 deletion plugins/woocommerce-admin/client/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ import {
CustomerEffortScoreModalContainer,
triggerExitPageCesSurvey,
} from '@woocommerce/customer-effort-score';
import { getHistory, getQuery } from '@woocommerce/navigation';
import {
getHistory,
getQuery,
getNewPath,
navigateTo,
} from '@woocommerce/navigation';
import {
PLUGINS_STORE_NAME,
useUser,
Expand Down Expand Up @@ -192,6 +197,19 @@ function _Layout( {
}
}, [ showHeader ] );

const isDashboardShown =
query.page && query.page === 'wc-admin' && ! query.path && ! query.task; // ?&task=<x> query param is used to show tasks instead of the homescreen
useEffect( () => {
// Catch-all to redirect to LYS hub when it was previously opened.
const isLYSWaiting =
window.sessionStorage.getItem( 'lysWaiting' ) === 'yes';
if ( isDashboardShown && isLYSWaiting ) {
navigateTo( {
url: getNewPath( {}, '/launch-your-store' ),
} );
}
}, [ isDashboardShown ] );

return (
<LayoutContextProvider
value={ getLayoutContextValue( [
Expand Down
4 changes: 4 additions & 0 deletions plugins/woocommerce/changelog/try-lys-return-catch-all
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: update

Return users to LYS after completing essential task

0 comments on commit 501272c

Please sign in to comment.