Skip to content

Commit

Permalink
feat(harvest-lib): Add missing props to new Account modal
Browse files Browse the repository at this point in the history
  • Loading branch information
Merkur39 committed Jan 25, 2023
1 parent 393e87c commit 6e23453
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ import TriggerError from './TriggerError'

const AccountModalContentWrapper = ({ children }) => {
const { isMobile } = useBreakpoints()
const { trigger, account, konnector } = useOutletContext()
const {
konnector,
account,
trigger,
intentsApi,
innerAccountModalOverrides
} = useOutletContext()

return (
<DialogContent className={isMobile ? 'u-p-0' : 'u-pt-0'}>
Expand All @@ -21,10 +27,17 @@ const AccountModalContentWrapper = ({ children }) => {
konnector={konnector}
account={account}
trigger={trigger}
intentsApi={intentsApi}
/>
{React.Children.map(children, child =>
React.isValidElement(child)
? React.cloneElement(child, { flow, trigger, account })
? React.cloneElement(child, {
flow,
account,
trigger,
intentsApi,
innerAccountModalOverrides
})
: null
)}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ import { withMountPointProps } from '../MountPointContext'
import { getMatchingTrigger } from './helpers'
import AccountModalHeader from './AccountModalHeader'
import Error from './Error'
import {
innerAccountModalOverridesProptype,
intentsApiProptype
} from '../../helpers/proptypes'

const AccountModalWithoutTabs = ({
accountsAndTriggers,
konnector,
accountId
accountId,
intentsApi,
innerAccountModalOverrides
}) => {
const matchingTrigger = getMatchingTrigger(accountsAndTriggers, accountId)
const matchingAccountId = matchingTrigger ? accountId : undefined
Expand Down Expand Up @@ -57,7 +63,15 @@ const AccountModalWithoutTabs = ({
</DialogContent>
)}
{!isError && !isLoading && (
<Outlet context={{ trigger: matchingTrigger, account, konnector }} />
<Outlet
context={{
trigger: matchingTrigger,
account,
konnector,
intentsApi,
innerAccountModalOverrides
}}
/>
)}
</>
)
Expand All @@ -74,7 +88,9 @@ AccountModalWithoutTabs.propTypes = {
trigger: PropTypes.object.isRequired
})
).isRequired,
accountId: PropTypes.string.isRequired
accountId: PropTypes.string.isRequired,
intentsApi: intentsApiProptype,
innerAccountModalOverrides: innerAccountModalOverridesProptype
}

export default withMountPointProps(AccountModalWithoutTabs)
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import React from 'react'
import PropTypes from 'prop-types'
import DialogContent from '@material-ui/core/DialogContent'

import useBreakpoints from 'cozy-ui/transpiled/react/hooks/useBreakpoints'

import FlowProvider from '../../FlowProvider'
import TriggerError from '../TriggerError'
import {
innerAccountModalOverridesProptype,
intentsApiProptype
} from '../../../helpers/proptypes'

const AccountModalContentWrapper = ({
children,
trigger,
account,
konnector
konnector,
intentsApi,
innerAccountModalOverrides
}) => {
const { isMobile } = useBreakpoints()

Expand All @@ -24,10 +31,17 @@ const AccountModalContentWrapper = ({
konnector={konnector}
account={account}
trigger={trigger}
intentsApi={intentsApi}
/>
{React.Children.map(children, child =>
React.isValidElement(child)
? React.cloneElement(child, { flow, trigger, account })
? React.cloneElement(child, {
flow,
account,
trigger,
intentsApi,
innerAccountModalOverrides
})
: null
)}
</>
Expand All @@ -37,4 +51,12 @@ const AccountModalContentWrapper = ({
)
}

AccountModalContentWrapper.propTypes = {
konnector: PropTypes.object.isRequired,
trigger: PropTypes.object.isRequired,
account: PropTypes.object.isRequired,
intentsApi: intentsApiProptype,
innerAccountModalOverrides: innerAccountModalOverridesProptype
}

export default AccountModalContentWrapper
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@ import { withMountPointProps } from '../../MountPointContext'
import { getMatchingTrigger } from '../helpers'
import AccountModalHeader from '../AccountModalHeader'
import Error from '../Error'
import {
innerAccountModalOverridesProptype,
intentsApiProptype
} from '../../../helpers/proptypes'

const AccountModalWithoutTabs = ({
accountsAndTriggers,
konnector,
accountId,
intentsApi,
innerAccountModalOverrides,
children
}) => {
const matchingTrigger = getMatchingTrigger(accountsAndTriggers, accountId)
Expand Down Expand Up @@ -63,7 +69,9 @@ const AccountModalWithoutTabs = ({
? React.cloneElement(child, {
trigger: matchingTrigger,
account,
konnector
konnector,
intentsApi,
innerAccountModalOverrides
})
: null
)}
Expand All @@ -82,7 +90,9 @@ AccountModalWithoutTabs.propTypes = {
trigger: PropTypes.object.isRequired
})
).isRequired,
accountId: PropTypes.string.isRequired
accountId: PropTypes.string.isRequired,
intentsApi: intentsApiProptype,
innerAccountModalOverrides: innerAccountModalOverridesProptype
}

export default withMountPointProps(AccountModalWithoutTabs)
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import flag from 'cozy-flags'
import { useClient } from 'cozy-client'
import { useI18n } from 'cozy-ui/transpiled/react/I18n'
import { Button } from 'cozy-ui/transpiled/react/Button'
import { useWebviewIntent } from 'cozy-intent'

import useOAuthExtraParams from '../hooks/useOAuthExtraParams'
import { OAUTH_SERVICE_OK, openOAuthWindow } from '../OAuthService'
import { intentsApiProptype } from '../../helpers/proptypes'

const OpenOAuthWindowButton = ({ flow, account, konnector }) => {
const OpenOAuthWindowButton = ({ flow, account, konnector, intentsApi }) => {
const { t } = useI18n()
const client = useClient()
const webviewIntent = useWebviewIntent()

const { extraParams } = useOAuthExtraParams({
account,
Expand All @@ -26,6 +29,8 @@ const OpenOAuthWindowButton = ({ flow, account, konnector }) => {
konnector,
account,
extraParams,
intentsApi,
webviewIntent,
reconnect: true
})

Expand All @@ -35,7 +40,7 @@ const OpenOAuthWindowButton = ({ flow, account, konnector }) => {
) {
flow.expectTriggerLaunch()
}
}, [account, client, extraParams, flow, konnector])
}, [account, client, extraParams, flow, konnector, webviewIntent, intentsApi])

return (
<Button
Expand All @@ -52,7 +57,8 @@ const OpenOAuthWindowButton = ({ flow, account, konnector }) => {
OpenOAuthWindowButton.propTypes = {
flow: PropTypes.object.isRequired,
account: PropTypes.object.isRequired,
konnector: PropTypes.object.isRequired
konnector: PropTypes.object.isRequired,
intentsApi: intentsApiProptype
}

export default OpenOAuthWindowButton
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import { useClient } from 'cozy-client'
import useMaintenanceStatus from '../hooks/useMaintenanceStatus'
import TriggerErrorInfo from '../infos/TriggerErrorInfo'
import TriggerErrorAction from './TriggerErrorAction'
import { intentsApiProptype } from '../../helpers/proptypes'

const TriggerError = ({ flow, konnector, account, trigger }) => {
const TriggerError = ({ flow, konnector, account, trigger, intentsApi }) => {
const client = useClient()
const flowState = flow.getState()
const { error } = flowState
Expand All @@ -29,6 +30,7 @@ const TriggerError = ({ flow, konnector, account, trigger }) => {
konnector={konnector}
account={account}
trigger={trigger}
intentsApi={intentsApi}
/>
}
className="u-mt-1"
Expand All @@ -42,5 +44,6 @@ TriggerError.propTypes = {
flow: PropTypes.object.isRequired,
konnector: PropTypes.object.isRequired,
account: PropTypes.object,
trigger: PropTypes.object
trigger: PropTypes.object,
intentsApi: intentsApiProptype
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@ import PropTypes from 'prop-types'
import { findKonnectorPolicy } from '../../konnector-policies'
import RedirectToAccountFormButton from '../RedirectToAccountFormButton'
import OpenOAuthWindowButton from './OpenOAuthWindowButton'
import { intentsApiProptype } from '../../helpers/proptypes'

const TriggerErrorAction = ({ flow, konnector, account, trigger, error }) => {
const TriggerErrorAction = ({
flow,
konnector,
account,
trigger,
error,
intentsApi
}) => {
const konnectorPolicy = findKonnectorPolicy(konnector)

if (!error.isSolvableViaReconnect()) return null
Expand All @@ -16,6 +24,7 @@ const TriggerErrorAction = ({ flow, konnector, account, trigger, error }) => {
flow={flow}
account={account}
konnector={konnector}
intentsApi={intentsApi}
/>
)

Expand All @@ -27,7 +36,8 @@ TriggerErrorAction.propTypes = {
konnector: PropTypes.object.isRequired,
account: PropTypes.object,
trigger: PropTypes.object,
error: PropTypes.object.isRequired
error: PropTypes.object.isRequired,
intentsApi: intentsApiProptype
}

export default TriggerErrorAction

0 comments on commit 6e23453

Please sign in to comment.