2020-03-25 03:20:17 +00:00
|
|
|
/**
|
|
|
|
* WooCommerce dependencies
|
|
|
|
*/
|
|
|
|
import { SETTINGS_STORE_NAME } from '@woocommerce/data';
|
|
|
|
|
2019-03-29 02:45:19 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2020-03-25 03:20:17 +00:00
|
|
|
import { DEFAULT_ACTIONABLE_STATUSES } from 'analytics/settings/config';
|
2019-10-07 11:51:25 +00:00
|
|
|
import { getSetting } from '@woocommerce/wc-admin-settings';
|
2020-05-28 08:52:25 +00:00
|
|
|
import { QUERY_DEFAULTS } from 'wc-api/constants';
|
2019-03-29 02:45:19 +00:00
|
|
|
|
|
|
|
export function getUnreadNotes( select ) {
|
2020-02-14 02:23:21 +00:00
|
|
|
const {
|
|
|
|
getCurrentUserData,
|
|
|
|
getNotes,
|
|
|
|
getNotesError,
|
|
|
|
isGetNotesRequesting,
|
|
|
|
} = select( 'wc-api' );
|
2019-03-29 02:45:19 +00:00
|
|
|
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,
|
2020-05-28 08:52:25 +00:00
|
|
|
type: QUERY_DEFAULTS.noteTypes,
|
2019-04-01 02:53:34 +00:00
|
|
|
orderby: 'date',
|
|
|
|
order: 'desc',
|
2019-03-29 02:45:19 +00:00
|
|
|
};
|
|
|
|
|
2020-02-14 02:23:21 +00:00
|
|
|
// Disable eslint rule requiring `latestNote` to be defined below because the next two statements
|
|
|
|
// depend on `getNotes` to have been called.
|
|
|
|
// eslint-disable-next-line @wordpress/no-unused-vars-before-return
|
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 ) {
|
2020-02-14 02:23:21 +00:00
|
|
|
const {
|
|
|
|
getItems,
|
|
|
|
getItemsTotalCount,
|
|
|
|
getItemsError,
|
|
|
|
isGetItemsRequesting,
|
|
|
|
} = select( 'wc-api' );
|
2020-03-25 03:20:17 +00:00
|
|
|
const { getSetting: getMutableSetting } = select( SETTINGS_STORE_NAME );
|
2019-10-07 11:51:25 +00:00
|
|
|
const {
|
|
|
|
woocommerce_actionable_order_statuses: orderStatuses = DEFAULT_ACTIONABLE_STATUSES,
|
2020-03-25 03:20:17 +00:00
|
|
|
} = getMutableSetting( 'wc_admin', '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 );
|
2020-02-14 02:23:21 +00:00
|
|
|
|
|
|
|
// Disable eslint rule requiring `latestNote` to be defined below because the next two statements
|
|
|
|
// depend on `getItemsTotalCount` to have been called.
|
|
|
|
// eslint-disable-next-line @wordpress/no-unused-vars-before-return
|
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 ) {
|
2020-02-14 02:23:21 +00:00
|
|
|
const {
|
|
|
|
getReviewsTotalCount,
|
|
|
|
getReviewsError,
|
|
|
|
isGetReviewsRequesting,
|
|
|
|
} = select( 'wc-api' );
|
2019-10-07 11:51:25 +00:00
|
|
|
const reviewsEnabled = getSetting( 'reviewsEnabled' );
|
2020-02-14 02:23:21 +00:00
|
|
|
if ( reviewsEnabled === 'yes' ) {
|
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
|
|
|
};
|
2020-02-14 02:23:21 +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
|
|
|
}
|
|
|
|
|
2020-03-02 22:22:32 +00:00
|
|
|
export function getUnreadStock() {
|
|
|
|
return getSetting( 'hasLowStock', false );
|
2019-03-29 02:45:19 +00:00
|
|
|
}
|