All files / src/components/ErrorPage index.jsx

100% Statements 10/10
100% Branches 8/8
100% Functions 3/3
100% Lines 10/10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48                2x 3x   3x               3x 2x     1x       3x 2x     1x       2x                        
import styles from './style.postcss';
 
import React from 'react';
import { pure } from 'recompose';
import is from 'is_js';
import Icon from 'components/Icon';
import PropTypes from 'prop-types';
 
export const ErrorPage = (props) => {
  const { config } = props;
 
  return <div className={styles.ErrorPage}>
    <div className={styles.ErrorPage_content}>
      <Icon className={styles.ErrorPage_image} id={renderIcon()} />
      <div className={styles.ErrorPage_text}>{renderMessage()}</div>
    </div>
  </div>;
 
  function renderIcon() {
    if (is.not.object(config) || is.not.function(config.icon)) {
      return 'warning';
    }
 
    return config.icon(props);
  }
 
  function renderMessage() {
    if (is.not.object(config) || is.not.function(config.message)) {
      return 'Omni could not load this page.';
    }
 
    return config.message(props);
  }
};
 
ErrorPage.propTypes = {
  replace: PropTypes.func.isRequired,
  location: PropTypes.shape({
    pathname: PropTypes.string.isRequired,
  }).isRequired,
  config: PropTypes.shape({
    icon: PropTypes.func,
    message: PropTypes.func,
  }),
};
 
export default pure(ErrorPage);