2019-02-13 11:44:58 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import classnames from 'classnames';
|
|
|
|
import PropTypes from 'prop-types';
|
2021-02-09 15:19:43 +00:00
|
|
|
import { useDispatch, useSelect } from '@wordpress/data';
|
2019-02-13 11:44:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2020-11-09 07:17:08 +00:00
|
|
|
import SnackbarList from './snackbar/list';
|
2019-02-13 11:44:58 +00:00
|
|
|
import './style.scss';
|
|
|
|
|
2021-02-09 15:19:43 +00:00
|
|
|
function TransientNotices( props ) {
|
|
|
|
const { removeNotice: onRemove } = useDispatch( 'core/notices' );
|
|
|
|
const { removeNotice: onRemove2 } = useDispatch( 'core/notices2' );
|
|
|
|
const noticeData = useSelect( ( select ) => {
|
|
|
|
// NOTE: This uses core/notices2, if this file is copied back upstream
|
|
|
|
// to Gutenberg this needs to be changed back to just core/notices.
|
|
|
|
const notices = select( 'core/notices' ).getNotices();
|
|
|
|
const notices2 = select( 'core/notices2' ).getNotices();
|
|
|
|
|
|
|
|
return { notices, notices2 };
|
|
|
|
} );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Combines the two notices in the component vs in the useSelect, as we don't want to
|
|
|
|
* create new object references on each useSelect call.
|
|
|
|
*/
|
|
|
|
const getNotices = () => {
|
|
|
|
const { notices, notices2 = [] } = noticeData;
|
|
|
|
return notices.concat( notices2 );
|
|
|
|
};
|
|
|
|
|
|
|
|
const { className } = props;
|
|
|
|
const classes = classnames(
|
|
|
|
'woocommerce-transient-notices',
|
|
|
|
'components-notices__snackbar',
|
|
|
|
className
|
|
|
|
);
|
|
|
|
const notices = getNotices();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<SnackbarList
|
|
|
|
notices={ notices }
|
|
|
|
className={ classes }
|
|
|
|
onRemove={ onRemove }
|
|
|
|
onRemove2={ onRemove2 }
|
|
|
|
/>
|
|
|
|
);
|
2019-02-13 11:44:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TransientNotices.propTypes = {
|
|
|
|
/**
|
|
|
|
* Additional class name to style the component.
|
|
|
|
*/
|
|
|
|
className: PropTypes.string,
|
|
|
|
/**
|
|
|
|
* Array of notices to be displayed.
|
|
|
|
*/
|
|
|
|
notices: PropTypes.array,
|
|
|
|
};
|
|
|
|
|
2021-02-09 15:19:43 +00:00
|
|
|
export default TransientNotices;
|