2020-05-12 23:14:08 +00:00
|
|
|
|
/**
|
|
|
|
|
* External dependencies
|
|
|
|
|
*/
|
2020-11-11 17:20:15 +00:00
|
|
|
|
import {
|
|
|
|
|
Suspense,
|
|
|
|
|
lazy,
|
|
|
|
|
useCallback,
|
|
|
|
|
useLayoutEffect,
|
|
|
|
|
useRef,
|
|
|
|
|
} from '@wordpress/element';
|
2020-05-21 17:15:08 +00:00
|
|
|
|
import { compose } from '@wordpress/compose';
|
2024-06-13 02:39:21 +00:00
|
|
|
|
import { withSelect } from '@wordpress/data';
|
2024-05-31 03:49:36 +00:00
|
|
|
|
import clsx from 'clsx';
|
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';
|
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';
|
2023-05-17 01:54:31 +00:00
|
|
|
|
import {
|
|
|
|
|
TasksPlaceholder,
|
|
|
|
|
useActiveSetupTasklist,
|
|
|
|
|
ProgressTitle,
|
|
|
|
|
} from '../task-lists';
|
2022-09-15 03:58:47 +00:00
|
|
|
|
import { MobileAppModal } from './mobile-app-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';
|
2023-01-20 14:01:20 +00:00
|
|
|
|
import { WooHomescreenHeaderBanner } from './header-banner-slot';
|
2023-04-17 21:07:25 +00:00
|
|
|
|
import { WooHomescreenWCPayFeature } from './wcpay-feature-slot';
|
2020-11-04 00:33:04 +00:00
|
|
|
|
|
2023-05-17 01:54:31 +00:00
|
|
|
|
const TaskLists = lazy( () =>
|
|
|
|
|
import( /* webpackChunkName: "tasks" */ '../task-lists' ).then(
|
|
|
|
|
( module ) => ( {
|
|
|
|
|
default: module.TaskLists,
|
|
|
|
|
} )
|
|
|
|
|
)
|
2021-08-23 14:29:20 +00:00
|
|
|
|
);
|
|
|
|
|
|
2024-06-27 20:37:25 +00:00
|
|
|
|
export const hasTwoColumnLayout = (
|
|
|
|
|
userPrefLayout,
|
|
|
|
|
defaultHomescreenLayout,
|
|
|
|
|
taskListComplete,
|
|
|
|
|
isTaskListHidden
|
|
|
|
|
) => {
|
|
|
|
|
const hasTwoColumnContent =
|
|
|
|
|
taskListComplete ||
|
|
|
|
|
isTaskListHidden ||
|
|
|
|
|
window.wcAdminFeatures.analytics;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
( userPrefLayout || defaultHomescreenLayout ) === 'two_columns' &&
|
|
|
|
|
hasTwoColumnContent
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2020-08-05 00:14:56 +00:00
|
|
|
|
export const Layout = ( {
|
2020-11-06 17:53:03 +00:00
|
|
|
|
defaultHomescreenLayout,
|
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,
|
2021-03-25 21:54:24 +00:00
|
|
|
|
isTaskListHidden,
|
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;
|
2023-04-17 21:07:25 +00:00
|
|
|
|
const shouldShowWCPayFeature = taskListComplete || isTaskListHidden;
|
2024-05-22 22:05:01 +00:00
|
|
|
|
const isDashboardShown = Object.keys( query ).length > 0 && ! 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
|
|
|
|
|
2024-06-27 20:37:25 +00:00
|
|
|
|
const twoColumns = hasTwoColumnLayout(
|
|
|
|
|
userPrefs.homepage_layout,
|
|
|
|
|
defaultHomescreenLayout,
|
|
|
|
|
taskListComplete,
|
|
|
|
|
isTaskListHidden
|
|
|
|
|
);
|
2021-11-02 22:36:12 +00:00
|
|
|
|
|
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;
|
2022-09-15 03:58:47 +00:00
|
|
|
|
const shouldShowMobileAppModal = query.mobileAppModal ?? false;
|
2020-11-11 17:20:15 +00:00
|
|
|
|
|
2023-11-15 07:21:14 +00:00
|
|
|
|
const renderTaskList = () => {
|
|
|
|
|
return (
|
|
|
|
|
<Suspense fallback={ <TasksPlaceholder query={ query } /> }>
|
|
|
|
|
{ activeSetupTaskList && isDashboardShown && (
|
|
|
|
|
<>
|
|
|
|
|
<ProgressTitle taskListId={ activeSetupTaskList } />
|
|
|
|
|
</>
|
|
|
|
|
) }
|
|
|
|
|
<TaskLists query={ query } />
|
|
|
|
|
</Suspense>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
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={ __(
|
2024-08-20 09:13:17 +00:00
|
|
|
|
'To do’s, tips, and insights for your business',
|
2022-06-16 20:51:46 +00:00
|
|
|
|
'woocommerce'
|
|
|
|
|
) }
|
|
|
|
|
/>
|
|
|
|
|
) }
|
2023-04-17 21:07:25 +00:00
|
|
|
|
{ shouldShowWCPayFeature && <WooHomescreenWCPayFeature /> }
|
2023-09-21 22:35:45 +00:00
|
|
|
|
{ isTaskListHidden && <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
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-12 23:14:08 +00:00
|
|
|
|
return (
|
2021-10-20 16:16:22 +00:00
|
|
|
|
<>
|
2023-01-20 14:01:20 +00:00
|
|
|
|
{ isDashboardShown && (
|
|
|
|
|
<WooHomescreenHeaderBanner
|
2024-05-31 03:49:36 +00:00
|
|
|
|
className={ clsx( 'woocommerce-homescreen', {
|
2023-01-20 14:01:20 +00:00
|
|
|
|
'woocommerce-homescreen-column': ! twoColumns,
|
|
|
|
|
} ) }
|
|
|
|
|
/>
|
|
|
|
|
) }
|
2021-10-20 16:16:22 +00:00
|
|
|
|
<div
|
2024-05-31 03:49:36 +00:00
|
|
|
|
className={ clsx( 'woocommerce-homescreen', {
|
2021-10-20 16:16:22 +00:00
|
|
|
|
'two-columns': twoColumns,
|
|
|
|
|
} ) }
|
|
|
|
|
>
|
|
|
|
|
{ isDashboardShown ? renderColumns() : renderTaskList() }
|
2022-09-15 03:58:47 +00:00
|
|
|
|
{ shouldShowMobileAppModal && <MobileAppModal /> }
|
2021-10-20 16:16:22 +00:00
|
|
|
|
</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,
|
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 );
|
2024-06-13 02:39:21 +00:00
|
|
|
|
const { getOption } = 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
|
|
|
|
|
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' ),
|
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
|
|
|
|
};
|
2024-06-13 02:39:21 +00:00
|
|
|
|
} )
|
2020-05-21 17:15:08 +00:00
|
|
|
|
)( Layout );
|