Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ import PropTypes from 'prop-types';
import { Redirect, Route } from 'react-router-dom';
import { UNLOCK_ROUTE, ONBOARDING_ROUTE } from '../../constants/routes';

const OnboardingRoute = { pathname: ONBOARDING_ROUTE };
const UnlockRoute = { pathname: UNLOCK_ROUTE };

export default function Authenticated(props) {
const { isUnlocked, completedOnboarding } = props;
switch (true) {
case isUnlocked && completedOnboarding:
return <Route {...props} />;
case !completedOnboarding:
return <Redirect to={{ pathname: ONBOARDING_ROUTE }} />;
return <Redirect to={OnboardingRoute} />;
default:
return <Redirect to={{ pathname: UNLOCK_ROUTE }} />;
return <Redirect to={UnlockRoute} />;
}
}

Expand Down
8 changes: 6 additions & 2 deletions ui/helpers/higher-order-components/feature-toggled-route.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import React from 'react';
import React, { useMemo } from 'react';
import PropTypes from 'prop-types';
import { Redirect, Route } from 'react-router-dom';

export default function FeatureToggledRoute({ flag, redirectRoute, ...props }) {
const redirect = useMemo(
() => ({ pathname: redirectRoute }),
[redirectRoute],
);
if (flag) {
return <Route {...props} />;
}
return <Redirect to={{ pathname: redirectRoute }} />;
return <Redirect to={redirect} />;
}

FeatureToggledRoute.propTypes = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import PropTypes from 'prop-types';
import { Redirect, Route } from 'react-router-dom';
import { ONBOARDING_ROUTE } from '../../constants/routes';

const onboardingRoute = { pathname: ONBOARDING_ROUTE };

export default function Initialized(props) {
return props.completedOnboarding ? (
<Route {...props} />
) : (
<Redirect to={{ pathname: ONBOARDING_ROUTE }} />
<Redirect to={onboardingRoute} />
);
}

Expand Down
Loading