/**
* External dependencies
*/
import {
Suspense,
lazy,
useCallback,
useLayoutEffect,
useRef,
useState,
} from '@wordpress/element';
import { compose } from '@wordpress/compose';
import { withDispatch, withSelect } from '@wordpress/data';
import classnames from 'classnames';
import PropTypes from 'prop-types';
import {
useUserPreferences,
NOTES_STORE_NAME,
OPTIONS_STORE_NAME,
} from '@woocommerce/data';
import { __ } from '@wordpress/i18n';
import moment from 'moment';
import { useExperiment } from '@woocommerce/explat';
/**
* Internal dependencies
*/
import ActivityHeader from '../header/activity-panel/activity-header';
import { ActivityPanel } from './activity-panel';
import { Column } from './column';
import InboxPanel from '../inbox-panel';
import { IntroModal as NavigationIntroModal } from '../navigation/components/intro-modal';
import StatsOverview from './stats-overview';
import { StoreManagementLinks } from '../store-management-links';
import { TasksPlaceholder } from '../tasks';
import {
WELCOME_MODAL_DISMISSED_OPTION_NAME,
WELCOME_FROM_CALYPSO_MODAL_DISMISSED_OPTION_NAME,
} from './constants';
import { WelcomeFromCalypsoModal } from './welcome-from-calypso-modal';
import { WelcomeModal } from './welcome-modal';
import './style.scss';
import '../dashboard/style.scss';
const Tasks = lazy( () =>
import( /* webpackChunkName: "tasks" */ '../tasks' )
);
const TwoColumnTasks = lazy( () =>
import( /* webpackChunkName: "two-column-tasks" */ '../two-column-tasks' )
);
const TwoColumnTasksExtended = lazy( () =>
import(
/* webpackChunkName: "two-column-tasks-extended" */ '../two-column-tasks/extended-task'
)
);
export const Layout = ( {
defaultHomescreenLayout,
isBatchUpdating,
query,
taskListComplete,
bothTaskListsHidden,
shouldShowWelcomeModal,
shouldShowWelcomeFromCalypsoModal,
isTaskListHidden,
updateOptions,
} ) => {
const userPrefs = useUserPreferences();
const shouldShowStoreLinks = taskListComplete || isTaskListHidden;
const hasTwoColumnContent =
shouldShowStoreLinks || window.wcAdminFeatures.analytics;
const twoColumns =
( userPrefs.homepage_layout || defaultHomescreenLayout ) ===
'two_columns' && hasTwoColumnContent;
const [ showInbox, setShowInbox ] = useState( true );
const isTaskListEnabled = bothTaskListsHidden === false;
const isDashboardShown = ! query.task;
const momentDate = moment().utc();
const [
isLoadingExperimentAssignment,
experimentAssignment,
] = useExperiment(
'woocommerce_tasklist_progression_headercard_' +
momentDate.format( 'YYYY' ) +
'_' +
momentDate.format( 'MM' )
);
const isRunningTwoColumnExperiment =
experimentAssignment?.variationName === 'treatment';
if ( isBatchUpdating && ! showInbox ) {
setShowInbox( true );
}
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;
const renderColumns = () => {
return (
<>