summaryrefslogtreecommitdiffstats
path: root/components/ErrorMessage.js
blob: 12de51d86dbc670b9b5aa23f61c6740911ed283f (plain)
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
import styled from 'styled-components';
import React from 'react';

import PropTypes from 'prop-types';

const StyledError = styled.div`
  background: pink;
  border: 2px solid red;
  padding: 20px;
  display: flex;
  p {
    margin: 0;
    flex: 1 0 auto;
  }
`;

const DisplayError = props => {
  if (!props.error || !props.error.message) return null;
  return (
    <StyledError>
      <p>{props.error.message}</p>
      <button onClick={props.onButtonClick}>&times;</button>
    </StyledError>
  );
};

DisplayError.propTypes = {
  error: PropTypes.object.isRequired,
  onButtonClick: PropTypes.func.isRequired,
};

export default DisplayError;