2023-02-14 14:27:26 +01:00
|
|
|
import { Suspense, useEffect } from 'react';
|
2023-01-25 13:12:31 +01:00
|
|
|
import { Route, Routes } from 'react-router-dom';
|
2022-10-10 12:18:37 +02:00
|
|
|
import { ErrorBoundary } from 'react-error-boundary';
|
|
|
|
import { Error } from 'component/layout/Error/Error';
|
2022-05-02 12:52:33 +02:00
|
|
|
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
2022-03-31 09:23:46 +02:00
|
|
|
import { FeedbackNPS } from 'component/feedback/FeedbackNPS/FeedbackNPS';
|
2022-04-01 10:28:15 +02:00
|
|
|
import { LayoutPicker } from 'component/layout/LayoutPicker/LayoutPicker';
|
2022-03-28 10:49:59 +02:00
|
|
|
import Loader from 'component/common/Loader/Loader';
|
|
|
|
import NotFound from 'component/common/NotFound/NotFound';
|
2022-05-05 13:42:18 +02:00
|
|
|
import { ProtectedRoute } from 'component/common/ProtectedRoute/ProtectedRoute';
|
2022-08-30 09:54:52 +02:00
|
|
|
import { SWRProvider } from 'component/providers/SWRProvider/SWRProvider';
|
2022-10-10 14:06:44 +02:00
|
|
|
import { PlausibleProvider } from 'component/providers/PlausibleProvider/PlausibleProvider';
|
2022-03-28 10:49:59 +02:00
|
|
|
import ToastRenderer from 'component/common/ToastRenderer/ToastRenderer';
|
|
|
|
import { routes } from 'component/menu/routes';
|
2022-03-22 08:23:51 +01:00
|
|
|
import { useAuthDetails } from 'hooks/api/getters/useAuth/useAuthDetails';
|
|
|
|
import { useAuthUser } from 'hooks/api/getters/useAuth/useAuthUser';
|
|
|
|
import { SplashPageRedirect } from 'component/splash/SplashPageRedirect/SplashPageRedirect';
|
2022-06-10 16:09:50 +02:00
|
|
|
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
|
2023-01-25 13:12:31 +01:00
|
|
|
|
2022-12-21 12:23:44 +01:00
|
|
|
import MaintenanceBanner from './maintenance/MaintenanceBanner';
|
2023-01-11 09:52:53 +01:00
|
|
|
import { styled } from '@mui/material';
|
2023-01-25 13:12:31 +01:00
|
|
|
import { InitialRedirect } from './InitialRedirect';
|
2021-10-15 09:21:38 +02:00
|
|
|
|
2023-01-11 09:52:53 +01:00
|
|
|
const StyledContainer = styled('div')(() => ({
|
|
|
|
'& ul': {
|
|
|
|
margin: 0,
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
|
2022-02-11 11:19:55 +01:00
|
|
|
export const App = () => {
|
2022-02-10 17:04:10 +01:00
|
|
|
const { authDetails } = useAuthDetails();
|
2023-02-14 14:27:26 +01:00
|
|
|
const { refetch: refetchUiConfig } = useUiConfig();
|
|
|
|
|
2022-02-10 17:04:10 +01:00
|
|
|
const { user } = useAuthUser();
|
|
|
|
const hasFetchedAuth = Boolean(authDetails || user);
|
2021-04-12 15:04:03 +02:00
|
|
|
|
2022-12-15 15:07:22 +01:00
|
|
|
const { isOss, uiConfig } = useUiConfig();
|
2022-11-28 15:10:40 +01:00
|
|
|
|
2022-06-10 16:09:50 +02:00
|
|
|
const availableRoutes = isOss()
|
|
|
|
? routes.filter(route => !route.enterprise)
|
|
|
|
: routes;
|
|
|
|
|
2023-02-14 14:27:26 +01:00
|
|
|
useEffect(() => {
|
|
|
|
if (hasFetchedAuth && Boolean(user?.id)) {
|
|
|
|
refetchUiConfig();
|
|
|
|
}
|
|
|
|
}, [authDetails, user]);
|
|
|
|
|
2021-04-12 15:04:03 +02:00
|
|
|
return (
|
2022-10-10 12:18:37 +02:00
|
|
|
<ErrorBoundary FallbackComponent={Error}>
|
2023-03-27 13:17:37 +02:00
|
|
|
<PlausibleProvider>
|
|
|
|
<ErrorBoundary FallbackComponent={Error}>
|
|
|
|
<SWRProvider>
|
|
|
|
<Suspense fallback={<Loader />}>
|
|
|
|
<ConditionallyRender
|
|
|
|
condition={!hasFetchedAuth}
|
|
|
|
show={<Loader />}
|
|
|
|
elseShow={
|
|
|
|
<>
|
|
|
|
<ConditionallyRender
|
|
|
|
condition={Boolean(
|
|
|
|
uiConfig?.maintenanceMode
|
|
|
|
)}
|
|
|
|
show={<MaintenanceBanner />}
|
|
|
|
/>
|
|
|
|
<StyledContainer>
|
|
|
|
<ToastRenderer />
|
|
|
|
<Routes>
|
|
|
|
{availableRoutes.map(route => (
|
|
|
|
<Route
|
|
|
|
key={route.path}
|
|
|
|
path={route.path}
|
|
|
|
element={
|
|
|
|
<LayoutPicker
|
|
|
|
isStandalone={
|
|
|
|
route.isStandalone ===
|
|
|
|
true
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<ProtectedRoute
|
|
|
|
route={
|
|
|
|
route
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</LayoutPicker>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
))}
|
2022-11-28 15:10:40 +01:00
|
|
|
<Route
|
2023-03-27 13:17:37 +02:00
|
|
|
path="/"
|
2022-11-28 15:10:40 +01:00
|
|
|
element={
|
2023-03-27 13:17:37 +02:00
|
|
|
<InitialRedirect />
|
2022-11-28 15:10:40 +01:00
|
|
|
}
|
|
|
|
/>
|
2023-03-27 13:17:37 +02:00
|
|
|
<Route
|
|
|
|
path="*"
|
|
|
|
element={<NotFound />}
|
|
|
|
/>
|
|
|
|
</Routes>
|
2023-01-17 13:33:52 +01:00
|
|
|
|
2023-03-27 13:17:37 +02:00
|
|
|
<FeedbackNPS openUrl="http://feedback.unleash.run" />
|
2023-01-17 13:33:52 +01:00
|
|
|
|
2023-03-27 13:17:37 +02:00
|
|
|
<SplashPageRedirect />
|
|
|
|
</StyledContainer>
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</Suspense>
|
|
|
|
</SWRProvider>
|
|
|
|
</ErrorBoundary>
|
|
|
|
</PlausibleProvider>
|
2022-10-10 12:18:37 +02:00
|
|
|
</ErrorBoundary>
|
2021-04-12 15:04:03 +02:00
|
|
|
);
|
|
|
|
};
|