-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
108 additions
and
1 deletion.
There are no files selected for viewing
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
103 changes: 103 additions & 0 deletions
103
packages/cozy-harvest-lib/src/components/Routes/RoutesV6.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,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 |