Last active
May 21, 2018 13:44
-
-
Save nickydonna/93dbf46aa18fdddd77bdee42b5728057 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {Component, Fragment} from 'react'; | |
import { Modal, ModalBody, ModalHeader, ModalFooter, Button } from 'reactstrap'; | |
/* eslint react/jsx-filename-extension: 0 */ | |
const ErrorModal = ({error}) => ( | |
<Modal isOpen={showError} toggle={toggleError}> | |
<ModalHeader toggle={toggleError}>Felicitaciones</ModalHeader> | |
<ModalBody> | |
<div className="col-md-6 offset-md-3"> | |
{error} | |
</div> | |
</ModalBody> | |
<ModalFooter> | |
<Button color="primary" onClick={() => toggleError()}>OK</Button> | |
</ModalFooter> | |
</Modal> | |
); | |
const DoneModal = ({message}) => ( | |
<Modal isOpen={showDone} toggle={toggleDone}> | |
<ModalHeader toggle={toggleDone}>Felicitaciones</ModalHeader> | |
<ModalBody> | |
<div className="col-md-6 offset-md-3"> | |
{message} | |
</div> | |
</ModalBody> | |
<ModalFooter> | |
<Button color="primary" onClick={() => toggleDone()}>OK</Button> | |
</ModalFooter> | |
</Modal> | |
); | |
const defaultState = { | |
doneMessage: undefined, | |
error: undefined, | |
}; | |
const withModal = Component => { | |
class WithModal extends Component { | |
this.state = defaultState; | |
showModals(doneMessage, error) { | |
this.setState({doneMessage, error}); | |
} | |
hideModals() { | |
this.setState(defaultState); | |
} | |
render() { | |
const {doneMessage, error} = this.state; | |
return ( | |
<Fragment> | |
<Component {...this.props} showModals={this.showModals} hideModals={this.hideModals} /> | |
{doneMessage && <DoneModal message={doneMessage} />} | |
{error && <ErrorModal error={error} />} | |
</Fragment> | |
) | |
} | |
} | |
WithModal.displayName = `WithModal(${Component.displayName || Component.name}`; | |
return WithModal; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment