Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(harvest): Add
/config
route on routerV4 and remove tabs
as we do on router v6. Some duplicated code between v4 and v6 but it's the simpliest way to do it. Since the v4 is almost deprecated (Home should be update with v6 soon), there will be no reason to keep this code anymore
- Loading branch information
Showing
3 changed files
with
202 additions
and
14 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
...est-lib/src/components/AccountModalWithoutTabs/FovV4Router/AccountModalContentWrapper.jsx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React from 'react' | ||
import DialogContent from '@material-ui/core/DialogContent' | ||
|
||
import useBreakpoints from 'cozy-ui/transpiled/react/hooks/useBreakpoints' | ||
|
||
import FlowProvider from '../../FlowProvider' | ||
import TriggerError from '../TriggerError' | ||
|
||
const AccountModalContentWrapper = ({ | ||
children, | ||
trigger, | ||
account, | ||
konnector | ||
}) => { | ||
const { isMobile } = useBreakpoints() | ||
|
||
return ( | ||
<DialogContent className={isMobile ? 'u-p-0' : 'u-pt-0'}> | ||
<FlowProvider initialTrigger={trigger} konnector={konnector}> | ||
{({ flow }) => ( | ||
<> | ||
<TriggerError | ||
flow={flow} | ||
konnector={konnector} | ||
account={account} | ||
trigger={trigger} | ||
/> | ||
{React.Children.map(children, child => | ||
React.isValidElement(child) | ||
? React.cloneElement(child, { flow, trigger, account }) | ||
: null | ||
)} | ||
</> | ||
)} | ||
</FlowProvider> | ||
</DialogContent> | ||
) | ||
} | ||
|
||
export default AccountModalContentWrapper |
88 changes: 88 additions & 0 deletions
88
...arvest-lib/src/components/AccountModalWithoutTabs/FovV4Router/AccountModalWithoutTabs.jsx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import DialogContent from '@material-ui/core/DialogContent' | ||
|
||
import { useQuery, isQueryLoading } from 'cozy-client' | ||
import Spinner from 'cozy-ui/transpiled/react/Spinner' | ||
|
||
import { buildAccountQueryById } from '../../../connections/accounts' | ||
import { withMountPointProps } from '../../MountPointContext' | ||
import { getMatchingTrigger } from '../helpers' | ||
import AccountModalHeader from '../AccountModalHeader' | ||
import Error from '../Error' | ||
|
||
const AccountModalWithoutTabs = ({ | ||
accountsAndTriggers, | ||
konnector, | ||
accountId, | ||
children | ||
}) => { | ||
const matchingTrigger = getMatchingTrigger(accountsAndTriggers, accountId) | ||
const matchingAccountId = matchingTrigger ? accountId : undefined | ||
|
||
const { definition, options } = buildAccountQueryById(matchingAccountId) | ||
const { data: accounts, ...accountQueryResult } = useQuery( | ||
definition, | ||
options | ||
) | ||
|
||
const isLoading = | ||
isQueryLoading(accountQueryResult) || accountQueryResult.hasMore | ||
|
||
const isError = | ||
!isLoading && (!matchingTrigger || !accounts || accounts?.length === 0) | ||
|
||
const account = accounts?.[0] | ||
|
||
return ( | ||
<> | ||
<AccountModalHeader | ||
konnector={konnector} | ||
account={account} | ||
accountsAndTriggers={accountsAndTriggers} | ||
/> | ||
{(isError || isLoading) && ( | ||
<DialogContent className="u-pb-2"> | ||
{isError && ( | ||
<Error | ||
accountId={accountId} | ||
accountsAndTriggers={accountsAndTriggers} | ||
trigger={matchingTrigger} | ||
lastError={accountQueryResult.lastError} | ||
/> | ||
)} | ||
{isLoading && ( | ||
<Spinner className="u-flex u-flex-justify-center" size="xxlarge" /> | ||
)} | ||
</DialogContent> | ||
)} | ||
{!isError && | ||
!isLoading && | ||
React.Children.map(children, child => | ||
React.isValidElement(child) | ||
? React.cloneElement(child, { | ||
trigger: matchingTrigger, | ||
account, | ||
konnector | ||
}) | ||
: null | ||
)} | ||
</> | ||
) | ||
} | ||
|
||
AccountModalWithoutTabs.propTypes = { | ||
konnector: PropTypes.object.isRequired, | ||
/** | ||
* @type {{ account: 'io.cozy.accounts', trigger: 'io.cozy.triggers' }[]} - An array of objects containing an account and its associated trigger | ||
*/ | ||
accountsAndTriggers: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
account: PropTypes.object.isRequired, | ||
trigger: PropTypes.object.isRequired | ||
}) | ||
).isRequired, | ||
accountId: PropTypes.string.isRequired | ||
} | ||
|
||
export default withMountPointProps(AccountModalWithoutTabs) |
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