fix: Redirect to SPOTS_LIST_PATH when spotOnly is true in PrivateRoutes

This commit is contained in:
nick-delirium 2024-08-30 11:32:19 +02:00
parent 3a14e0f7ce
commit 128746fa15
No known key found for this signature in database
GPG key ID: 93ABD695DF5FDBA0

View file

@ -1,16 +1,17 @@
import React, { lazy, Suspense } from 'react';
import { Switch, Route, Redirect } from 'react-router-dom';
import { connect } from 'react-redux';
import { Loader } from 'UI';
import withSiteIdUpdater from 'HOCs/withSiteIdUpdater';
import { Map } from 'immutable';
import React, { Suspense, lazy } from 'react';
import { connect } from 'react-redux';
import { Redirect, Route, Switch } from 'react-router-dom';
import AdditionalRoutes from 'App/AdditionalRoutes';
import { GLOBAL_HAS_NO_RECORDINGS } from 'App/constants/storageKeys';
import { OB_DEFAULT_TAB } from 'App/routes';
import { Loader } from 'UI';
import APIClient from './api_client';
import { getScope } from "./duck/user";
import { getScope } from './duck/user';
import * as routes from './routes';
import { OB_DEFAULT_TAB } from 'App/routes';
import { GLOBAL_HAS_NO_RECORDINGS } from 'App/constants/storageKeys';
import { Map } from 'immutable';
import AdditionalRoutes from 'App/AdditionalRoutes';
const components: any = {
SessionPure: lazy(() => import('Components/Session/Session')),
@ -21,12 +22,20 @@ const components: any = {
SessionsOverviewPure: lazy(() => import('Components/Overview')),
DashboardPure: lazy(() => import('Components/Dashboard/NewDashboard')),
FunnelDetailsPure: lazy(() => import('Components/Funnels/FunnelDetails')),
FunnelIssueDetails: lazy(() => import('Components/Funnels/FunnelIssueDetails')),
FunnelIssueDetails: lazy(
() => import('Components/Funnels/FunnelIssueDetails')
),
FunnelPagePure: lazy(() => import('Components/Funnels/FunnelPage')),
MultiviewPure: lazy(() => import('Components/Session_/Multiview/Multiview')),
UsabilityTestingPure: lazy(() => import('Components/UsabilityTesting/UsabilityTesting')),
UsabilityTestEditPure: lazy(() => import('Components/UsabilityTesting/TestEdit')),
UsabilityTestOverviewPure: lazy(() => import('Components/UsabilityTesting/TestOverview')),
UsabilityTestingPure: lazy(
() => import('Components/UsabilityTesting/UsabilityTesting')
),
UsabilityTestEditPure: lazy(
() => import('Components/UsabilityTesting/TestEdit')
),
UsabilityTestOverviewPure: lazy(
() => import('Components/UsabilityTesting/TestOverview')
),
SpotsListPure: lazy(() => import('Components/Spots/SpotsList')),
SpotPure: lazy(() => import('Components/Spots/SpotPlayer')),
ScopeSetup: lazy(() => import('Components/ScopeForm')),
@ -46,10 +55,12 @@ const enhancedComponents: any = {
Multiview: withSiteIdUpdater(components.MultiviewPure),
UsabilityTesting: withSiteIdUpdater(components.UsabilityTestingPure),
UsabilityTestEdit: withSiteIdUpdater(components.UsabilityTestEditPure),
UsabilityTestOverview: withSiteIdUpdater(components.UsabilityTestOverviewPure),
UsabilityTestOverview: withSiteIdUpdater(
components.UsabilityTestOverviewPure
),
SpotsList: withSiteIdUpdater(components.SpotsListPure),
Spot: components.SpotPure,
ScopeSetup: components.ScopeSetup
ScopeSetup: components.ScopeSetup,
};
const withSiteId = routes.withSiteId;
@ -137,139 +148,139 @@ function PrivateRoutes(props: Props) {
path={SCOPE_SETUP}
component={enhancedComponents.ScopeSetup}
/>
{props.spotOnly ? null : <>
<Route
path="/integrations/"
render={({ location }) => {
const client = new APIClient();
switch (location.pathname) {
case "/integrations/slack":
client.post("integrations/slack/add", {
code: location.search.split("=")[1],
state: props.tenantId
});
break;
case "/integrations/msteams":
client.post("integrations/msteams/add", {
code: location.search.split("=")[1],
state: props.tenantId
});
break;
}
return <Redirect to={CLIENT_PATH} />;
}}
/>
{redirectToOnboarding && <Redirect to={withSiteId(ONBOARDING_REDIRECT_PATH, siteId)} />}
{/* DASHBOARD and Metrics */}
<Route
exact
strict
path={[
withSiteId(ALERTS_PATH, siteIdList),
withSiteId(ALERT_EDIT_PATH, siteIdList),
withSiteId(ALERT_CREATE_PATH, siteIdList),
withSiteId(METRICS_PATH, siteIdList),
withSiteId(METRICS_DETAILS, siteIdList),
withSiteId(METRICS_DETAILS_SUB, siteIdList),
withSiteId(DASHBOARD_PATH, siteIdList),
withSiteId(DASHBOARD_SELECT_PATH, siteIdList),
withSiteId(DASHBOARD_METRIC_CREATE_PATH, siteIdList),
withSiteId(DASHBOARD_METRIC_DETAILS_PATH, siteIdList)
]}
component={enhancedComponents.Dashboard}
/>
<Route
exact
strict
path={withSiteId(USABILITY_TESTING_PATH, siteIdList)}
component={enhancedComponents.UsabilityTesting}
/>
<Route
exact
strict
path={withSiteId(USABILITY_TESTING_EDIT_PATH, siteIdList)}
component={enhancedComponents.UsabilityTestEdit}
/>
<Route
exact
strict
path={withSiteId(USABILITY_TESTING_VIEW_PATH, siteIdList)}
component={enhancedComponents.UsabilityTestOverview}
/>
<Route
exact
path={withSiteId(MULTIVIEW_INDEX_PATH, siteIdList)}
component={enhancedComponents.Multiview}
/>
<Route
path={withSiteId(MULTIVIEW_PATH, siteIdList)}
component={enhancedComponents.Multiview}
/>
<Route
exact
strict
path={withSiteId(ASSIST_PATH, siteIdList)}
component={enhancedComponents.Assist}
/>
<Route
exact
strict
path={withSiteId(RECORDINGS_PATH, siteIdList)}
component={enhancedComponents.Assist}
/>
<Route
exact
strict
path={withSiteId(FUNNEL_PATH, siteIdList)}
component={enhancedComponents.FunnelPage}
/>
<Route
exact
strict
path={withSiteId(FUNNEL_CREATE_PATH, siteIdList)}
component={enhancedComponents.FunnelsDetails}
/>
<Route
exact
strict
path={withSiteId(FUNNEL_ISSUE_PATH, siteIdList)}
component={enhancedComponents.FunnelIssue}
/>
<Route
exact
strict
path={[
withSiteId(SESSIONS_PATH, siteIdList),
withSiteId(FFLAGS_PATH, siteIdList),
withSiteId(FFLAG_PATH, siteIdList),
withSiteId(FFLAG_READ_PATH, siteIdList),
withSiteId(FFLAG_CREATE_PATH, siteIdList),
withSiteId(NOTES_PATH, siteIdList),
withSiteId(BOOKMARKS_PATH, siteIdList)
]}
component={enhancedComponents.SessionsOverview}
/>
<Route
exact
strict
path={withSiteId(SESSION_PATH, siteIdList)}
component={enhancedComponents.Session}
/>
<Route
exact
strict
path={withSiteId(LIVE_SESSION_PATH, siteIdList)}
component={enhancedComponents.LiveSession}
/>
{/*{Object.entries(routes.redirects).map(([fr, to]) => (*/}
{/* <Redirect key={fr} exact strict from={fr} to={to} />*/}
{/*))}*/}
{/*<Redirect to={withSiteId(routes.sessions(), siteId)} />*/}
</>}
{props.spotOnly ? <Redirect to={SPOTS_LIST_PATH} /> : null}
<Route
path="/integrations/"
render={({ location }) => {
const client = new APIClient();
switch (location.pathname) {
case '/integrations/slack':
client.post('integrations/slack/add', {
code: location.search.split('=')[1],
state: props.tenantId,
});
break;
case '/integrations/msteams':
client.post('integrations/msteams/add', {
code: location.search.split('=')[1],
state: props.tenantId,
});
break;
}
return <Redirect to={CLIENT_PATH} />;
}}
/>
{redirectToOnboarding && (
<Redirect to={withSiteId(ONBOARDING_REDIRECT_PATH, siteId)} />
)}
{/* DASHBOARD and Metrics */}
<Route
exact
strict
path={[
withSiteId(ALERTS_PATH, siteIdList),
withSiteId(ALERT_EDIT_PATH, siteIdList),
withSiteId(ALERT_CREATE_PATH, siteIdList),
withSiteId(METRICS_PATH, siteIdList),
withSiteId(METRICS_DETAILS, siteIdList),
withSiteId(METRICS_DETAILS_SUB, siteIdList),
withSiteId(DASHBOARD_PATH, siteIdList),
withSiteId(DASHBOARD_SELECT_PATH, siteIdList),
withSiteId(DASHBOARD_METRIC_CREATE_PATH, siteIdList),
withSiteId(DASHBOARD_METRIC_DETAILS_PATH, siteIdList),
]}
component={enhancedComponents.Dashboard}
/>
<Route
exact
strict
path={withSiteId(USABILITY_TESTING_PATH, siteIdList)}
component={enhancedComponents.UsabilityTesting}
/>
<Route
exact
strict
path={withSiteId(USABILITY_TESTING_EDIT_PATH, siteIdList)}
component={enhancedComponents.UsabilityTestEdit}
/>
<Route
exact
strict
path={withSiteId(USABILITY_TESTING_VIEW_PATH, siteIdList)}
component={enhancedComponents.UsabilityTestOverview}
/>
<Route
exact
path={withSiteId(MULTIVIEW_INDEX_PATH, siteIdList)}
component={enhancedComponents.Multiview}
/>
<Route
path={withSiteId(MULTIVIEW_PATH, siteIdList)}
component={enhancedComponents.Multiview}
/>
<Route
exact
strict
path={withSiteId(ASSIST_PATH, siteIdList)}
component={enhancedComponents.Assist}
/>
<Route
exact
strict
path={withSiteId(RECORDINGS_PATH, siteIdList)}
component={enhancedComponents.Assist}
/>
<Route
exact
strict
path={withSiteId(FUNNEL_PATH, siteIdList)}
component={enhancedComponents.FunnelPage}
/>
<Route
exact
strict
path={withSiteId(FUNNEL_CREATE_PATH, siteIdList)}
component={enhancedComponents.FunnelsDetails}
/>
<Route
exact
strict
path={withSiteId(FUNNEL_ISSUE_PATH, siteIdList)}
component={enhancedComponents.FunnelIssue}
/>
<Route
exact
strict
path={[
withSiteId(SESSIONS_PATH, siteIdList),
withSiteId(FFLAGS_PATH, siteIdList),
withSiteId(FFLAG_PATH, siteIdList),
withSiteId(FFLAG_READ_PATH, siteIdList),
withSiteId(FFLAG_CREATE_PATH, siteIdList),
withSiteId(NOTES_PATH, siteIdList),
withSiteId(BOOKMARKS_PATH, siteIdList),
]}
component={enhancedComponents.SessionsOverview}
/>
<Route
exact
strict
path={withSiteId(SESSION_PATH, siteIdList)}
component={enhancedComponents.Session}
/>
<Route
exact
strict
path={withSiteId(LIVE_SESSION_PATH, siteIdList)}
component={enhancedComponents.LiveSession}
/>
{Object.entries(routes.redirects).map(([fr, to]) => (
<Redirect key={fr} exact strict from={fr} to={to} />
))}
<Redirect to={withSiteId(routes.sessions(), siteId)} />
</Switch>
</Suspense>
);