From d0d18f207f3840c15ee6cd0e723bf03af5ad63d8 Mon Sep 17 00:00:00 2001 From: Harshil Sharma <18575143+harshilsharma63@users.noreply.github.com> Date: Mon, 28 Mar 2022 10:22:25 +0530 Subject: [PATCH] Fixed bug where match didn't receive current router's route (#2598) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fixed bug where match didn't receive current router's route * Lint fiX * Simplified the FBRoute Co-authored-by: Jesús Espino Co-authored-by: Scott Bishel --- webapp/src/route.tsx | 60 +++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/webapp/src/route.tsx b/webapp/src/route.tsx index c139b5b71..55ec3c54f 100644 --- a/webapp/src/route.tsx +++ b/webapp/src/route.tsx @@ -4,7 +4,6 @@ import React from 'react' import { Redirect, Route, - useRouteMatch, } from 'react-router-dom' import {Utils} from './utils' @@ -27,14 +26,10 @@ type RouteProps = { function FBRoute(props: RouteProps) { const loggedIn = useAppSelector(getLoggedIn) - const match = useRouteMatch() const me = useAppSelector(getMe) const clientConfig = useAppSelector(getClientConfig) - let originalPath - if (props.getOriginalPath) { - originalPath = props.getOriginalPath(match) - } + let redirect: React.ReactNode = null const showWelcomePage = !clientConfig.featureFlags.disableTour && Utils.isFocalboardPlugin() && @@ -44,37 +39,38 @@ function FBRoute(props: RouteProps) { !me?.props[UserPropPrefix + UserSettingKey.WelcomePageViewed] if (showWelcomePage) { - if (originalPath) { - return - } - return - } - - if (loggedIn === false && props.loginRequired) { - if (originalPath) { - let redirectUrl = '/' + Utils.buildURL(originalPath) - if (redirectUrl.indexOf('//') === 0) { - redirectUrl = redirectUrl.slice(1) + redirect = ({match}: any) => { + if (props.getOriginalPath) { + return } - const loginUrl = `/error?id=not-logged-in&r=${encodeURIComponent(redirectUrl)}` - return + return } - return } - if (loggedIn === true || !props.loginRequired) { - return ( - - {props.children} - - ) + if (redirect === null && loggedIn === false && props.loginRequired) { + redirect = ({match}: any) => { + if (props.getOriginalPath) { + let redirectUrl = '/' + Utils.buildURL(props.getOriginalPath!(match)) + if (redirectUrl.indexOf('//') === 0) { + redirectUrl = redirectUrl.slice(1) + } + const loginUrl = `/error?id=not-logged-in&r=${encodeURIComponent(redirectUrl)}` + return + } + return + } } - return null + + return ( + + {redirect || props.children} + + ) } export default React.memo(FBRoute)