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';
|
2022-06-01 17:10:20 +00:00
|
|
|
import { TasksPlaceholder, useActiveSetupTasklist } from '../tasks';
|
2021-02-22 18:40:44 +00:00
|
|
|
import {
|
|
|
|
WELCOME_MODAL_DISMISSED_OPTION_NAME,
|
|
|
|
WELCOME_FROM_CALYPSO_MODAL_DISMISSED_OPTION_NAME,
|
|
|
|
} 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';
|
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';
|
2022-06-01 17:10:20 +00:00
|
|
|
import { ProgressTitle } from '../task-lists';
|
2020-11-04 00:33:04 +00:00
|
|
|
|
2021-08-23 14:29:20 +00:00
|
|
|
const Tasks = lazy( () =>
|
2022-06-14 18:31:50 +00:00
|
|
|
import( /* webpackChunkName: "tasks" */ '../tasks' ).then( ( module ) => ( {
|
|
|
|
default: module.Tasks,
|
|
|
|
} ) )
|
2021-08-23 14:29:20 +00:00
|
|
|
);
|
|
|
|
|
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,
|
2022-04-06 17:02:02 +00:00
|
|
|
showingProgressHeader,
|
|
|
|
isLoadingTaskLists,
|
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,
|
|
|
|
} ) => {
|
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 );
|
2022-08-04 08:57:53 +00:00
|
|
|
const isDashboardShown = ! query.task; // ?&task=<x> query param is used to show tasks instead of the homescreen
|
2022-06-01 17:10:20 +00:00
|
|
|
const activeSetupTaskList = useActiveSetupTasklist();
|
2022-05-09 17:01:11 +00:00
|
|
|
|
2021-11-02 22:36:12 +00:00
|
|
|
const twoColumns =
|
2022-06-16 20:51:46 +00:00
|
|
|
( userPrefs.homepage_layout || defaultHomescreenLayout ) ===
|
2021-11-02 22:36:12 +00:00
|
|
|
'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-06-16 20:51:46 +00:00
|
|
|
{ ! isLoadingTaskLists && ! showingProgressHeader && (
|
|
|
|
<ActivityHeader
|
|
|
|
className="your-store-today"
|
|
|
|
title={ __( 'Your store today', 'woocommerce' ) }
|
|
|
|
subtitle={ __(
|
|
|
|
"To do's, tips, and insights for your business",
|
|
|
|
'woocommerce'
|
|
|
|
) }
|
|
|
|
/>
|
|
|
|
) }
|
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 = () => {
|
|
|
|
return (
|
2021-10-05 18:20:28 +00:00
|
|
|
<Suspense fallback={ <TasksPlaceholder query={ query } /> }>
|
2022-07-28 16:16:10 +00:00
|
|
|
{ activeSetupTaskList && isDashboardShown && (
|
|
|
|
<ProgressTitle taskListId={ activeSetupTaskList } />
|
|
|
|
) }
|
2021-10-05 18:20:28 +00:00
|
|
|
<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
|
|
|
<>
|
|
|
|
<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 );
|
2022-06-21 08:37:34 +00:00
|
|
|
const { getOption, hasFinishedResolution } =
|
|
|
|
select( OPTIONS_STORE_NAME );
|
2022-04-06 17:02:02 +00:00
|
|
|
const {
|
|
|
|
getTaskList,
|
|
|
|
getTaskLists,
|
|
|
|
hasFinishedResolution: taskListFinishResolution,
|
|
|
|
} = select( ONBOARDING_STORE_NAME );
|
|
|
|
const taskLists = getTaskLists();
|
|
|
|
const isLoadingTaskLists = ! taskListFinishResolution( '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 ]
|
|
|
|
);
|
2022-06-21 08:37:34 +00:00
|
|
|
const fromCalypsoUrlArgIsPresent =
|
|
|
|
!! window.location.search.match( 'from-calypso' );
|
2021-01-08 02:06:52 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
|
|
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,
|
2022-04-06 17:02:02 +00:00
|
|
|
isLoadingTaskLists,
|
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,
|
2022-04-06 17:02:02 +00:00
|
|
|
showingProgressHeader: !! taskLists.find(
|
|
|
|
( list ) => list.isVisible && list.displayProgressHeader
|
|
|
|
),
|
2021-11-15 20:57:13 +00:00
|
|
|
taskListComplete: getTaskList( 'setup' )?.isComplete,
|
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 );
|