Skip to content

Commit

Permalink
fix(harvest): Use the same 2FA Modal for Trigger Manager/Launcher
Browse files Browse the repository at this point in the history
  • Loading branch information
CPatchane committed May 6, 2019
1 parent 0a67664 commit 701c610
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 126 deletions.
20 changes: 15 additions & 5 deletions packages/cozy-harvest-lib/src/components/TriggerLauncher.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types'

import { withMutations } from 'cozy-client'

import TwoFAModal from './TwoFA/Modal'
import TwoFAForm from './TwoFAForm'
import { accountsMutations } from '../connections/accounts'
import { triggersMutations } from '../connections/triggers'

Expand All @@ -17,6 +17,7 @@ const TWO_FA_REQUEST = 'TWO_FA_REQUEST'
const TWO_FA_MISMATCH = 'TWO_FA_MISMATCH'
const PENDING = 'PENDING'
const SUCCESS = 'SUCCESS'
const RUNNING_TWOFA = 'RUNNING_TWOFA'

/**
* Trigger Launcher renders its children with following props:
Expand Down Expand Up @@ -46,6 +47,7 @@ export class TriggerLauncher extends Component {

this.launch = this.launch.bind(this)
this.handleTwoFAModalDismiss = this.handleTwoFAModalDismiss.bind(this)
this.handle2FACode = this.handle2FACode.bind(this)
this.handleError = this.handleError.bind(this)
this.handleSuccess = this.handleSuccess.bind(this)
this.handleLoginSuccess = this.handleLoginSuccess.bind(this)
Expand Down Expand Up @@ -77,6 +79,11 @@ export class TriggerLauncher extends Component {
this.setState({ status: TWO_FA_MISMATCH, showTwoFAModal: true })
}

handle2FACode(code) {
this.setState({ status: RUNNING_TWOFA })
this.konnectorJob.sendTwoFACode(code)
}

async launch() {
const { trigger } = this.props
const { client } = this.context
Expand All @@ -95,7 +102,7 @@ export class TriggerLauncher extends Component {

render() {
const { showTwoFAModal, status } = this.state
const { children, submitting } = this.props
const { account, children, konnector, submitting } = this.props

return (
<div>
Expand All @@ -104,10 +111,13 @@ export class TriggerLauncher extends Component {
running: ![ERRORED, IDLE, SUCCESS].includes(status) || submitting
})}
{showTwoFAModal && (
<TwoFAModal
<TwoFAForm
account={account}
konnector={konnector}
dismissAction={this.handleTwoFAModalDismiss}
hasError={status === TWO_FA_MISMATCH}
onSubmit={this.konnectorJob.sendTwoFACode}
handleSubmitTwoFACode={this.handle2FACode}
submitting={status === RUNNING_TWOFA}
retryAsked={status === TWO_FA_MISMATCH}
into="coz-harvest-modal-place"
/>
)}
Expand Down
121 changes: 0 additions & 121 deletions packages/cozy-harvest-lib/src/components/TwoFA/Modal.jsx

This file was deleted.

0 comments on commit 701c610

Please sign in to comment.