chore: title and sidebar moved to app.js

This commit is contained in:
Jose Sousa 2020-11-23 18:59:13 +00:00 committed by Josh Harvey
parent fd0f42c0ce
commit 3e1e2b4831
3 changed files with 122 additions and 108 deletions

View file

@ -20,7 +20,10 @@ import MachineLogs from 'src/pages/MachineLogs'
import CashCassettes from 'src/pages/Maintenance/CashCassettes'
import MachineStatus from 'src/pages/Maintenance/MachineStatus'
import Notifications from 'src/pages/Notifications/Notifications'
import OperatorInfo from 'src/pages/OperatorInfo/OperatorInfo'
import CoinAtmRadar from 'src/pages/OperatorInfo/CoinATMRadar'
import ContactInfo from 'src/pages/OperatorInfo/ContactInfo'
import ReceiptPrinting from 'src/pages/OperatorInfo/ReceiptPrinting'
import TermsConditions from 'src/pages/OperatorInfo/TermsConditions'
import ServerLogs from 'src/pages/ServerLogs'
import Services from 'src/pages/Services/Services'
import TokenManagement from 'src/pages/TokenManagement/TokenManagement'
@ -125,7 +128,36 @@ const tree = [
key: namespaces.OPERATOR_INFO,
label: 'Operator Info',
route: '/settings/operator-info',
component: OperatorInfo
children: [
{
key: 'contact-info',
label: 'Contact information',
title: 'Operator information',
route: '/settings/operator-info/contact-info',
component: ContactInfo
},
{
key: 'receipt-printing',
label: 'Receipt',
title: 'Operator information',
route: '/settings/operator-info/receipt-printing',
component: ReceiptPrinting
},
{
key: 'coin-atm-radar',
label: 'Coin ATM Radar',
title: 'Operator information',
route: '/settings/operator-info/coin-atm-radar',
component: CoinAtmRadar
},
{
key: 'terms-conditions',
label: 'Terms & Conditions',
title: 'Operator information',
route: '/settings/operator-info/terms-conditions',
component: TermsConditions
}
]
}
]
},
@ -181,10 +213,33 @@ const tree = [
]
const map = R.map(R.when(R.has('children'), R.prop('children')))
const leafRoutes = R.compose(R.flatten, map)(tree)
const parentRoutes = R.filter(R.has('children'))(tree)
const mappedRoutes = R.compose(R.flatten, map)(tree)
const parentRoutes = R.filter(R.has('children'))(tree).concat(
R.filter(R.has('children'))(mappedRoutes)
)
const leafRoutes = R.compose(R.flatten, map)(mappedRoutes)
const thirdLevelRoutes = R.compose(
R.flatten,
R.map(R.prop('children')),
R.filter(R.has('children'))
)(mappedRoutes)
const flattened = R.concat(leafRoutes, parentRoutes)
const getTitle = route =>
R.prop('title', R.find(R.propEq('route', route))(flattened))
const hasSidebar = route => R.any(r => r.route === route, thirdLevelRoutes)
const getSidebarData = route => {
const parentRoute = R.dropLast(
1,
R.dropLastWhile(x => x !== '/', route)
)
const parent = R.find(R.propEq('route', parentRoute))(flattened)
return parent?.children
}
const Routes = () => {
const history = useHistory()
const location = useLocation()
@ -201,6 +256,9 @@ const Routes = () => {
<Route exact path="/">
<Redirect to={{ pathname: '/transactions' }} />
</Route>
<Route exact path="/settings/operator-info">
<Redirect to={{ pathname: '/settings/operator-info/contact-info' }} />
</Route>
<Route path="/wizard" component={Wizard} />
<Route path="/register" component={AuthRegister} />
{flattened.map(({ route, component: Page, key }) => (
@ -215,4 +273,4 @@ const Routes = () => {
</Switch>
)
}
export { tree, Routes }
export { getTitle, tree, getSidebarData, hasSidebar, Routes }