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
11 changes: 5 additions & 6 deletions src/app/components/elements/PageTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ export const PageTitle = ({
}: PageTitleProps) => {
const dispatch = useAppDispatch();
const openModal = useAppSelector((state: AppState) => Boolean(state?.activeModals?.length));
const user = useAppSelector((state: AppState) => state?.user);
const headerRef = useRef<HTMLHeadingElement>(null);

useEffect(() => {
Expand All @@ -83,12 +82,12 @@ export const PageTitle = ({
// Extract nested ternary logic
const renderHelpOrBoosterButton = () => {
if (boosterVideoButton) {
const targetPath = user?.loggedIn
? "/pages/booster_video_binary_conversion_and_addition"
: "/login?target=/pages/booster_video_binary_conversion_and_addition";

return (
<Button tag={Link} to={targetPath} className="primary-button text-light align-self-center ml-sm-2">
<Button
tag={Link}
to="/booster_video_binary_conversion_and_addition"
className="primary-button text-light align-self-center ml-sm-2"
>
Watch booster videos
</Button>
);
Expand Down
8 changes: 4 additions & 4 deletions src/app/components/navigation/IsaacApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ export const IsaacApp = () => {
{/* historic route which might get reintroduced with the introduction of dashboards */}
<TrackedRoute exact path="/account" ifUser={isLoggedIn} component={MyAccount} />
<TrackedRoute exact path="/search" component={Search} />
<TrackedRoute
<StaticPageRoute exact path="/booster_video_binary_conversion_and_addition" ifUser={isLoggedIn} />
<Redirect
exact
path="/booster_video_binary_conversion_and_addition"
ifUser={isLoggedIn}
component={Generic}
from="/pages/booster_video_binary_conversion_and_addition"
to="/booster_video_binary_conversion_and_addition"
/>
<TrackedRoute exact path="/pages/:pageId" component={Generic} />
<TrackedRoute
Expand Down
51 changes: 28 additions & 23 deletions src/app/components/navigation/TrackedRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,29 +74,34 @@ export const TrackedRoute = function ({ component, trackingOptions, componentPro
const userNeedsToBeTutorOrTeacher =
rest.ifUser && [isTutorOrAbove.name, isTeacherOrAbove.name].includes(rest.ifUser.name); // TODO we should try to find a more robust way than this
return (
<ShowLoading until={user}>
{(user && ifUser(user)) || isBot(userAgent) ? (
<WrapperComponent
component={component}
trackingOptions={trackingOptions}
{...propsWithUser}
{...componentProps}
/>
) : user && !user.loggedIn && !isTutorOrAbove(user) && userNeedsToBeTutorOrTeacher ? (
persistence.save(KEY.AFTER_AUTH_PATH, props.location.pathname + props.location.search) && (
<Redirect to="/login" />
)
) : user && !isTutorOrAbove(user) && userNeedsToBeTutorOrTeacher ? (
<Redirect to={TEACHER_REQUEST_ROUTE} />
) : user && user.loggedIn && !ifUser(user) ? (
<Unauthorised />
) : (
persistence.save(
KEY.AFTER_AUTH_PATH,
props.location.pathname + props.location.search + props.location.hash,
) && <Redirect to="/login" />
)}
</ShowLoading>
<ShowLoading
until={user}
thenRender={(user) => {
if (ifUser(user) || isBot(userAgent)) {
return (
<WrapperComponent
component={component}
trackingOptions={trackingOptions}
{...propsWithUser}
{...componentProps}
/>
);
} else if (!user.loggedIn && !isTutorOrAbove(user) && userNeedsToBeTutorOrTeacher) {
persistence.save(KEY.AFTER_AUTH_PATH, props.location.pathname + props.location.search);
return <Redirect to="/login" />;
} else if (!isTutorOrAbove(user) && userNeedsToBeTutorOrTeacher) {
return <Redirect to={TEACHER_REQUEST_ROUTE} />;
} else if (user.loggedIn && !ifUser(user)) {
return <Unauthorised />;
} else {
persistence.save(
KEY.AFTER_AUTH_PATH,
props.location.pathname + props.location.search + props.location.hash,
);
return <Redirect to="/login" />;
}
}}
/>
);
}}
/>
Expand Down
Loading