2018-07-16 18:37:25 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
2018-07-20 18:41:39 +00:00
|
|
|
import { Button } from '@wordpress/components';
|
2018-07-16 18:37:25 +00:00
|
|
|
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';
|
2018-10-12 20:56:45 +00:00
|
|
|
import { sortBy } from 'lodash';
|
2018-10-12 19:20:48 +00:00
|
|
|
import { withSelect } from '@wordpress/data';
|
2018-07-16 18:37:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2018-07-20 18:41:39 +00:00
|
|
|
import { ActivityCard, ActivityCardPlaceholder } from '../activity-card';
|
2018-07-16 18:37:25 +00:00
|
|
|
import ActivityHeader from '../activity-header';
|
2018-10-12 20:40:16 +00:00
|
|
|
import sanitizeHTML from 'lib/sanitize-html';
|
2018-09-21 15:19:05 +00:00
|
|
|
import { Section } from '@woocommerce/components';
|
2018-07-16 18:37:25 +00:00
|
|
|
|
|
|
|
class InboxPanel extends Component {
|
|
|
|
render() {
|
2018-10-12 19:20:48 +00:00
|
|
|
const { loading, notes } = this.props;
|
|
|
|
|
2018-07-20 18:41:39 +00:00
|
|
|
const getButtonsFromActions = actions => {
|
|
|
|
if ( ! actions ) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
return actions.map( action => (
|
|
|
|
<Button isDefault href={ action.url }>
|
|
|
|
{ action.label }
|
|
|
|
</Button>
|
|
|
|
) );
|
|
|
|
};
|
|
|
|
|
2018-10-12 20:56:45 +00:00
|
|
|
const notesArray = Object.keys( notes ).map( key => notes[ key ] );
|
|
|
|
const sortedNotesArray = sortBy( notesArray, id => -id );
|
|
|
|
|
2018-07-16 18:37:25 +00:00
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
<ActivityHeader title={ __( 'Inbox', 'wc-admin' ) } />
|
|
|
|
<Section>
|
2018-07-20 18:41:39 +00:00
|
|
|
{ loading ? (
|
|
|
|
<ActivityCardPlaceholder
|
|
|
|
className="woocommerce-inbox-activity-card"
|
|
|
|
hasAction
|
|
|
|
hasDate
|
|
|
|
lines={ 2 }
|
|
|
|
/>
|
|
|
|
) : (
|
2018-10-12 20:56:45 +00:00
|
|
|
sortedNotesArray.map( note => (
|
2018-07-20 18:41:39 +00:00
|
|
|
<ActivityCard
|
2018-10-12 20:56:45 +00:00
|
|
|
key={ note.id }
|
2018-07-20 18:41:39 +00:00
|
|
|
className="woocommerce-inbox-activity-card"
|
2018-10-12 20:56:45 +00:00
|
|
|
title={ note.title }
|
|
|
|
date={ note.date_created }
|
|
|
|
icon={ <Gridicon icon={ note.icon } size={ 48 } /> }
|
|
|
|
unread={ 'unread' === note.status }
|
|
|
|
actions={ getButtonsFromActions( note.actions ) }
|
2018-07-20 18:41:39 +00:00
|
|
|
>
|
2018-10-12 20:56:45 +00:00
|
|
|
<span dangerouslySetInnerHTML={ sanitizeHTML( note.content ) } />
|
2018-07-20 18:41:39 +00:00
|
|
|
</ActivityCard>
|
|
|
|
) )
|
|
|
|
) }
|
2018-07-16 18:37:25 +00:00
|
|
|
</Section>
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-12 19:20:48 +00:00
|
|
|
export default compose(
|
|
|
|
withSelect( select => {
|
|
|
|
const { getNotes } = select( 'wc-admin' );
|
|
|
|
const notes = getNotes();
|
|
|
|
const loading = select( 'core/data' ).isResolving( 'wc-admin', 'getNotes' );
|
|
|
|
return { loading, notes };
|
|
|
|
} )
|
|
|
|
)( InboxPanel );
|