refactor: use Wizard component on first route
This commit is contained in:
parent
f8a82bb84b
commit
61285c9037
3 changed files with 28 additions and 39 deletions
|
|
@ -2,13 +2,7 @@ import Fade from '@mui/material/Fade'
|
|||
import Slide from '@mui/material/Slide'
|
||||
import * as R from 'ramda'
|
||||
import React, { useContext } from 'react'
|
||||
import {
|
||||
matchPath,
|
||||
Redirect,
|
||||
Switch,
|
||||
useHistory,
|
||||
useLocation,
|
||||
} from 'react-router-dom'
|
||||
import { matchPath, Redirect, Switch, useLocation } from 'react-router-dom'
|
||||
import Login from '../pages/Authentication/Login'
|
||||
import Register from '../pages/Authentication/Register'
|
||||
import Reset2FA from '../pages/Authentication/Reset2FA'
|
||||
|
|
@ -17,7 +11,6 @@ import ResetPassword from '../pages/Authentication/ResetPassword'
|
|||
import AppContext from '../AppContext'
|
||||
import Dashboard from '../pages/Dashboard'
|
||||
import Machines from '../pages/Machines'
|
||||
import Wizard from '../pages/Wizard'
|
||||
|
||||
import PrivateRoute from './PrivateRoute'
|
||||
import PublicRoute from './PublicRoute'
|
||||
|
|
@ -57,27 +50,12 @@ const getParent = route =>
|
|||
)(flattened)
|
||||
|
||||
const Routes = () => {
|
||||
const history = useHistory()
|
||||
const location = useLocation()
|
||||
const { wizardTested, userData } = useContext(AppContext)
|
||||
|
||||
const dontTriggerPages = [
|
||||
'/404',
|
||||
'/register',
|
||||
'/wizard',
|
||||
'/login',
|
||||
'/register',
|
||||
'/resetpassword',
|
||||
'/reset2fa',
|
||||
]
|
||||
|
||||
if (!wizardTested && !R.contains(location.pathname)(dontTriggerPages)) {
|
||||
history.push('/wizard')
|
||||
return null
|
||||
}
|
||||
const { userData } = useContext(AppContext)
|
||||
|
||||
const getFilteredRoutes = () => {
|
||||
if (!userData) return []
|
||||
// return all to prevent the user from being stuck at a 404 page
|
||||
if (!userData) return flattened
|
||||
|
||||
return flattened.filter(value => {
|
||||
const keys = value.allowedRoles
|
||||
|
|
@ -116,11 +94,10 @@ const Routes = () => {
|
|||
</Transition>
|
||||
</PrivateRoute>
|
||||
<PrivateRoute path="/machines" component={Machines} />
|
||||
<PrivateRoute path="/wizard" component={Wizard} />
|
||||
<PublicRoute path="/register" component={Register} />
|
||||
<PublicRoute path="/login" restricted component={Login} />
|
||||
<PublicRoute path="/resetpassword" component={ResetPassword} />
|
||||
<PublicRoute path="/reset2fa" component={Reset2FA} />
|
||||
<PublicRoute path="/login" restricted component={Login} />
|
||||
{getFilteredRoutes().map(({ route, component: Page, key }) => (
|
||||
<PrivateRoute path={route} key={key}>
|
||||
<Transition
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue