2019-01-30 16:15:44 -08:00
|
|
|
// @flow
|
2019-02-04 20:41:45 -08:00
|
|
|
|
2019-01-30 16:15:44 -08:00
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
import { createPortal } from 'react-dom';
|
|
|
|
import styled from 'styled-components';
|
|
|
|
|
|
|
|
import { TextComponent } from './text';
|
|
|
|
import { Button } from './button';
|
|
|
|
|
2019-02-16 19:34:12 -08:00
|
|
|
import ErrorIcon from '../assets/images/error_icon_dark.png';
|
2019-01-30 16:15:44 -08:00
|
|
|
|
|
|
|
const ModalWrapper = styled.div`
|
|
|
|
width: 100vw;
|
|
|
|
height: 100vh;
|
|
|
|
position: fixed;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
background-color: rgba(0, 0, 0, 0.5);
|
|
|
|
`;
|
|
|
|
|
|
|
|
const ChildrenWrapper = styled.div`
|
|
|
|
width: 350px;
|
2019-02-07 08:31:59 -08:00
|
|
|
background-color: ${props => props.theme.colors.background};
|
2019-01-30 16:15:44 -08:00
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
border-radius: 6px;
|
|
|
|
box-shadow: 0px 0px 30px 0px black;
|
|
|
|
position: relative;
|
|
|
|
z-index: 90;
|
|
|
|
min-height: 400px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const Message = styled(TextComponent)`
|
|
|
|
margin: 15px 0;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const ErrorImage = styled.img`
|
|
|
|
width: 35px;
|
|
|
|
height: 35px;
|
|
|
|
margin-bottom: 15px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
isVisible: boolean,
|
|
|
|
message: string,
|
|
|
|
onRequestClose: () => void,
|
|
|
|
};
|
|
|
|
|
|
|
|
const modalRoot = document.getElementById('modal-root');
|
|
|
|
|
|
|
|
export class ErrorModalComponent extends PureComponent<Props> {
|
|
|
|
element = document.createElement('div');
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
const { isVisible } = this.props;
|
|
|
|
|
|
|
|
if (isVisible) {
|
|
|
|
if (modalRoot) modalRoot.appendChild(this.element);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate = (prevProps: Props) => {
|
|
|
|
const { isVisible } = this.props;
|
|
|
|
|
|
|
|
if (!prevProps.isVisible && isVisible) {
|
|
|
|
if (modalRoot) modalRoot.appendChild(this.element);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prevProps.isVisible && !isVisible) {
|
|
|
|
if (modalRoot) modalRoot.removeChild(this.element);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { isVisible, message, onRequestClose } = this.props;
|
|
|
|
|
2019-02-06 19:06:48 -08:00
|
|
|
return !isVisible
|
|
|
|
? null
|
|
|
|
: createPortal(
|
|
|
|
<ModalWrapper id='error-modal-portal-wrapper'>
|
|
|
|
<ChildrenWrapper>
|
|
|
|
<ErrorImage src={ErrorIcon} alt='Error Icon' />
|
|
|
|
<Message value={message} />
|
|
|
|
<Button label='Ok!' onClick={onRequestClose} />
|
|
|
|
</ChildrenWrapper>
|
|
|
|
</ModalWrapper>,
|
|
|
|
this.element,
|
|
|
|
);
|
2019-01-30 16:15:44 -08:00
|
|
|
}
|
|
|
|
}
|