Skip to content

Commit

Permalink
refactor(harvest): Extract routes v4 from Routes
Browse files Browse the repository at this point in the history
  • Loading branch information
JF-Cozy committed Dec 21, 2022
1 parent 3f08dd2 commit 525af21
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 89 deletions.
101 changes: 12 additions & 89 deletions packages/cozy-harvest-lib/src/components/Routes.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect } from 'react'
import { Switch, Route, Redirect } from 'react-router'
import { withStyles } from 'cozy-ui/transpiled/react/styles'

import { useVaultUnlockContext, VaultUnlockPlaceholder } from 'cozy-keys-lib'
import { withStyles } from 'cozy-ui/transpiled/react/styles'
import Alerter from 'cozy-ui/transpiled/react/Alerter'
import Dialog from 'cozy-ui/transpiled/react/Dialog'
import {
Expand All @@ -10,23 +10,16 @@ import {
} from 'cozy-ui/transpiled/react/CozyDialogs'
import { useI18n } from 'cozy-ui/transpiled/react/I18n'
import Spinner from 'cozy-ui/transpiled/react/Spinner'
import { useVaultUnlockContext, VaultUnlockPlaceholder } from 'cozy-keys-lib'

import { useKonnectorWithTriggers } from '../helpers/useKonnectorWithTriggers'
import ComponentsPropsProvider from './Providers/ComponentsPropsProvider'
import { DatacardOptions } from './Datacards/DatacardOptionsContext'
import RoutesV4 from './Routes/RoutesV4'
import KonnectorAccounts from './KonnectorAccounts'
import AccountModal from './AccountModal'
import NewAccountModal from './NewAccountModal'
import EditAccountModal from './EditAccountModal'
import KonnectorSuccess from './KonnectorSuccess'
import HarvestModalRoot from './HarvestModalRoot'
import HarvestVaultProvider from './HarvestVaultProvider'
import VaultUnlockProvider from './VaultUnlockProvider'
import { MountPointProvider } from './MountPointContext'
import DialogContext from './DialogContext'
import { DatacardOptions } from './Datacards/DatacardOptionsContext'

import { ViewerModal } from '../datacards/ViewerModal'
import { useKonnectorWithTriggers } from '../helpers/useKonnectorWithTriggers'
import ComponentsPropsProvider from './Providers/ComponentsPropsProvider'

/**
* Dialog will not be centered vertically since we need the modal to "stay in place"
Expand Down Expand Up @@ -94,82 +87,12 @@ const Routes = ({
) : (
<KonnectorAccounts konnector={konnectorWithTriggers}>
{accountsAndTriggers => (
<Switch>
<Route
path={`${konnectorRoot}/`}
exact
render={() => (
<HarvestModalRoot
accounts={accountsAndTriggers}
konnector={konnectorWithTriggers}
/>
)}
/>
<Route
path={`${konnectorRoot}/accounts/:accountId`}
exact
render={({ match }) => (
<AccountModal
konnector={konnectorWithTriggers}
accountId={match.params.accountId}
accountsAndTriggers={accountsAndTriggers}
onDismiss={onDismiss}
showNewAccountButton={
!konnectorWithTriggers.clientSide
}
showAccountSelection={
!konnectorWithTriggers.clientSide
}
/>
)}
/>
<Route
path={`${konnectorRoot}/accounts/:accountId/edit`}
exact
render={({ match }) => (
<EditAccountModal
konnector={konnectorWithTriggers}
accountId={match.params.accountId}
accounts={accountsAndTriggers}
/>
)}
/>
<Route
path={`${konnectorRoot}/viewer/:accountId/:folderToSaveId/:fileIndex`}
exact
render={routeComponentProps => (
<ViewerModal {...routeComponentProps} />
)}
/>
<Route
path={`${konnectorRoot}/new`}
exact
render={() => (
<NewAccountModal
konnector={konnectorWithTriggers}
onDismiss={onDismiss}
/>
)}
/>
<Route
path={`${konnectorRoot}/accounts/:accountId/success`}
exact
render={({ match }) => {
return (
<KonnectorSuccess
konnector={konnectorWithTriggers}
accountId={match.params.accountId}
accounts={accountsAndTriggers}
onDismiss={onDismiss}
/>
)
}}
/>
<Redirect
from={`${konnectorRoot}/*`}
to={`${konnectorRoot}/`}
/>
</Switch>
<RoutesV4
konnectorRoot={konnectorRoot}
konnectorWithTriggers={konnectorWithTriggers}
accountsAndTriggers={accountsAndTriggers}
onDismiss={onDismiss}
/>
)}
</KonnectorAccounts>
)}
Expand Down
88 changes: 88 additions & 0 deletions packages/cozy-harvest-lib/src/components/Routes/RoutesV4.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import React from 'react'
import { Switch, Route, Redirect } from 'react-router-dom'

import { ViewerModal } from '../../datacards/ViewerModal'
import AccountModal from '../AccountModal'
import NewAccountModal from '../NewAccountModal'
import EditAccountModal from '../EditAccountModal'
import KonnectorSuccess from '../KonnectorSuccess'
import HarvestModalRoot from '../HarvestModalRoot'

const RoutesV4 = ({
konnectorRoot,
konnectorWithTriggers,
accountsAndTriggers,
onDismiss
}) => {
return (
<Switch>
<Route
path={`${konnectorRoot}/`}
exact
render={() => (
<HarvestModalRoot
accounts={accountsAndTriggers}
konnector={konnectorWithTriggers}
/>
)}
/>
<Route
path={`${konnectorRoot}/accounts/:accountId`}
exact
render={({ match }) => (
<AccountModal
konnector={konnectorWithTriggers}
accountId={match.params.accountId}
accountsAndTriggers={accountsAndTriggers}
onDismiss={onDismiss}
showNewAccountButton={!konnectorWithTriggers.clientSide}
showAccountSelection={!konnectorWithTriggers.clientSide}
/>
)}
/>
<Route
path={`${konnectorRoot}/accounts/:accountId/edit`}
exact
render={({ match }) => (
<EditAccountModal
konnector={konnectorWithTriggers}
accountId={match.params.accountId}
accounts={accountsAndTriggers}
/>
)}
/>
<Route
path={`${konnectorRoot}/viewer/:accountId/:folderToSaveId/:fileIndex`}
exact
render={routeComponentProps => <ViewerModal {...routeComponentProps} />}
/>
<Route
path={`${konnectorRoot}/new`}
exact
render={() => (
<NewAccountModal
konnector={konnectorWithTriggers}
onDismiss={onDismiss}
/>
)}
/>
<Route
path={`${konnectorRoot}/accounts/:accountId/success`}
exact
render={({ match }) => {
return (
<KonnectorSuccess
konnector={konnectorWithTriggers}
accountId={match.params.accountId}
accounts={accountsAndTriggers}
onDismiss={onDismiss}
/>
)
}}
/>
<Redirect from={`${konnectorRoot}/*`} to={`${konnectorRoot}/`} />
</Switch>
)
}

export default RoutesV4

0 comments on commit 525af21

Please sign in to comment.