/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { lazy, useState } from '@wordpress/element';
import { Button } from '@wordpress/components';
import { useDispatch, useSelect } from '@wordpress/data';
import { uniqueId, find } from 'lodash';
import CrossIcon from 'gridicons/dist/cross-small';
import classnames from 'classnames';
import { Icon, help as helpIcon, inbox as inboxIcon } from '@wordpress/icons';
import { getAdminLink } from '@woocommerce/wc-admin-settings';
import { H, Section } from '@woocommerce/components';
import { OPTIONS_STORE_NAME, useUser } from '@woocommerce/data';
import { getHistory, getNewPath } from '@woocommerce/navigation';
import { recordEvent } from '@woocommerce/tracks';
/**
* Internal dependencies
*/
import './style.scss';
import ActivityPanelToggleBubble from './toggle-bubble';
import { getUnreadNotes } from './unread-indicators';
import { isWCAdmin } from '../../dashboard/utils';
import { Tabs } from './tabs';
import { SetupProgress } from './setup-progress';
import { DisplayOptions } from './display-options';
import { HighlightTooltip } from './highlight-tooltip';
import { Panel } from './panel';
const HelpPanel = lazy( () =>
import( /* webpackChunkName: "activity-panels-help" */ './panels/help' )
);
const InboxPanel = lazy( () =>
import(
/* webpackChunkName: "activity-panels-inbox" */ '../../inbox-panel'
)
);
export const ActivityPanel = ( { isEmbedded, query, userPreferencesData } ) => {
const [ currentTab, setCurrentTab ] = useState( '' );
const [ isPanelOpen, setIsPanelOpen ] = useState( false );
const [ isPanelSwitching, setIsPanelSwitching ] = useState( false );
const [ mobileOpen, setMobileOpen ] = useState( false );
const {
hasUnreadNotes,
requestingTaskListOptions,
setupTaskListComplete,
setupTaskListHidden,
trackedCompletedTasks,
} = useSelect( ( select ) => {
const { getOption, isResolving } = select( OPTIONS_STORE_NAME );
return {
hasUnreadNotes: getUnreadNotes( select ),
requestingTaskListOptions:
isResolving( 'getOption', [
'woocommerce_task_list_complete',
] ) ||
isResolving( 'getOption', [ 'woocommerce_task_list_hidden' ] ),
setupTaskListComplete:
getOption( 'woocommerce_task_list_complete' ) === 'yes',
setupTaskListHidden:
getOption( 'woocommerce_task_list_hidden' ) === 'yes',
trackedCompletedTasks:
getOption( 'woocommerce_task_list_tracked_completed_tasks' ) ||
[],
};
} );
const { updateOptions } = useDispatch( OPTIONS_STORE_NAME );
const { currentUserCan } = useUser();
const togglePanel = ( { name: tabName }, isTabOpen ) => {
const panelSwitching =
tabName !== currentTab &&
currentTab !== '' &&
isTabOpen &&
isPanelOpen;
setCurrentTab( tabName );
setMobileOpen( isTabOpen );
setIsPanelOpen( isTabOpen );
setIsPanelSwitching( panelSwitching );
};
const closePanel = () => {
setCurrentTab( '' );
setIsPanelOpen( false );
};
const clearPanel = () => {
setIsPanelSwitching( 'false' );
};
// On smaller screen, the panel buttons are hidden behind a toggle.
const toggleMobile = () => {
const tabs = getTabs();
setCurrentTab( mobileOpen ? '' : tabs[ 0 ].name );
setMobileOpen( ! mobileOpen );
setIsPanelOpen( ! mobileOpen );
};
const isHomescreen = () => {
return query.page === 'wc-admin' && ! query.path;
};
const isPerformingSetupTask = () => {
return (
query.task &&
! query.path &&
( requestingTaskListOptions === true ||
( setupTaskListHidden === false &&
setupTaskListComplete === false ) )
);
};
// @todo Pull in dynamic unread status/count
const getTabs = () => {
const inbox = {
name: 'inbox',
title: __( 'Inbox', 'woocommerce-admin' ),
icon: