From 16435925b6bc0d2e39e64840915fa8b818a66bfe Mon Sep 17 00:00:00 2001 From: LautaroCesso <59095036+LautaroCesso@users.noreply.github.com> Date: Wed, 18 Nov 2020 11:47:38 -0300 Subject: [PATCH] Group params of open modal function (#935) * Agrupate params of open modal function * Add white color prop in modal componenet --- client/src/app-components/are-you-sure.js | 46 +++++++------------ client/src/app-components/modal-container.js | 19 +++++--- client/src/app-components/popup-message.js | 24 +++++----- .../settings/admin-panel-advanced-settings.js | 39 ++++++---------- client/src/core-components/modal.js | 19 ++++---- client/src/core-components/modal.scss | 4 ++ client/src/reducers/modal-reducer.js | 38 +++++++++------ 7 files changed, 94 insertions(+), 95 deletions(-) diff --git a/client/src/app-components/are-you-sure.js b/client/src/app-components/are-you-sure.js index e3d3d266..a69a2ec8 100644 --- a/client/src/app-components/are-you-sure.js +++ b/client/src/app-components/are-you-sure.js @@ -5,10 +5,8 @@ import ModalContainer from 'app-components/modal-container'; import Button from 'core-components/button'; import Input from 'core-components/input'; -import Icon from 'core-components/icon'; import Loading from 'core-components/loading' - class AreYouSure extends React.Component { static propTypes = { description: React.PropTypes.node, @@ -31,8 +29,8 @@ class AreYouSure extends React.Component { static openModal(description, onYes, type = 'default') { ModalContainer.openModal( - , - true + , + {noPadding: true, closeButton: {showCloseButton: true, whiteColor: true}} ); } @@ -42,18 +40,17 @@ class AreYouSure extends React.Component { render() { const { loading } = this.state; + const { description, type } = this.props; + return (
{i18n('ARE_YOU_SURE')}
- - -
- {this.props.description || (this.props.type === 'secure' && i18n('PLEASE_CONFIRM_PASSWORD'))} + {description || (type === 'secure' && i18n('PLEASE_CONFIRM_PASSWORD'))}
- {(this.props.type === 'secure') ? this.renderPassword() : null} + {(type === 'secure') ? this.renderPassword() : null}
@@ -68,9 +65,8 @@ class AreYouSure extends React.Component { onClick={this.onYes.bind(this)} ref="yesButton" tabIndex="2" - disabled={loading} - > - {loading ? : i18n('YES')} + disabled={loading}> + {loading ? : i18n('YES')}
@@ -79,10 +75,8 @@ class AreYouSure extends React.Component { } renderPassword() { - const { - password, - loading - } = this.state; + const { password, loading } = this.state; + return ( + disabled={loading} /> ); } @@ -112,13 +105,8 @@ class AreYouSure extends React.Component { } onYes() { - const { - password, - } = this.state; - const { - type, - onYes - } = this.props; + const { password } = this.state; + const { type, onYes } = this.props; if(type === 'secure' && !password) { this.refs.password.focus() @@ -166,10 +154,10 @@ class AreYouSure extends React.Component { } closeModal() { - if (this.context.closeModal) { - this.context.closeModal(); - } + const { closeModal } = this.context; + + closeModal && closeModal(); } } -export default AreYouSure; \ No newline at end of file +export default AreYouSure; diff --git a/client/src/app-components/modal-container.js b/client/src/app-components/modal-container.js index 78aab32a..c1e8f03e 100644 --- a/client/src/app-components/modal-container.js +++ b/client/src/app-components/modal-container.js @@ -8,13 +8,14 @@ import Modal from 'core-components/modal'; class ModalContainer extends React.Component { - static openModal(content, noPadding, outsideClick=false, showCloseButton=false) { + static openModal( + content, + options={noPadding: false, outsideClick: false, closeButton: {showCloseButton: false, whiteColor: false}} + ) { store.dispatch( ModalActions.openModal({ content, - noPadding, - outsideClick, - showCloseButton + options }) ); } @@ -50,10 +51,16 @@ class ModalContainer extends React.Component { } renderModal() { - const {content, noPadding, outsideClick, showCloseButton} = this.props.modal; + const { content, options } = this.props.modal; + const { noPadding, outsideClick, closeButton } = options; return ( - + ); } diff --git a/client/src/app-components/popup-message.js b/client/src/app-components/popup-message.js index 85198329..bd1e14ab 100644 --- a/client/src/app-components/popup-message.js +++ b/client/src/app-components/popup-message.js @@ -1,10 +1,8 @@ import React from 'react'; -import i18n from 'lib-app/i18n'; import ModalContainer from 'app-components/modal-container'; import Button from 'core-components/button'; -import Icon from 'core-components/icon'; import Message from 'core-components/message'; @@ -17,9 +15,8 @@ class PopupMessage extends React.Component { static open(props) { ModalContainer.openModal( - , - true, - true + , + {noPadding: true, outsideClick: true} ); } @@ -30,17 +27,22 @@ class PopupMessage extends React.Component { render() { return (
- -
); } closeModal() { - if (this.context.closeModal) { - this.context.closeModal(); - } + const { closeModal } = this.context; + + closeModal && closeModal(); } } -export default PopupMessage; \ No newline at end of file +export default PopupMessage; diff --git a/client/src/app/admin/panel/settings/admin-panel-advanced-settings.js b/client/src/app/admin/panel/settings/admin-panel-advanced-settings.js index 096ba5c9..808c1e18 100644 --- a/client/src/app/admin/panel/settings/admin-panel-advanced-settings.js +++ b/client/src/app/admin/panel/settings/admin-panel-advanced-settings.js @@ -36,11 +36,7 @@ class AdminPanelAdvancedSettings extends React.Component { render() { const { config } = this.props; - const { - messageType, - error, - selectedAPIKey - } = this.state; + const { messageType, error, selectedAPIKey } = this.state; return (
@@ -106,11 +102,7 @@ class AdminPanelAdvancedSettings extends React.Component { } renderMessage() { - const { - messageType, - messageTitle, - messageContent - } = this.state; + const { messageType, messageTitle, messageContent } = this.state; return ( @@ -128,10 +120,7 @@ class AdminPanelAdvancedSettings extends React.Component { } renderKey() { - const { - APIKeys, - selectedAPIKey - } = this.state; + const { APIKeys, selectedAPIKey } = this.state; const { name, token, @@ -203,17 +192,21 @@ class AdminPanelAdvancedSettings extends React.Component { {i18n('SUBMIT')}
, - null, - null, - true + { + closeButton: { + showCloseButton: true + } + } ); } addAPIKey({name,userPermission,createTicketPermission,checkTicketPermission,ticketNumberPermission}) { ModalContainer.closeModal(); + this.setState({ error: '' - }) + }); + API.call({ path: '/system/add-api-key', data: { @@ -266,10 +259,7 @@ class AdminPanelAdvancedSettings extends React.Component { } onAreYouSureMandatoryLoginOk(password) { - const { - config, - dispatch - } = this.props; + const { config, dispatch } = this.props; return API.call({ path: config['mandatory-login'] ? '/system/disable-mandatory-login' : '/system/enable-mandatory-login', @@ -287,10 +277,7 @@ class AdminPanelAdvancedSettings extends React.Component { } onAreYouSureRegistrationOk(password) { - const { - config, - dispatch - } = this.props; + const { config, dispatch } = this.props; return API.call({ path: config['registration'] ? '/system/disable-registration' : '/system/enable-registration', diff --git a/client/src/core-components/modal.js b/client/src/core-components/modal.js index a4dea955..ded83674 100644 --- a/client/src/core-components/modal.js +++ b/client/src/core-components/modal.js @@ -5,13 +5,18 @@ import {Motion, spring} from 'react-motion'; import Icon from 'core-components/icon'; +const closeButtonSchema = React.PropTypes.shape({ + showCloseButton: React.PropTypes.bool, + whiteColor: React.PropTypes.bool +}); + class Modal extends React.Component { static propTypes = { content: React.PropTypes.node, noPadding: React.PropTypes.bool, outsideClick: React.PropTypes.bool, onOutsideClick: React.PropTypes.func, - showCloseButton: React.PropTypes.bool + closeButton: closeButtonSchema }; render() { @@ -36,24 +41,22 @@ class Modal extends React.Component { } renderModal(animation) { - const { - showCloseButton, - content - } = this.props; + const { closeButton, content } = this.props; + const { showCloseButton, whiteColor } = closeButton; return (
- {showCloseButton ? this.renderCloseButton() : null} + {showCloseButton ? this.renderCloseButton(whiteColor) : null} {content}
) } - renderCloseButton() { + renderCloseButton(whiteColor = false) { return ( - this.props.onOutsideClick()}> + this.props.onOutsideClick()}> ); diff --git a/client/src/core-components/modal.scss b/client/src/core-components/modal.scss index 47d63a74..38c1d920 100644 --- a/client/src/core-components/modal.scss +++ b/client/src/core-components/modal.scss @@ -31,5 +31,9 @@ position: absolute; top: 10px; right: 10px; + + &__white-color { + color: white; + } } } diff --git a/client/src/reducers/modal-reducer.js b/client/src/reducers/modal-reducer.js index 7bb1054f..48ca7ef5 100644 --- a/client/src/reducers/modal-reducer.js +++ b/client/src/reducers/modal-reducer.js @@ -7,10 +7,15 @@ class ModalReducer extends Reducer { getInitialState() { return { opened: false, - noPadding: false, content: null, - outsideClick: false, - showCloseButton: false + options: { + noPadding: false, + outsideClick: false, + closeButton: { + showCloseButton: false, + whiteColor: false + } + } }; } @@ -22,21 +27,19 @@ class ModalReducer extends Reducer { } onOpenModal(state, payload) { - const { - content, - noPadding, - outsideClick, - showCloseButton - } = payload; + const { content, options } = payload; + const { noPadding, outsideClick, closeButton } = options; document.body.setAttribute('style', 'overflow:hidden'); return _.extend({}, state, { opened: true, content, - noPadding: noPadding || false, - outsideClick, - showCloseButton + options: { + noPadding: noPadding || false, + outsideClick, + closeButton + } }); } @@ -46,9 +49,14 @@ class ModalReducer extends Reducer { return _.extend({}, state, { opened: false, content: null, - noPadding: false, - outsideClick: false, - showCloseButton: false + options: { + noPadding: false, + outsideClick: false, + closeButton: { + showCloseButton: false, + whiteColor: false + } + } }); } }