woocommerce/plugins/woocommerce-admin/client/header/activity-panel/panels/inbox.js

86 lines
2.2 KiB
JavaScript
Raw Normal View History

/** @format */
/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { Button } from '@wordpress/components';
import { Component, Fragment } from '@wordpress/element';
2018-10-12 19:20:48 +00:00
import { compose } from '@wordpress/compose';
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';
/**
* Internal dependencies
*/
import { ActivityCard, ActivityCardPlaceholder } from '../activity-card';
import ActivityHeader from '../activity-header';
import sanitizeHTML from 'lib/sanitize-html';
import { Section } from '@woocommerce/components';
class InboxPanel extends Component {
render() {
2018-10-16 19:46:00 +00:00
const { isRequesting, notes } = this.props;
2018-10-12 19:20:48 +00:00
const getButtonsFromActions = actions => {
if ( ! actions ) {
return [];
}
return actions.map( action => (
<Button disabled 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 );
return (
<Fragment>
<ActivityHeader title={ __( 'Inbox', 'wc-admin' ) } />
<Section>
2018-10-16 19:46:00 +00:00
{ isRequesting ? (
<ActivityCardPlaceholder
className="woocommerce-inbox-activity-card"
hasAction
hasDate
lines={ 2 }
/>
) : (
2018-10-12 20:56:45 +00:00
sortedNotesArray.map( note => (
<ActivityCard
2018-10-12 20:56:45 +00:00
key={ note.id }
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-10-12 20:56:45 +00:00
<span dangerouslySetInnerHTML={ sanitizeHTML( note.content ) } />
</ActivityCard>
) )
) }
</Section>
</Fragment>
);
}
}
2018-10-12 19:20:48 +00:00
export default compose(
withSelect( select => {
2018-10-16 19:46:00 +00:00
const { getNotes, isGetNotesError, isGetNotesRequesting } = select( 'wc-admin' );
const inboxQuery = {
page: 1,
per_page: 25,
};
const notes = getNotes( inboxQuery );
const isError = isGetNotesError( inboxQuery );
const isRequesting = isGetNotesRequesting( inboxQuery );
return { notes, isError, isRequesting };
2018-10-12 19:20:48 +00:00
} )
)( InboxPanel );