import withSiteIdUpdater from 'HOCs/withSiteIdUpdater'; import withSiteIdUpdater from 'HOCs/withSiteIdUpdater'; import React, { Suspense, lazy } from 'react'; import { Redirect, Route, Switch } from 'react-router-dom'; import { observer } from 'mobx-react-lite'; import { useStore } from './mstore'; 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 * as routes from './routes'; import { debounce } from '@/utils'; const components: any = { SessionPure: lazy(() => import('Components/Session/Session')), LiveSessionPure: lazy(() => import('Components/Session/LiveSession')), OnboardingPure: lazy(() => import('Components/Onboarding/Onboarding')), ClientPure: lazy(() => import('Components/Client/Client')), AssistPure: lazy(() => import('Components/Assist/AssistRouter')), SessionsOverviewPure: lazy(() => import('Components/Overview')), DashboardPure: lazy(() => import('Components/Dashboard/NewDashboard')), 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'), ), SpotsListPure: lazy(() => import('Components/Spots/SpotsList')), SpotPure: lazy(() => import('Components/Spots/SpotPlayer')), ScopeSetup: lazy(() => import('Components/ScopeForm')), HighlightsPure: lazy(() => import('Components/Highlights/HighlightsList')) }; const enhancedComponents: any = { SessionsOverview: withSiteIdUpdater(components.SessionsOverviewPure), Dashboard: withSiteIdUpdater(components.DashboardPure), Session: withSiteIdUpdater(components.SessionPure), LiveSession: withSiteIdUpdater(components.LiveSessionPure), Assist: withSiteIdUpdater(components.AssistPure), Client: withSiteIdUpdater(components.ClientPure), Onboarding: withSiteIdUpdater(components.OnboardingPure), Multiview: withSiteIdUpdater(components.MultiviewPure), UsabilityTesting: withSiteIdUpdater(components.UsabilityTestingPure), UsabilityTestEdit: withSiteIdUpdater(components.UsabilityTestEditPure), UsabilityTestOverview: withSiteIdUpdater( components.UsabilityTestOverviewPure, ), SpotsList: withSiteIdUpdater(components.SpotsListPure), Spot: components.SpotPure, ScopeSetup: components.ScopeSetup, Highlights: withSiteIdUpdater(components.HighlightsPure) }; const { withSiteId } = routes; const METRICS_PATH = routes.metrics(); const METRICS_DETAILS = routes.metricDetails(); const METRICS_DETAILS_SUB = routes.metricDetailsSub(); const ALERTS_PATH = routes.alerts(); const ALERT_CREATE_PATH = routes.alertCreate(); const ALERT_EDIT_PATH = routes.alertEdit(); const DASHBOARD_PATH = routes.dashboard(); const DASHBOARD_SELECT_PATH = routes.dashboardSelected(); const DASHBOARD_METRIC_CREATE_PATH = routes.dashboardMetricCreate(); const DASHBOARD_METRIC_DETAILS_PATH = routes.dashboardMetricDetails(); const SESSIONS_PATH = routes.sessions(); const FFLAGS_PATH = routes.fflags(); const FFLAG_PATH = routes.fflag(); const FFLAG_CREATE_PATH = routes.newFFlag(); const FFLAG_READ_PATH = routes.fflagRead(); const NOTES_PATH = routes.notes(); const BOOKMARKS_PATH = routes.bookmarks(); const RECORDINGS_PATH = routes.recordings(); const SESSION_PATH = routes.session(); const CLIENT_PATH = routes.client(); const ONBOARDING_PATH = routes.onboarding(); const ONBOARDING_REDIRECT_PATH = routes.onboarding(OB_DEFAULT_TAB); const ASSIST_PATH = routes.assist(); const LIVE_SESSION_PATH = routes.liveSession(); const MULTIVIEW_PATH = routes.multiview(); const MULTIVIEW_INDEX_PATH = routes.multiviewIndex(); const ASSIST_STATS_PATH = routes.assistStats(); const USABILITY_TESTING_PATH = routes.usabilityTesting(); const USABILITY_TESTING_EDIT_PATH = routes.usabilityTestingEdit(); const USABILITY_TESTING_VIEW_PATH = routes.usabilityTestingView(); const SPOTS_LIST_PATH = routes.spotsList(); const SPOT_PATH = routes.spot(); const SCOPE_SETUP = routes.scopeSetup(); const HIGHLIGHTS_PATH = routes.highlights(); let debounceSearch: any = () => {}; function PrivateRoutes() { const { projectsStore, userStore, integrationsStore, searchStore } = useStore(); const onboarding = userStore.onboarding; const scope = userStore.scopeState; const { tenantId } = userStore.account; const sites = projectsStore.list; const { siteId } = projectsStore; const hasRecordings = sites.some((s) => s.recorded); const redirectToSetup = scope === 0; const redirectToOnboarding = !onboarding && (localStorage.getItem(GLOBAL_HAS_NO_RECORDINGS) === 'true' || (sites.length > 0 && !hasRecordings)) && scope > 0; const siteIdList: any = sites.map(({ id }) => id); React.useEffect(() => { if (siteId && integrationsStore.integrations.siteId !== siteId) { integrationsStore.integrations.setSiteId(siteId); void integrationsStore.integrations.fetchIntegrations(siteId); } }, [siteId]); React.useEffect(() => { debounceSearch = debounce(() => searchStore.fetchSessions(), 250); }, []); React.useEffect(() => { if (!searchStore.urlParsed) return; debounceSearch(); }, [searchStore.urlParsed, searchStore.instance.filters, searchStore.instance.eventsOrder]); return ( }> {redirectToSetup ? : null} {scope === 1 ? : null} { const client = new APIClient(); switch (location.pathname) { case '/integrations/slack': client.post('integrations/slack/add', { code: location.search.split('=')[1], state: tenantId }); break; case '/integrations/msteams': client.post('integrations/msteams/add', { code: location.search.split('=')[1], state: tenantId }); break; } return ; }} /> {redirectToOnboarding && ( )} {/* DASHBOARD and Metrics */} {Object.entries(routes.redirects).map(([fr, to]) => ( ))} ); } export default observer(PrivateRoutes);