2020-05-12 23:14:08 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2020-11-11 17:20:15 +00:00
|
|
|
import {
|
|
|
|
Suspense,
|
|
|
|
lazy,
|
|
|
|
useCallback,
|
|
|
|
useLayoutEffect,
|
|
|
|
useRef,
|
|
|
|
useState,
|
|
|
|
} from '@wordpress/element';
|
2020-05-21 17:15:08 +00:00
|
|
|
import { compose } from '@wordpress/compose';
|
2020-09-03 21:45:40 +00:00
|
|
|
import { withDispatch, withSelect } from '@wordpress/data';
|
2020-05-12 23:14:08 +00:00
|
|
|
import classnames from 'classnames';
|
2020-05-21 17:15:08 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2020-10-22 22:13:14 +00:00
|
|
|
import {
|
|
|
|
useUserPreferences,
|
|
|
|
NOTES_STORE_NAME,
|
2021-11-15 20:57:13 +00:00
|
|
|
ONBOARDING_STORE_NAME,
|
2020-10-22 22:13:14 +00:00
|
|
|
OPTIONS_STORE_NAME,
|
|
|
|
} from '@woocommerce/data';
|
2020-11-06 17:53:03 +00:00
|
|
|
import { __ } from '@wordpress/i18n';
|
2020-06-10 23:49:27 +00:00
|
|
|
|
2020-05-12 23:14:08 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2021-12-14 16:56:42 +00:00
|
|
|
import ActivityHeader from '~/activity-panel/activity-header';
|
2021-02-22 18:40:44 +00:00
|
|
|
import { ActivityPanel } from './activity-panel';
|
|
|
|
import { Column } from './column';
|
|
|
|
import InboxPanel from '../inbox-panel';
|
|
|
|
import { IntroModal as NavigationIntroModal } from '../navigation/components/intro-modal';
|
2020-05-12 23:14:08 +00:00
|
|
|
import StatsOverview from './stats-overview';
|
2021-02-22 18:40:44 +00:00
|
|
|
import { StoreManagementLinks } from '../store-management-links';
|
2021-08-23 14:29:20 +00:00
|
|
|
import { TasksPlaceholder } from '../tasks';
|
2021-02-22 18:40:44 +00:00
|
|
|
import {
|
|
|
|
WELCOME_MODAL_DISMISSED_OPTION_NAME,
|
|
|
|
WELCOME_FROM_CALYPSO_MODAL_DISMISSED_OPTION_NAME,
|
2022-02-07 00:50:20 +00:00
|
|
|
WOOCOMMERCE_ADMIN_INSTALL_TIMESTAMP_OPTION_NAME,
|
2021-02-22 18:40:44 +00:00
|
|
|
} from './constants';
|
2021-01-08 02:06:52 +00:00
|
|
|
import { WelcomeFromCalypsoModal } from './welcome-from-calypso-modal';
|
2021-02-22 18:40:44 +00:00
|
|
|
import { WelcomeModal } from './welcome-modal';
|
2022-02-07 00:50:20 +00:00
|
|
|
import { useHeadercardExperimentHook } from './hooks/use-headercard-experiment-hook';
|
2020-11-04 00:33:04 +00:00
|
|
|
import './style.scss';
|
|
|
|
import '../dashboard/style.scss';
|
2022-04-04 18:38:27 +00:00
|
|
|
import { getAdminSetting } from '~/utils/admin-settings';
|
2020-11-04 00:33:04 +00:00
|
|
|
|
2021-08-23 14:29:20 +00:00
|
|
|
const Tasks = lazy( () =>
|
|
|
|
import( /* webpackChunkName: "tasks" */ '../tasks' )
|
|
|
|
);
|
|
|
|
|
2021-10-20 16:16:22 +00:00
|
|
|
const TwoColumnTasks = lazy( () =>
|
|
|
|
import( /* webpackChunkName: "two-column-tasks" */ '../two-column-tasks' )
|
|
|
|
);
|
|
|
|
|
2021-10-26 04:08:05 +00:00
|
|
|
const TwoColumnTasksExtended = lazy( () =>
|
|
|
|
import(
|
|
|
|
/* webpackChunkName: "two-column-tasks-extended" */ '../two-column-tasks/extended-task'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2020-08-05 00:14:56 +00:00
|
|
|
export const Layout = ( {
|
2020-11-06 17:53:03 +00:00
|
|
|
defaultHomescreenLayout,
|
2020-08-13 13:23:38 +00:00
|
|
|
isBatchUpdating,
|
2020-08-05 00:14:56 +00:00
|
|
|
query,
|
2021-03-25 21:54:24 +00:00
|
|
|
taskListComplete,
|
2021-11-15 20:57:13 +00:00
|
|
|
hasTaskList,
|
2020-08-05 00:14:56 +00:00
|
|
|
shouldShowWelcomeModal,
|
2021-01-08 02:06:52 +00:00
|
|
|
shouldShowWelcomeFromCalypsoModal,
|
2021-03-25 21:54:24 +00:00
|
|
|
isTaskListHidden,
|
2020-08-05 00:14:56 +00:00
|
|
|
updateOptions,
|
2022-02-07 00:50:20 +00:00
|
|
|
installTimestamp,
|
|
|
|
installTimestampHasResolved,
|
2020-08-05 00:14:56 +00:00
|
|
|
} ) => {
|
2020-10-22 22:13:14 +00:00
|
|
|
const userPrefs = useUserPreferences();
|
2021-06-30 23:16:11 +00:00
|
|
|
const shouldShowStoreLinks = taskListComplete || isTaskListHidden;
|
|
|
|
const hasTwoColumnContent =
|
|
|
|
shouldShowStoreLinks || window.wcAdminFeatures.analytics;
|
2020-05-12 23:14:08 +00:00
|
|
|
const [ showInbox, setShowInbox ] = useState( true );
|
2021-01-08 03:24:23 +00:00
|
|
|
const isDashboardShown = ! query.task;
|
2022-02-07 00:50:20 +00:00
|
|
|
const {
|
2021-10-20 16:16:22 +00:00
|
|
|
isLoadingExperimentAssignment,
|
2021-11-02 22:36:12 +00:00
|
|
|
isLoadingTwoColExperimentAssignment,
|
2022-02-07 00:50:20 +00:00
|
|
|
experimentAssignment,
|
2021-11-02 22:36:12 +00:00
|
|
|
twoColExperimentAssignment,
|
2022-02-07 00:50:20 +00:00
|
|
|
} = useHeadercardExperimentHook(
|
|
|
|
installTimestampHasResolved,
|
|
|
|
installTimestamp
|
2021-11-02 22:36:12 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
const isRunningTwoColumnExperiment =
|
|
|
|
twoColExperimentAssignment?.variationName === 'treatment';
|
|
|
|
|
2021-11-12 10:32:27 +00:00
|
|
|
// New TaskList UI is enabled when either experiment is treatment.
|
|
|
|
const isRunningTaskListExperiment =
|
|
|
|
experimentAssignment?.variationName === 'treatment' ||
|
|
|
|
isRunningTwoColumnExperiment;
|
|
|
|
|
2021-11-02 22:36:12 +00:00
|
|
|
// Override defaultHomescreenLayout if store is in the experiment.
|
|
|
|
const defaultHomescreenLayoutOverride = () => {
|
|
|
|
if (
|
|
|
|
isLoadingExperimentAssignment ||
|
|
|
|
isLoadingTwoColExperimentAssignment
|
|
|
|
) {
|
2021-11-12 10:32:27 +00:00
|
|
|
return defaultHomescreenLayout; // Experiments are still loading, don't override.
|
2021-11-02 22:36:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! isRunningTaskListExperiment ) {
|
|
|
|
return defaultHomescreenLayout; // Not in the experiment, don't override.
|
|
|
|
}
|
|
|
|
|
|
|
|
return isRunningTwoColumnExperiment ? 'two_columns' : 'single_column';
|
|
|
|
};
|
|
|
|
|
|
|
|
const twoColumns =
|
|
|
|
( userPrefs.homepage_layout || defaultHomescreenLayoutOverride() ) ===
|
|
|
|
'two_columns' && hasTwoColumnContent;
|
|
|
|
|
2020-08-13 13:23:38 +00:00
|
|
|
if ( isBatchUpdating && ! showInbox ) {
|
2020-06-05 16:28:25 +00:00
|
|
|
setShowInbox( true );
|
|
|
|
}
|
|
|
|
|
2020-11-11 17:20:15 +00:00
|
|
|
const isWideViewport = useRef( true );
|
|
|
|
const maybeToggleColumns = useCallback( () => {
|
|
|
|
isWideViewport.current = window.innerWidth >= 782;
|
|
|
|
}, [] );
|
|
|
|
|
|
|
|
useLayoutEffect( () => {
|
|
|
|
maybeToggleColumns();
|
|
|
|
window.addEventListener( 'resize', maybeToggleColumns );
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
window.removeEventListener( 'resize', maybeToggleColumns );
|
|
|
|
};
|
|
|
|
}, [ maybeToggleColumns ] );
|
|
|
|
|
|
|
|
const shouldStickColumns = isWideViewport.current && twoColumns;
|
|
|
|
|
2020-05-21 17:15:08 +00:00
|
|
|
const renderColumns = () => {
|
|
|
|
return (
|
2020-11-06 17:53:03 +00:00
|
|
|
<>
|
2020-11-11 17:20:15 +00:00
|
|
|
<Column shouldStick={ shouldStickColumns }>
|
2022-02-07 00:50:20 +00:00
|
|
|
{ ! isLoadingExperimentAssignment &&
|
|
|
|
! isLoadingTwoColExperimentAssignment &&
|
|
|
|
! isRunningTaskListExperiment && (
|
|
|
|
<ActivityHeader
|
|
|
|
className="your-store-today"
|
|
|
|
title={ __(
|
|
|
|
'Your store today',
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2022-02-07 00:50:20 +00:00
|
|
|
) }
|
|
|
|
subtitle={ __(
|
|
|
|
"To do's, tips, and insights for your business",
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2022-02-07 00:50:20 +00:00
|
|
|
) }
|
|
|
|
/>
|
|
|
|
) }
|
2022-01-05 02:23:34 +00:00
|
|
|
{ <ActivityPanel /> }
|
2021-11-15 20:57:13 +00:00
|
|
|
{ hasTaskList && renderTaskList() }
|
2021-01-28 13:33:36 +00:00
|
|
|
<InboxPanel />
|
2020-11-06 17:53:03 +00:00
|
|
|
</Column>
|
2020-11-11 17:20:15 +00:00
|
|
|
<Column shouldStick={ shouldStickColumns }>
|
2021-06-30 23:16:11 +00:00
|
|
|
{ window.wcAdminFeatures.analytics && <StatsOverview /> }
|
2021-03-25 21:54:24 +00:00
|
|
|
{ shouldShowStoreLinks && <StoreManagementLinks /> }
|
2020-11-06 17:53:03 +00:00
|
|
|
</Column>
|
|
|
|
</>
|
2020-05-21 17:15:08 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const renderTaskList = () => {
|
2021-11-02 22:36:12 +00:00
|
|
|
if ( twoColumns && isRunningTaskListExperiment ) {
|
2021-10-26 04:08:05 +00:00
|
|
|
return (
|
|
|
|
// When running the two-column experiment, we still need to render
|
|
|
|
// the component in the left column for the extended task list.
|
2022-02-07 00:50:20 +00:00
|
|
|
<Suspense fallback={ null }>
|
|
|
|
<TwoColumnTasksExtended query={ query } />
|
|
|
|
</Suspense>
|
2021-10-26 04:08:05 +00:00
|
|
|
);
|
2021-10-20 16:16:22 +00:00
|
|
|
} else if (
|
|
|
|
! twoColumns &&
|
2021-11-02 22:36:12 +00:00
|
|
|
isRunningTaskListExperiment &&
|
2021-10-20 16:16:22 +00:00
|
|
|
! isLoadingExperimentAssignment
|
|
|
|
) {
|
|
|
|
return (
|
2022-02-07 00:50:20 +00:00
|
|
|
<Suspense fallback={ null }>
|
|
|
|
<>
|
|
|
|
<TwoColumnTasks
|
|
|
|
query={ query }
|
|
|
|
userPreferences={ userPrefs }
|
|
|
|
twoColumns={ twoColumns }
|
|
|
|
/>
|
|
|
|
<TwoColumnTasksExtended query={ query } />
|
|
|
|
</>
|
|
|
|
</Suspense>
|
2021-10-20 16:16:22 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-05-21 17:15:08 +00:00
|
|
|
return (
|
2021-10-05 18:20:28 +00:00
|
|
|
<Suspense fallback={ <TasksPlaceholder query={ query } /> }>
|
|
|
|
<Tasks query={ query } />
|
2020-05-21 17:15:08 +00:00
|
|
|
</Suspense>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-05-12 23:14:08 +00:00
|
|
|
return (
|
2021-10-20 16:16:22 +00:00
|
|
|
<>
|
2021-11-02 22:36:12 +00:00
|
|
|
{ twoColumns && isRunningTaskListExperiment && (
|
2022-02-07 00:50:20 +00:00
|
|
|
<Suspense fallback={ null }>
|
|
|
|
<TwoColumnTasks
|
|
|
|
query={ query }
|
|
|
|
userPreferences={ userPrefs }
|
|
|
|
twoColumns={ twoColumns }
|
|
|
|
/>
|
|
|
|
</Suspense>
|
2021-01-08 02:06:52 +00:00
|
|
|
) }
|
2021-10-20 16:16:22 +00:00
|
|
|
<div
|
|
|
|
className={ classnames( 'woocommerce-homescreen', {
|
|
|
|
'two-columns': twoColumns,
|
|
|
|
} ) }
|
|
|
|
>
|
|
|
|
{ isDashboardShown ? renderColumns() : renderTaskList() }
|
|
|
|
{ shouldShowWelcomeModal && (
|
|
|
|
<WelcomeModal
|
|
|
|
onClose={ () => {
|
|
|
|
updateOptions( {
|
|
|
|
[ WELCOME_MODAL_DISMISSED_OPTION_NAME ]: 'yes',
|
|
|
|
} );
|
|
|
|
} }
|
|
|
|
/>
|
|
|
|
) }
|
|
|
|
{ shouldShowWelcomeFromCalypsoModal && (
|
|
|
|
<WelcomeFromCalypsoModal
|
|
|
|
onClose={ () => {
|
|
|
|
updateOptions( {
|
|
|
|
[ WELCOME_FROM_CALYPSO_MODAL_DISMISSED_OPTION_NAME ]:
|
|
|
|
'yes',
|
|
|
|
} );
|
|
|
|
} }
|
|
|
|
/>
|
|
|
|
) }
|
|
|
|
{ window.wcAdminFeatures.navigation && (
|
|
|
|
<NavigationIntroModal />
|
|
|
|
) }
|
|
|
|
</div>
|
|
|
|
</>
|
2020-05-12 23:14:08 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-05-21 17:15:08 +00:00
|
|
|
Layout.propTypes = {
|
2020-05-27 16:08:39 +00:00
|
|
|
/**
|
|
|
|
* If the task list has been completed.
|
|
|
|
*/
|
|
|
|
taskListComplete: PropTypes.bool,
|
2020-05-21 17:15:08 +00:00
|
|
|
/**
|
2021-11-15 20:57:13 +00:00
|
|
|
* If any task list is visible.
|
2020-05-21 17:15:08 +00:00
|
|
|
*/
|
2021-11-15 20:57:13 +00:00
|
|
|
hasTaskList: PropTypes.bool,
|
2020-05-21 17:15:08 +00:00
|
|
|
/**
|
|
|
|
* Page query, used to determine the current task if any.
|
|
|
|
*/
|
|
|
|
query: PropTypes.object.isRequired,
|
2020-08-05 00:14:56 +00:00
|
|
|
/**
|
|
|
|
* If the welcome modal should display
|
|
|
|
*/
|
|
|
|
shouldShowWelcomeModal: PropTypes.bool,
|
2021-01-08 02:06:52 +00:00
|
|
|
/**
|
|
|
|
* If the welcome from Calypso modal should display.
|
|
|
|
*/
|
|
|
|
shouldShowWelcomeFromCalypsoModal: PropTypes.bool,
|
2022-02-07 00:50:20 +00:00
|
|
|
/**
|
|
|
|
* Timestamp of WooCommerce Admin installation.
|
|
|
|
*/
|
|
|
|
installTimestamp: PropTypes.string,
|
|
|
|
/**
|
|
|
|
* Resolution of WooCommerce Admin installation timetsamp.
|
|
|
|
*/
|
|
|
|
installTimestampHasResolved: PropTypes.bool,
|
2020-08-05 00:14:56 +00:00
|
|
|
/**
|
|
|
|
* Dispatch an action to update an option
|
|
|
|
*/
|
|
|
|
updateOptions: PropTypes.func.isRequired,
|
2020-05-21 17:15:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default compose(
|
2020-09-03 21:45:40 +00:00
|
|
|
withSelect( ( select ) => {
|
2020-08-13 13:23:38 +00:00
|
|
|
const { isNotesRequesting } = select( NOTES_STORE_NAME );
|
2021-08-10 18:58:01 +00:00
|
|
|
const { getOption, hasFinishedResolution } = select(
|
2020-11-11 00:23:33 +00:00
|
|
|
OPTIONS_STORE_NAME
|
|
|
|
);
|
2021-11-15 20:57:13 +00:00
|
|
|
const { getTaskList, getTaskLists } = select( ONBOARDING_STORE_NAME );
|
|
|
|
const taskLists = getTaskLists();
|
2020-05-21 17:15:08 +00:00
|
|
|
|
2021-01-08 02:06:52 +00:00
|
|
|
const welcomeFromCalypsoModalDismissed =
|
2022-03-23 12:08:58 +00:00
|
|
|
getOption( WELCOME_FROM_CALYPSO_MODAL_DISMISSED_OPTION_NAME ) !==
|
|
|
|
'no';
|
2021-01-08 02:06:52 +00:00
|
|
|
const welcomeFromCalypsoModalDismissedResolved = hasFinishedResolution(
|
|
|
|
'getOption',
|
|
|
|
[ WELCOME_FROM_CALYPSO_MODAL_DISMISSED_OPTION_NAME ]
|
|
|
|
);
|
|
|
|
const fromCalypsoUrlArgIsPresent = !! window.location.search.match(
|
|
|
|
'from-calypso'
|
|
|
|
);
|
|
|
|
|
|
|
|
const shouldShowWelcomeFromCalypsoModal =
|
|
|
|
welcomeFromCalypsoModalDismissedResolved &&
|
|
|
|
! welcomeFromCalypsoModalDismissed &&
|
|
|
|
fromCalypsoUrlArgIsPresent;
|
|
|
|
|
2020-08-05 00:14:56 +00:00
|
|
|
const welcomeModalDismissed =
|
2022-03-23 12:08:58 +00:00
|
|
|
getOption( WELCOME_MODAL_DISMISSED_OPTION_NAME ) !== 'no';
|
2020-08-05 00:14:56 +00:00
|
|
|
|
2022-02-07 00:50:20 +00:00
|
|
|
const installTimestamp = getOption(
|
|
|
|
WOOCOMMERCE_ADMIN_INSTALL_TIMESTAMP_OPTION_NAME
|
|
|
|
);
|
|
|
|
|
2020-11-11 00:23:33 +00:00
|
|
|
const welcomeModalDismissedHasResolved = hasFinishedResolution(
|
|
|
|
'getOption',
|
2021-02-22 18:40:44 +00:00
|
|
|
[ WELCOME_MODAL_DISMISSED_OPTION_NAME ]
|
2020-11-11 00:23:33 +00:00
|
|
|
);
|
2020-08-05 00:14:56 +00:00
|
|
|
|
2022-02-07 00:50:20 +00:00
|
|
|
const installTimestampHasResolved = hasFinishedResolution(
|
|
|
|
'getOption',
|
|
|
|
[ WOOCOMMERCE_ADMIN_INSTALL_TIMESTAMP_OPTION_NAME ]
|
|
|
|
);
|
|
|
|
|
2020-08-05 00:14:56 +00:00
|
|
|
const shouldShowWelcomeModal =
|
2021-01-08 02:06:52 +00:00
|
|
|
welcomeModalDismissedHasResolved &&
|
|
|
|
! welcomeModalDismissed &&
|
|
|
|
welcomeFromCalypsoModalDismissedResolved &&
|
|
|
|
! welcomeFromCalypsoModalDismissed;
|
2020-08-05 00:14:56 +00:00
|
|
|
|
2020-11-06 17:53:03 +00:00
|
|
|
const defaultHomescreenLayout =
|
|
|
|
getOption( 'woocommerce_default_homepage_layout' ) ||
|
|
|
|
'single_column';
|
|
|
|
|
2020-05-21 17:15:08 +00:00
|
|
|
return {
|
2020-11-06 17:53:03 +00:00
|
|
|
defaultHomescreenLayout,
|
2020-08-24 21:51:41 +00:00
|
|
|
isBatchUpdating: isNotesRequesting( 'batchUpdateNotes' ),
|
2020-08-05 00:14:56 +00:00
|
|
|
shouldShowWelcomeModal,
|
2021-01-08 02:06:52 +00:00
|
|
|
shouldShowWelcomeFromCalypsoModal,
|
2021-11-15 20:57:13 +00:00
|
|
|
isTaskListHidden: getTaskList( 'setup' )?.isHidden,
|
2022-04-04 18:38:27 +00:00
|
|
|
hasTaskList: getAdminSetting( 'visibleTaskListIds', [] ).length > 0,
|
2021-11-15 20:57:13 +00:00
|
|
|
taskListComplete: getTaskList( 'setup' )?.isComplete,
|
2022-02-07 00:50:20 +00:00
|
|
|
installTimestamp,
|
|
|
|
installTimestampHasResolved,
|
2020-05-21 17:15:08 +00:00
|
|
|
};
|
2020-08-05 00:14:56 +00:00
|
|
|
} ),
|
|
|
|
withDispatch( ( dispatch ) => ( {
|
|
|
|
updateOptions: dispatch( OPTIONS_STORE_NAME ).updateOptions,
|
|
|
|
} ) )
|
2020-05-21 17:15:08 +00:00
|
|
|
)( Layout );
|