Skip to content

Commit

Permalink
feat(harvest): Add routes v6
Browse files Browse the repository at this point in the history
  • Loading branch information
JF-Cozy committed Dec 21, 2022
1 parent e66ef79 commit 9927d78
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/cozy-harvest-lib/src/components/Routes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ import { useKonnectorWithTriggers } from '../helpers/useKonnectorWithTriggers'
import ComponentsPropsProvider from './Providers/ComponentsPropsProvider'
import { DatacardOptions } from './Datacards/DatacardOptionsContext'
import RoutesV4 from './Routes/RoutesV4'
import RoutesV6 from './Routes/RoutesV6'
import KonnectorAccounts from './KonnectorAccounts'
import HarvestVaultProvider from './HarvestVaultProvider'
import VaultUnlockProvider from './VaultUnlockProvider'
import { MountPointProvider } from './MountPointContext'
import DialogContext from './DialogContext'
import { isRouterV6 } from './hoc/withRouter'

/**
* Dialog will not be centered vertically since we need the modal to "stay in place"
Expand Down Expand Up @@ -51,6 +53,8 @@ const Routes = ({
datacardOptions,
ComponentsProps
}) => {
const RoutesV4orV6 = isRouterV6 ? RoutesV6 : RoutesV4

const { t } = useI18n()
const dialogContext = useCozyDialog({
size: 'l',
Expand Down Expand Up @@ -87,7 +91,7 @@ const Routes = ({
) : (
<KonnectorAccounts konnector={konnectorWithTriggers}>
{accountsAndTriggers => (
<RoutesV4
<RoutesV4orV6
konnectorRoot={konnectorRoot}
konnectorWithTriggers={konnectorWithTriggers}
accountsAndTriggers={accountsAndTriggers}
Expand Down
103 changes: 103 additions & 0 deletions packages/cozy-harvest-lib/src/components/Routes/RoutesV6.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import React from 'react'
import { Routes, Route, Navigate, useParams } 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 HarvestParamsWrapper = props => {
const params = useParams()
return props.children(params)
}

const RoutesV6 = ({
konnectorWithTriggers,
accountsAndTriggers,
onDismiss
}) => {
return (
<Routes>
<Route
path="/"
element={
<HarvestModalRoot
accounts={accountsAndTriggers}
konnector={konnectorWithTriggers}
/>
}
/>

<Route
path="new"
element={
<NewAccountModal
konnector={konnectorWithTriggers}
onDismiss={onDismiss}
/>
}
/>

<Route
path="accounts/:accountId"
element={
<HarvestParamsWrapper>
{params => (
<AccountModal
konnector={konnectorWithTriggers}
accountId={params.accountId}
accountsAndTriggers={accountsAndTriggers}
onDismiss={onDismiss}
showNewAccountButton={!konnectorWithTriggers.clientSide}
showAccountSelection={!konnectorWithTriggers.clientSide}
/>
)}
</HarvestParamsWrapper>
}
/>
<Route
path="accounts/:accountId/edit"
element={
<HarvestParamsWrapper>
{params => (
<EditAccountModal
konnector={konnectorWithTriggers}
accountId={params.accountId}
accounts={accountsAndTriggers}
/>
)}
</HarvestParamsWrapper>
}
/>
<Route
path="accounts/:accountId/success"
element={
<HarvestParamsWrapper>
{params => (
<KonnectorSuccess
konnector={konnectorWithTriggers}
accountId={params.accountId}
accounts={accountsAndTriggers}
onDismiss={onDismiss}
/>
)}
</HarvestParamsWrapper>
}
/>

<Route
path="viewer/:accountId/:folderToSaveId/:fileIndex"
element={routeComponentProps => (
<ViewerModal {...routeComponentProps} />
)}
/>

{/* Redirections */}
<Route path="*" element={<Navigate replace to="/" />} />
</Routes>
)
}

export default RoutesV6

0 comments on commit 9927d78

Please sign in to comment.