2019-03-29 02:45:19 +00:00
|
|
|
/** @format */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2019-04-30 09:40:10 +00:00
|
|
|
import { DEFAULT_ACTIONABLE_STATUSES } from 'wc-api/constants';
|
2019-10-07 11:51:25 +00:00
|
|
|
import { getSetting } from '@woocommerce/wc-admin-settings';
|
2019-03-29 02:45:19 +00:00
|
|
|
|
|
|
|
export function getUnreadNotes( select ) {
|
|
|
|
const { getCurrentUserData, getNotes, getNotesError, isGetNotesRequesting } = select( 'wc-api' );
|
|
|
|
const userData = getCurrentUserData();
|
2019-09-23 21:47:08 +00:00
|
|
|
if ( ! userData ) {
|
|
|
|
return null;
|
|
|
|
}
|
2019-03-29 02:45:19 +00:00
|
|
|
const notesQuery = {
|
|
|
|
page: 1,
|
|
|
|
per_page: 1,
|
2019-04-01 02:53:34 +00:00
|
|
|
type: 'info,warning',
|
|
|
|
orderby: 'date',
|
|
|
|
order: 'desc',
|
2019-03-29 02:45:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const latestNote = getNotes( notesQuery );
|
2019-04-09 07:50:00 +00:00
|
|
|
const isError = Boolean( getNotesError( notesQuery ) );
|
|
|
|
const isRequesting = isGetNotesRequesting( notesQuery );
|
|
|
|
|
|
|
|
if ( isError || isRequesting ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-03-29 02:45:19 +00:00
|
|
|
return (
|
|
|
|
latestNote[ 0 ] &&
|
2019-04-09 07:50:00 +00:00
|
|
|
new Date( latestNote[ 0 ].date_created_gmt + 'Z' ).getTime() >
|
|
|
|
userData.activity_panel_inbox_last_read
|
2019-03-29 02:45:19 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getUnreadOrders( select ) {
|
2019-07-17 15:56:13 +00:00
|
|
|
const { getItems, getItemsTotalCount, getItemsError, isGetItemsRequesting } = select( 'wc-api' );
|
2019-10-07 11:51:25 +00:00
|
|
|
const {
|
|
|
|
woocommerce_actionable_order_statuses: orderStatuses = DEFAULT_ACTIONABLE_STATUSES,
|
|
|
|
} = getSetting( 'wcAdminSettings', {} );
|
2019-03-29 02:45:19 +00:00
|
|
|
|
|
|
|
if ( ! orderStatuses.length ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ordersQuery = {
|
|
|
|
page: 1,
|
2019-07-16 21:03:15 +00:00
|
|
|
per_page: 1, // Core endpoint requires per_page > 0.
|
|
|
|
status: orderStatuses,
|
2019-07-17 15:56:13 +00:00
|
|
|
_fields: [ 'id' ],
|
2019-03-29 02:45:19 +00:00
|
|
|
};
|
|
|
|
|
2019-07-17 15:56:13 +00:00
|
|
|
getItems( 'orders', ordersQuery );
|
2019-07-16 21:03:15 +00:00
|
|
|
const totalOrders = getItemsTotalCount( 'orders', ordersQuery );
|
|
|
|
const isError = Boolean( getItemsError( 'orders', ordersQuery ) );
|
|
|
|
const isRequesting = isGetItemsRequesting( 'orders', ordersQuery );
|
2019-03-29 02:45:19 +00:00
|
|
|
|
2019-04-09 07:50:00 +00:00
|
|
|
if ( isError || isRequesting ) {
|
|
|
|
return null;
|
2019-03-29 02:45:19 +00:00
|
|
|
}
|
2019-04-09 07:50:00 +00:00
|
|
|
|
|
|
|
return totalOrders > 0;
|
2019-03-29 02:45:19 +00:00
|
|
|
}
|
|
|
|
|
2019-04-30 09:40:10 +00:00
|
|
|
export function getUnapprovedReviews( select ) {
|
|
|
|
const { getReviewsTotalCount, getReviewsError, isGetReviewsRequesting } = select( 'wc-api' );
|
2019-10-07 11:51:25 +00:00
|
|
|
const reviewsEnabled = getSetting( 'reviewsEnabled' );
|
2019-12-20 18:16:48 +00:00
|
|
|
if ( 'yes' === reviewsEnabled ) {
|
2019-04-30 09:40:10 +00:00
|
|
|
const actionableReviewsQuery = {
|
2019-03-29 02:45:19 +00:00
|
|
|
page: 1,
|
2019-04-30 09:40:10 +00:00
|
|
|
// @todo we are not using this review, so when the endpoint supports it,
|
|
|
|
// it could be replaced with `per_page: 0`
|
2019-03-29 02:45:19 +00:00
|
|
|
per_page: 1,
|
2019-04-30 09:40:10 +00:00
|
|
|
status: 'hold',
|
2019-03-29 02:45:19 +00:00
|
|
|
};
|
2019-04-30 09:40:10 +00:00
|
|
|
const totalActionableReviews = getReviewsTotalCount( actionableReviewsQuery );
|
|
|
|
const isActionableReviewsError = Boolean( getReviewsError( actionableReviewsQuery ) );
|
|
|
|
const isActionableReviewsRequesting = isGetReviewsRequesting( actionableReviewsQuery );
|
2019-04-01 18:43:48 +00:00
|
|
|
|
2019-04-30 09:40:10 +00:00
|
|
|
if ( ! isActionableReviewsError && ! isActionableReviewsRequesting ) {
|
|
|
|
return totalActionableReviews > 0;
|
2019-03-29 02:45:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-30 09:40:10 +00:00
|
|
|
return false;
|
2019-03-29 02:45:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getUnreadStock( select ) {
|
|
|
|
const { getItems, getItemsError, getItemsTotalCount, isGetItemsRequesting } = select( 'wc-api' );
|
|
|
|
const productsQuery = {
|
|
|
|
page: 1,
|
|
|
|
per_page: 1,
|
|
|
|
low_in_stock: true,
|
|
|
|
status: 'publish',
|
|
|
|
};
|
|
|
|
getItems( 'products', productsQuery );
|
|
|
|
const lowInStockCount = getItemsTotalCount( 'products', productsQuery );
|
2019-04-09 07:50:00 +00:00
|
|
|
const isError = Boolean( getItemsError( 'products', productsQuery ) );
|
|
|
|
const isRequesting = isGetItemsRequesting( 'products', productsQuery );
|
|
|
|
|
|
|
|
if ( isError || isRequesting ) {
|
|
|
|
return null;
|
|
|
|
}
|
2019-03-29 02:45:19 +00:00
|
|
|
|
2019-04-09 07:50:00 +00:00
|
|
|
return lowInStockCount > 0;
|
2019-03-29 02:45:19 +00:00
|
|
|
}
|