2021-06-09 13:56:45 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __, _n, sprintf } from '@wordpress/i18n';
|
|
|
|
import { Text } from '@woocommerce/experimental';
|
|
|
|
import { recordEvent } from '@woocommerce/tracks';
|
|
|
|
import { AbbreviatedCard } from '@woocommerce/components';
|
|
|
|
import { useSelect } from '@wordpress/data';
|
2021-11-15 20:57:13 +00:00
|
|
|
import { ONBOARDING_STORE_NAME } from '@woocommerce/data';
|
2021-06-09 13:56:45 +00:00
|
|
|
import { box, comment, page } from '@wordpress/icons';
|
2021-06-11 13:37:21 +00:00
|
|
|
import { createSlotFill } from '@wordpress/components';
|
2021-06-09 13:56:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import {
|
|
|
|
getLowStockCount,
|
|
|
|
getOrderStatuses,
|
|
|
|
getUnreadOrders,
|
2021-12-14 16:56:42 +00:00
|
|
|
} from '~/homescreen/activity-panel/orders/utils';
|
|
|
|
import { getUnapprovedReviews } from '~/homescreen/activity-panel/reviews/utils';
|
|
|
|
import { isWCAdmin } from '~/dashboard/utils';
|
2021-06-09 13:56:45 +00:00
|
|
|
import { Bell } from './icons/bell';
|
|
|
|
|
|
|
|
const EXTENDED_TASK_LIST_ID = 'extended_task_list';
|
|
|
|
const ORDER_PANEL_ID = 'orders-panel';
|
|
|
|
const REVIEWS_PANEL_ID = 'reviews-panel';
|
|
|
|
const STOCK_PANEL_ID = 'stock-panel';
|
|
|
|
|
2021-06-11 13:37:21 +00:00
|
|
|
export const ABBREVIATED_NOTIFICATION_SLOT_NAME = 'AbbreviatedNotification';
|
|
|
|
|
2021-06-09 13:56:45 +00:00
|
|
|
export const AbbreviatedNotificationsPanel = ( { thingsToDoNextCount } ) => {
|
|
|
|
const {
|
|
|
|
ordersToProcessCount,
|
|
|
|
reviewsToModerateCount,
|
|
|
|
stockNoticesCount,
|
|
|
|
isSetupTaskListHidden,
|
|
|
|
isExtendedTaskListHidden,
|
|
|
|
} = useSelect( ( select ) => {
|
2021-11-15 20:57:13 +00:00
|
|
|
const { getTaskList } = select( ONBOARDING_STORE_NAME );
|
2021-06-09 13:56:45 +00:00
|
|
|
const orderStatuses = getOrderStatuses( select );
|
2021-11-15 20:57:13 +00:00
|
|
|
|
2021-06-09 13:56:45 +00:00
|
|
|
return {
|
|
|
|
ordersToProcessCount: getUnreadOrders( select, orderStatuses ),
|
|
|
|
reviewsToModerateCount: getUnapprovedReviews( select ),
|
|
|
|
stockNoticesCount: getLowStockCount( select ),
|
2021-11-15 20:57:13 +00:00
|
|
|
isSetupTaskListHidden: getTaskList( 'setup' )?.isHidden,
|
|
|
|
isExtendedTaskListHidden: getTaskList( 'extended' )?.isHidden,
|
2021-06-09 13:56:45 +00:00
|
|
|
};
|
|
|
|
} );
|
|
|
|
|
|
|
|
const trackAbbreviatedCardClick = ( name ) => {
|
|
|
|
recordEvent( 'activity_panel_click', {
|
|
|
|
task: name,
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2021-06-11 13:37:21 +00:00
|
|
|
const { Slot } = createSlotFill( ABBREVIATED_NOTIFICATION_SLOT_NAME );
|
2021-06-09 13:56:45 +00:00
|
|
|
const isWCAdminPage = isWCAdmin( window.location.href );
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="woocommerce-abbreviated-notifications">
|
|
|
|
{ thingsToDoNextCount > 0 && ! isExtendedTaskListHidden && (
|
|
|
|
<AbbreviatedCard
|
|
|
|
className="woocommerce-abbreviated-notification"
|
|
|
|
icon={ <Bell /> }
|
|
|
|
href={ `admin.php?page=wc-admin#${ EXTENDED_TASK_LIST_ID }` }
|
|
|
|
onClick={ () =>
|
|
|
|
trackAbbreviatedCardClick( 'thingsToDoNext' )
|
|
|
|
}
|
|
|
|
type={ isWCAdminPage ? 'wc-admin' : 'wp-admin' }
|
|
|
|
>
|
|
|
|
<Text as="h3">
|
2022-03-30 09:00:04 +00:00
|
|
|
{ __( 'Things to do next', 'woocommerce' ) }
|
2021-06-09 13:56:45 +00:00
|
|
|
</Text>
|
2021-06-28 01:14:59 +00:00
|
|
|
<Text as="p">
|
2021-06-09 13:56:45 +00:00
|
|
|
{ sprintf(
|
|
|
|
/* translators: Things the user has to do */
|
|
|
|
_n(
|
|
|
|
'You have %d new thing to do',
|
|
|
|
'You have %d new things to do',
|
|
|
|
thingsToDoNextCount,
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2021-06-09 13:56:45 +00:00
|
|
|
),
|
|
|
|
thingsToDoNextCount
|
|
|
|
) }
|
|
|
|
</Text>
|
|
|
|
</AbbreviatedCard>
|
|
|
|
) }
|
|
|
|
{ ordersToProcessCount > 0 && isSetupTaskListHidden && (
|
|
|
|
<AbbreviatedCard
|
|
|
|
className="woocommerce-abbreviated-notification"
|
|
|
|
icon={ page }
|
|
|
|
href={ `admin.php?page=wc-admin&opened_panel=${ ORDER_PANEL_ID }` }
|
|
|
|
onClick={ () =>
|
|
|
|
trackAbbreviatedCardClick( 'ordersToProcess' )
|
|
|
|
}
|
|
|
|
type={ isWCAdminPage ? 'wc-admin' : 'wp-admin' }
|
|
|
|
>
|
|
|
|
<Text as="h3">
|
2022-03-30 09:00:04 +00:00
|
|
|
{ __( 'Orders to fulfill', 'woocommerce' ) }
|
2021-06-09 13:56:45 +00:00
|
|
|
</Text>
|
|
|
|
<Text>
|
|
|
|
{ sprintf(
|
|
|
|
/* translators: Number of orders the user has to fulfill */
|
|
|
|
_n(
|
|
|
|
'You have %d order to fulfill',
|
|
|
|
'You have %d orders to fulfill',
|
|
|
|
ordersToProcessCount,
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2021-06-09 13:56:45 +00:00
|
|
|
),
|
|
|
|
ordersToProcessCount
|
|
|
|
) }
|
|
|
|
</Text>
|
|
|
|
</AbbreviatedCard>
|
|
|
|
) }
|
|
|
|
{ reviewsToModerateCount > 0 && isSetupTaskListHidden && (
|
|
|
|
<AbbreviatedCard
|
|
|
|
className="woocommerce-abbreviated-notification"
|
|
|
|
icon={ comment }
|
|
|
|
href={ `admin.php?page=wc-admin&opened_panel=${ REVIEWS_PANEL_ID }` }
|
|
|
|
onClick={ () =>
|
|
|
|
trackAbbreviatedCardClick( 'reviewsToModerate' )
|
|
|
|
}
|
|
|
|
type={ isWCAdminPage ? 'wc-admin' : 'wp-admin' }
|
|
|
|
>
|
|
|
|
<Text as="h3">
|
2022-03-30 09:00:04 +00:00
|
|
|
{ __( 'Reviews to moderate', 'woocommerce' ) }
|
2021-06-09 13:56:45 +00:00
|
|
|
</Text>
|
|
|
|
<Text>
|
|
|
|
{ sprintf(
|
|
|
|
/* translators: Number of reviews the user has to moderate */
|
|
|
|
_n(
|
|
|
|
'You have %d review to moderate',
|
|
|
|
'You have %d reviews to moderate',
|
|
|
|
reviewsToModerateCount,
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2021-06-09 13:56:45 +00:00
|
|
|
),
|
|
|
|
reviewsToModerateCount
|
|
|
|
) }
|
|
|
|
</Text>
|
|
|
|
</AbbreviatedCard>
|
|
|
|
) }
|
|
|
|
{ stockNoticesCount > 0 && isSetupTaskListHidden && (
|
|
|
|
<AbbreviatedCard
|
|
|
|
className="woocommerce-abbreviated-notification"
|
|
|
|
icon={ box }
|
|
|
|
href={ `admin.php?page=wc-admin&opened_panel=${ STOCK_PANEL_ID }` }
|
|
|
|
onClick={ () =>
|
|
|
|
trackAbbreviatedCardClick( 'stockNotices' )
|
|
|
|
}
|
|
|
|
type={ isWCAdminPage ? 'wc-admin' : 'wp-admin' }
|
|
|
|
>
|
|
|
|
<Text as="h3">
|
2022-03-30 09:00:04 +00:00
|
|
|
{ __( 'Inventory to review', 'woocommerce' ) }
|
2021-06-09 13:56:45 +00:00
|
|
|
</Text>
|
|
|
|
<Text>
|
|
|
|
{ __(
|
|
|
|
'You have inventory to review and update',
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2021-06-09 13:56:45 +00:00
|
|
|
) }
|
|
|
|
</Text>
|
|
|
|
</AbbreviatedCard>
|
|
|
|
) }
|
2021-06-11 13:37:21 +00:00
|
|
|
{ ! isExtendedTaskListHidden && <Slot /> }
|
2021-06-09 13:56:45 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default AbbreviatedNotificationsPanel;
|