2019-07-11 10:12:44 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
2019-08-02 11:56:53 +00:00
|
|
|
import { Fragment } from '@wordpress/element';
|
2019-07-11 10:12:44 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import Gridicon from 'gridicons';
|
|
|
|
import classNames from 'classnames';
|
2019-09-05 15:09:31 +00:00
|
|
|
import { Button, Placeholder, Spinner } from '@wordpress/components';
|
2019-07-11 10:12:44 +00:00
|
|
|
|
2019-08-30 09:36:06 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import ErrorMessage from './error-message.js';
|
|
|
|
import './style.scss';
|
2019-08-02 11:56:53 +00:00
|
|
|
|
|
|
|
const ApiErrorPlaceholder = ( { className, error, isLoading, onRetry } ) => (
|
|
|
|
<Placeholder
|
|
|
|
icon={ <Gridicon icon="notice" /> }
|
|
|
|
label={ __( 'Sorry, an error occurred', 'woo-gutenberg-products-block' ) }
|
|
|
|
className={ classNames( 'wc-block-api-error', className ) }
|
|
|
|
>
|
2019-08-30 09:36:06 +00:00
|
|
|
<ErrorMessage error={ error } />
|
2019-08-02 11:56:53 +00:00
|
|
|
{ onRetry && (
|
|
|
|
<Fragment>
|
|
|
|
{ isLoading ? (
|
|
|
|
<Spinner />
|
|
|
|
) : (
|
|
|
|
<Button isDefault onClick={ onRetry }>
|
|
|
|
{ __( 'Retry', 'woo-gutenberg-products-block' ) }
|
|
|
|
</Button>
|
|
|
|
) }
|
|
|
|
</Fragment>
|
|
|
|
) }
|
|
|
|
</Placeholder>
|
|
|
|
);
|
2019-07-11 10:12:44 +00:00
|
|
|
|
|
|
|
ApiErrorPlaceholder.propTypes = {
|
|
|
|
/**
|
|
|
|
* Classname to add to placeholder in addition to the defaults.
|
|
|
|
*/
|
|
|
|
className: PropTypes.string,
|
2019-08-02 11:56:53 +00:00
|
|
|
/**
|
|
|
|
* The error object.
|
|
|
|
*/
|
|
|
|
error: PropTypes.shape( {
|
|
|
|
/**
|
2019-09-04 16:07:00 +00:00
|
|
|
* Human-readable error message to display.
|
2019-08-02 11:56:53 +00:00
|
|
|
*/
|
2019-09-04 16:07:00 +00:00
|
|
|
message: PropTypes.node,
|
2019-08-02 11:56:53 +00:00
|
|
|
/**
|
2019-09-04 16:07:00 +00:00
|
|
|
* Context in which the error was triggered. That will determine how the error is displayed to the user.
|
2019-08-02 11:56:53 +00:00
|
|
|
*/
|
2019-09-04 16:07:00 +00:00
|
|
|
type: PropTypes.oneOf( [ 'api', 'general' ] ),
|
2019-08-02 11:56:53 +00:00
|
|
|
} ),
|
|
|
|
/**
|
|
|
|
* Whether there is a request running, so the 'Retry' button is hidden and
|
|
|
|
* a spinner is shown instead.
|
|
|
|
*/
|
|
|
|
isLoading: PropTypes.bool,
|
2019-08-27 09:38:41 +00:00
|
|
|
/**
|
|
|
|
* Callback to retry an action.
|
|
|
|
*/
|
|
|
|
onRetry: PropTypes.func,
|
2019-07-11 10:12:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default ApiErrorPlaceholder;
|