2020-03-03 10:26:02 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
import { Notice } from 'wordpress-components';
|
2020-03-10 13:39:21 +00:00
|
|
|
import { useStoreNoticesContext } from '@woocommerce/base-context';
|
2020-03-03 10:26:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import './style.scss';
|
|
|
|
|
|
|
|
const getWooClassName = ( { status = 'default' } ) => {
|
|
|
|
switch ( status ) {
|
|
|
|
case 'error':
|
|
|
|
return 'woocommerce-message woocommerce-error';
|
|
|
|
case 'success':
|
|
|
|
return 'woocommerce-message woocommerce-success';
|
|
|
|
case 'info':
|
|
|
|
case 'warning':
|
|
|
|
return 'woocommerce-message woocommerce-info';
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
};
|
|
|
|
|
|
|
|
const StoreNoticesContainer = ( { className, notices } ) => {
|
|
|
|
const { removeNotice } = useStoreNoticesContext();
|
|
|
|
const wrapperClass = classnames( className, 'wc-block-components-notices' );
|
|
|
|
|
2020-03-05 14:15:28 +00:00
|
|
|
if ( ! notices.length ) {
|
|
|
|
return null;
|
|
|
|
}
|
2020-03-03 10:26:02 +00:00
|
|
|
return (
|
|
|
|
<div className={ wrapperClass }>
|
|
|
|
{ notices.map( ( props ) => (
|
|
|
|
<Notice
|
|
|
|
key={ 'store-notice-' + props.id }
|
|
|
|
{ ...props }
|
|
|
|
className={ classnames(
|
|
|
|
'wc-block-components-notices__notice',
|
|
|
|
getWooClassName( props )
|
|
|
|
) }
|
|
|
|
onRemove={ () => {
|
|
|
|
if ( props.isDismissible ) {
|
|
|
|
removeNotice( props.id );
|
|
|
|
}
|
|
|
|
} }
|
|
|
|
>
|
|
|
|
{ props.content }
|
|
|
|
</Notice>
|
|
|
|
) ) }
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
StoreNoticesContainer.propTypes = {
|
|
|
|
className: PropTypes.string,
|
|
|
|
notices: PropTypes.array,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default StoreNoticesContainer;
|