From ed4ffd92a98445598eec3ec3bd232c63d5380428 Mon Sep 17 00:00:00 2001 From: George Lima Date: Wed, 30 Jan 2019 21:15:44 -0300 Subject: [PATCH 1/7] feat(error-modal): add ErrorModalComponent --- app/components/error-modal.js | 94 +++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 app/components/error-modal.js diff --git a/app/components/error-modal.js b/app/components/error-modal.js new file mode 100644 index 0000000..94f9ae0 --- /dev/null +++ b/app/components/error-modal.js @@ -0,0 +1,94 @@ +// @flow +import React, { PureComponent } from 'react'; +import { createPortal } from 'react-dom'; +import styled from 'styled-components'; + +import { TextComponent } from './text'; +import { Button } from './button'; + +import ErrorIcon from '../assets/images/error_icon.png'; + +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; + background-color: ${props => props.theme.colors.background}; + 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 { + 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; + + return isVisible + ? createPortal( + + + + +