From a1911bbb082f0b7586823b1210c496679b1131c7 Mon Sep 17 00:00:00 2001 From: cyril lopez Date: Tue, 17 Oct 2017 14:23:28 +0200 Subject: [PATCH] Refacto component PopUpWarning --- .../lib/src/components/PopUpWarning/index.js | 103 ++++++++++-------- 1 file changed, 58 insertions(+), 45 deletions(-) diff --git a/packages/strapi-helper-plugin/lib/src/components/PopUpWarning/index.js b/packages/strapi-helper-plugin/lib/src/components/PopUpWarning/index.js index daf2c87ace..42fc2638eb 100644 --- a/packages/strapi-helper-plugin/lib/src/components/PopUpWarning/index.js +++ b/packages/strapi-helper-plugin/lib/src/components/PopUpWarning/index.js @@ -6,6 +6,7 @@ import React from 'react'; import PropTypes from 'prop-types'; +import { map } from 'lodash'; // modal import { Button, Modal, ModalHeader, ModalBody } from 'reactstrap'; @@ -17,54 +18,66 @@ import IcoSuccess from '../../assets/icons/icon_success.svg'; import IcoWarning from '../../assets/icons/icon_warning.svg'; import styles from './styles.scss'; -class PopUpWarning extends React.Component { // eslint-disable-line react/prefer-stateless-function - constructor(props) { - super(props); +const icons = { + 'danger': IcoDanger, + 'info': IcoInfo, + 'notFound': IcoNotFound, + 'success': IcoSuccess, + 'warning': IcoWarning, +}; - this.icons = { - 'danger': IcoDanger, - 'info': IcoInfo, - 'notFound': IcoNotFound, - 'success': IcoSuccess, - 'warning': IcoWarning, - }; - } +function PopUpWarning({ content, isOpen, onConfirm, onlyConfirmButton, popUpWarningType, toggleModal }) { + const buttons = [ + { + className: styles.secondary, + id: content.cancel || 'components.popUpWarning.button.cancel', + handleClick: toggleModal, + style: {}, + }, + { + className: styles.primary, + id: content.confirm || 'components.popUpWarning.button.confirm', + handleClick: onConfirm, + style: {}, + }, + ]; + const singleButton = [ + { + className: styles.primary, + id: content.confirm || 'components.popUpWarning.button.confirm', + handleClick: onConfirm, + style: { width: '100%' }, + }, + ]; + const footerButtons = onlyConfirmButton ? singleButton : buttons; - render() { - return ( -
- - - - -
- -
- icon - - {(message) => ( -

{message}

- )} + return ( +
+ + + + +
+ +
+ icon + + {(message) => ( +

{message}

+ )} +
+
+
+ {map(footerButtons, (button) => ( + + {(message) => } -
-
- - {(message) => ( - - )} - - - {(message) => ( - - )} - -
-
- - -
- ); - } + ))} +
+ + +
+ ); } PopUpWarning.propTypes = {