2018-07-16 18:37:25 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { Component, Fragment } from '@wordpress/element';
|
2018-10-12 19:20:48 +00:00
|
|
|
import { compose } from '@wordpress/compose';
|
2018-07-16 18:37:25 +00:00
|
|
|
import Gridicon from 'gridicons';
|
2019-03-21 02:54:36 +00:00
|
|
|
import { withDispatch } from '@wordpress/data';
|
2018-07-16 18:37:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2019-10-24 17:13:05 +00:00
|
|
|
import { ActivityCard, ActivityCardPlaceholder } from '../../activity-card';
|
|
|
|
import ActivityHeader from '../../activity-header';
|
|
|
|
import InboxNoteCard from './card';
|
2018-10-16 22:34:36 +00:00
|
|
|
import { EmptyContent, Section } from '@woocommerce/components';
|
2019-01-30 07:22:10 +00:00
|
|
|
import { QUERY_DEFAULTS } from 'wc-api/constants';
|
2019-03-21 02:54:36 +00:00
|
|
|
import withSelect from 'wc-api/with-select';
|
2018-07-16 18:37:25 +00:00
|
|
|
|
|
|
|
class InboxPanel extends Component {
|
2019-03-21 02:54:36 +00:00
|
|
|
constructor( props ) {
|
|
|
|
super( props );
|
|
|
|
this.mountTime = Date.now();
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
const userDataFields = {
|
|
|
|
[ 'activity_panel_inbox_last_read' ]: this.mountTime,
|
|
|
|
};
|
|
|
|
this.props.updateCurrentUserData( userDataFields );
|
|
|
|
}
|
|
|
|
|
2019-04-15 07:06:34 +00:00
|
|
|
renderEmptyCard() {
|
|
|
|
return (
|
|
|
|
<ActivityCard
|
2019-06-12 21:51:08 +00:00
|
|
|
className="woocommerce-empty-activity-card"
|
2019-04-15 07:06:34 +00:00
|
|
|
title={ __( 'Your inbox is empty', 'woocommerce-admin' ) }
|
|
|
|
icon={ <Gridicon icon="checkmark" size={ 48 } /> }
|
|
|
|
>
|
|
|
|
{ __(
|
|
|
|
'As things begin to happen in your store your inbox will start to fill up. ' +
|
|
|
|
"You'll see things like achievements, new feature announcements, extension recommendations and more!",
|
|
|
|
'woocommerce-admin'
|
|
|
|
) }
|
|
|
|
</ActivityCard>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderNotes() {
|
2019-06-19 19:23:32 +00:00
|
|
|
const { lastRead, notes } = this.props;
|
2019-04-15 07:06:34 +00:00
|
|
|
|
|
|
|
if ( 0 === Object.keys( notes ).length ) {
|
|
|
|
return this.renderEmptyCard();
|
|
|
|
}
|
|
|
|
|
|
|
|
const notesArray = Object.keys( notes ).map( key => notes[ key ] );
|
|
|
|
|
|
|
|
return notesArray.map( note => (
|
2019-10-24 17:13:05 +00:00
|
|
|
<InboxNoteCard key={ note.id } note={ note } lastRead={ lastRead } />
|
2019-04-15 07:06:34 +00:00
|
|
|
) );
|
|
|
|
}
|
|
|
|
|
2018-07-16 18:37:25 +00:00
|
|
|
render() {
|
2019-04-15 07:06:34 +00:00
|
|
|
const { isError, isRequesting } = this.props;
|
2018-10-16 22:34:36 +00:00
|
|
|
|
|
|
|
if ( isError ) {
|
2019-03-13 17:14:02 +00:00
|
|
|
const title = __(
|
|
|
|
'There was an error getting your inbox. Please try again.',
|
|
|
|
'woocommerce-admin'
|
|
|
|
);
|
|
|
|
const actionLabel = __( 'Reload', 'woocommerce-admin' );
|
2018-10-16 22:34:36 +00:00
|
|
|
const actionCallback = () => {
|
2019-02-06 06:41:53 +00:00
|
|
|
// @todo Add tracking for how often an error is displayed, and the reload action is clicked.
|
2018-10-16 22:34:36 +00:00
|
|
|
window.location.reload();
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
<EmptyContent
|
|
|
|
title={ title }
|
|
|
|
actionLabel={ actionLabel }
|
|
|
|
actionURL={ null }
|
|
|
|
actionCallback={ actionCallback }
|
|
|
|
/>
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
2018-10-12 19:20:48 +00:00
|
|
|
|
2018-07-16 18:37:25 +00:00
|
|
|
return (
|
|
|
|
<Fragment>
|
2019-03-13 17:14:02 +00:00
|
|
|
<ActivityHeader title={ __( 'Inbox', 'woocommerce-admin' ) } />
|
2018-07-16 18:37:25 +00:00
|
|
|
<Section>
|
2018-10-16 19:46:00 +00:00
|
|
|
{ isRequesting ? (
|
2018-07-20 18:41:39 +00:00
|
|
|
<ActivityCardPlaceholder
|
|
|
|
className="woocommerce-inbox-activity-card"
|
|
|
|
hasAction
|
|
|
|
hasDate
|
|
|
|
lines={ 2 }
|
|
|
|
/>
|
|
|
|
) : (
|
2019-04-15 07:06:34 +00:00
|
|
|
this.renderNotes()
|
2018-07-20 18:41:39 +00:00
|
|
|
) }
|
2018-07-16 18:37:25 +00:00
|
|
|
</Section>
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-12 19:20:48 +00:00
|
|
|
export default compose(
|
|
|
|
withSelect( select => {
|
2019-03-21 02:54:36 +00:00
|
|
|
const { getCurrentUserData, getNotes, getNotesError, isGetNotesRequesting } = select(
|
|
|
|
'wc-api'
|
|
|
|
);
|
|
|
|
const userData = getCurrentUserData();
|
2018-10-16 19:46:00 +00:00
|
|
|
const inboxQuery = {
|
|
|
|
page: 1,
|
2018-10-26 08:19:39 +00:00
|
|
|
per_page: QUERY_DEFAULTS.pageSize,
|
2018-12-11 01:00:57 +00:00
|
|
|
type: 'info,warning',
|
2019-04-01 02:53:34 +00:00
|
|
|
orderby: 'date',
|
|
|
|
order: 'desc',
|
2019-05-28 19:56:50 +00:00
|
|
|
status: 'unactioned',
|
2018-10-16 19:46:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const notes = getNotes( inboxQuery );
|
2018-12-15 12:38:54 +00:00
|
|
|
const isError = Boolean( getNotesError( inboxQuery ) );
|
2018-10-16 19:46:00 +00:00
|
|
|
const isRequesting = isGetNotesRequesting( inboxQuery );
|
|
|
|
|
2019-03-21 02:54:36 +00:00
|
|
|
return { notes, isError, isRequesting, lastRead: userData.activity_panel_inbox_last_read };
|
|
|
|
} ),
|
|
|
|
withDispatch( dispatch => {
|
2019-10-24 17:13:05 +00:00
|
|
|
const { updateCurrentUserData } = dispatch( 'wc-api' );
|
2019-03-21 02:54:36 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
updateCurrentUserData,
|
|
|
|
};
|
2018-10-12 19:20:48 +00:00
|
|
|
} )
|
|
|
|
)( InboxPanel );
|