Created
November 15, 2016 10:57
-
-
Save lmatteis/db279e99b56276e4c18b2f0371447404 to your computer and use it in GitHub Desktop.
This file contains hidden or 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, { PropTypes } from 'react'; | |
| import { connect } from 'react-redux'; | |
| import flow from 'lodash/flow'; | |
| import { FormattedMessage } from 'react-intl'; | |
| import { storeToken } from '../actions/securityActions'; | |
| import { resetError } from '../actions/errorsActions'; | |
| import { setCampaign } from '../actions/campaignActions'; | |
| import Modal from '#framework/modules/components/Modal'; | |
| import ModalBody from '#framework/modules/components/ModalBody'; | |
| import Workflow from '#socialads/public/js/models/workflow'; | |
| import { getOAuthToken } from '../helpers/oauthHelpers'; | |
| const propTypes = { | |
| error: PropTypes.string, | |
| campaign: PropTypes.instanceOf(Workflow), | |
| storeToken: PropTypes.func.isRequired, | |
| resetError: PropTypes.func.isRequired, | |
| setCampaign: PropTypes.func.isRequired, | |
| clientId: PropTypes.string.isRequired, | |
| redirectUri: PropTypes.string.isRequired, | |
| }; | |
| const defaultProps = { | |
| error: '', | |
| }; | |
| class ErrorContainer extends React.PureComponent { | |
| constructor(props) { | |
| super(props); | |
| this._handleRenew = this._handleRenew.bind(this); | |
| } | |
| _handleRenew() { | |
| const { storeToken, resetError, setCampaign, clientId, redirectUri, campaign } = this.props; | |
| setCampaign(null); | |
| getOAuthToken({ clientId, redirectUri }) | |
| .then(storeToken) | |
| .then(() => { | |
| resetError(); | |
| setCampaign(campaign) | |
| }); | |
| ; | |
| } | |
| render() { | |
| const { error } = this.props; | |
| return ( | |
| <Modal | |
| closeOnEscape={false} | |
| closeOnBackdropClick={false} | |
| show={Boolean(error)} | |
| attentionAnimation={false} | |
| className="hs-message-modal" | |
| > | |
| <ModalBody> | |
| <div className="hs-message hs-message-renew"> | |
| <h3 className="hs-tit"><FormattedMessage id="hootsuite.authorization.renew" /></h3> | |
| <p className="hs-text"><FormattedMessage id="hootsuite.authorization.renew_body" /></p> | |
| <p className="hs-cta"> | |
| <button className="btn btn-success" onClick={this._handleRenew}><FormattedMessage id="hootsuite.authorization.renew_button" /></button> | |
| </p> | |
| </div> | |
| </ModalBody> | |
| </Modal> | |
| ); | |
| } | |
| } | |
| ErrorContainer.propTypes = propTypes; | |
| ErrorContainer.defaultProps = defaultProps; | |
| function mapStateToProps({ error, campaign: { model } }) { | |
| return { | |
| error, | |
| campaign: model, | |
| }; | |
| } | |
| export default flow( | |
| connect(mapStateToProps, { storeToken, resetError, setCampaign }) | |
| )(ErrorContainer); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment