2022-04-05 18:21:25 +05:30
|
|
|
import { notification } from 'antd';
|
2022-11-14 14:29:13 +05:30
|
|
|
import getDynamicConfigs from 'api/dynamicConfigs/getDynamicConfigs';
|
2022-10-03 21:27:42 +05:30
|
|
|
import getFeaturesFlags from 'api/features/getFeatureFlags';
|
2022-04-08 13:49:33 +05:30
|
|
|
import getUserLatestVersion from 'api/user/getLatestVersion';
|
|
|
|
|
import getUserVersion from 'api/user/getVersion';
|
2022-05-03 15:27:09 +05:30
|
|
|
import Header from 'container/Header';
|
2021-10-20 09:24:55 +05:30
|
|
|
import SideNav from 'container/SideNav';
|
2022-05-03 15:27:09 +05:30
|
|
|
import TopNav from 'container/TopNav';
|
|
|
|
|
import React, { ReactNode, useEffect, useRef } from 'react';
|
2022-04-05 18:21:25 +05:30
|
|
|
import { useTranslation } from 'react-i18next';
|
2022-04-08 13:49:33 +05:30
|
|
|
import { useQueries } from 'react-query';
|
2022-04-05 18:21:25 +05:30
|
|
|
import { useDispatch, useSelector } from 'react-redux';
|
2022-03-24 12:06:57 +05:30
|
|
|
import { useLocation } from 'react-router-dom';
|
2022-04-05 18:21:25 +05:30
|
|
|
import { Dispatch } from 'redux';
|
2021-10-11 16:21:15 +05:30
|
|
|
import { AppState } from 'store/reducers';
|
2022-04-05 18:21:25 +05:30
|
|
|
import AppActions from 'types/actions';
|
|
|
|
|
import {
|
2022-11-14 14:29:13 +05:30
|
|
|
UPDATE_CONFIGS,
|
2022-04-05 18:21:25 +05:30
|
|
|
UPDATE_CURRENT_ERROR,
|
|
|
|
|
UPDATE_CURRENT_VERSION,
|
2022-10-03 21:27:42 +05:30
|
|
|
UPDATE_FEATURE_FLAGS,
|
2022-04-05 18:21:25 +05:30
|
|
|
UPDATE_LATEST_VERSION,
|
|
|
|
|
UPDATE_LATEST_VERSION_ERROR,
|
|
|
|
|
} from 'types/actions/app';
|
2021-10-11 16:21:15 +05:30
|
|
|
import AppReducer from 'types/reducer/app';
|
2021-05-16 18:35:50 +05:30
|
|
|
|
2022-05-03 15:27:09 +05:30
|
|
|
import { ChildrenContainer, Layout } from './styles';
|
2021-05-16 18:35:50 +05:30
|
|
|
|
2022-03-24 12:06:57 +05:30
|
|
|
function AppLayout(props: AppLayoutProps): JSX.Element {
|
2021-10-11 16:21:15 +05:30
|
|
|
const { isLoggedIn } = useSelector<AppState, AppReducer>((state) => state.app);
|
2022-03-24 12:06:57 +05:30
|
|
|
const { pathname } = useLocation();
|
2022-04-05 18:21:25 +05:30
|
|
|
const { t } = useTranslation();
|
2021-05-23 14:15:13 +05:30
|
|
|
|
2022-10-03 21:27:42 +05:30
|
|
|
const [
|
|
|
|
|
getUserVersionResponse,
|
|
|
|
|
getUserLatestVersionResponse,
|
|
|
|
|
getFeaturesResponse,
|
2022-11-14 14:29:13 +05:30
|
|
|
getDynamicConfigsResponse,
|
2022-10-03 21:27:42 +05:30
|
|
|
] = useQueries([
|
2022-04-08 13:49:33 +05:30
|
|
|
{
|
|
|
|
|
queryFn: getUserVersion,
|
|
|
|
|
queryKey: 'getUserVersion',
|
|
|
|
|
enabled: isLoggedIn,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
queryFn: getUserLatestVersion,
|
|
|
|
|
queryKey: 'getUserLatestVersion',
|
|
|
|
|
enabled: isLoggedIn,
|
|
|
|
|
},
|
2022-10-03 21:27:42 +05:30
|
|
|
{
|
|
|
|
|
queryFn: getFeaturesFlags,
|
|
|
|
|
queryKey: 'getFeatureFlags',
|
|
|
|
|
},
|
2022-11-14 14:29:13 +05:30
|
|
|
{
|
|
|
|
|
queryFn: getDynamicConfigs,
|
|
|
|
|
queryKey: 'getDynamicConfigs',
|
|
|
|
|
},
|
2022-04-08 13:49:33 +05:30
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
2022-10-03 21:27:42 +05:30
|
|
|
if (getFeaturesResponse.status === 'idle') {
|
|
|
|
|
getFeaturesResponse.refetch();
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-08 13:49:33 +05:30
|
|
|
if (getUserLatestVersionResponse.status === 'idle' && isLoggedIn) {
|
|
|
|
|
getUserLatestVersionResponse.refetch();
|
|
|
|
|
}
|
2022-04-05 18:21:25 +05:30
|
|
|
|
2022-04-08 13:49:33 +05:30
|
|
|
if (getUserVersionResponse.status === 'idle' && isLoggedIn) {
|
|
|
|
|
getUserVersionResponse.refetch();
|
|
|
|
|
}
|
2022-10-04 13:43:58 +05:30
|
|
|
if (getFeaturesResponse.status === 'idle') {
|
|
|
|
|
getFeaturesResponse.refetch();
|
|
|
|
|
}
|
2022-11-14 14:29:13 +05:30
|
|
|
if (getDynamicConfigsResponse.status === 'idle') {
|
|
|
|
|
getDynamicConfigsResponse.refetch();
|
|
|
|
|
}
|
2022-10-03 21:27:42 +05:30
|
|
|
}, [
|
|
|
|
|
getFeaturesResponse,
|
|
|
|
|
getUserLatestVersionResponse,
|
|
|
|
|
getUserVersionResponse,
|
|
|
|
|
isLoggedIn,
|
2022-11-14 14:29:13 +05:30
|
|
|
getDynamicConfigsResponse,
|
2022-10-03 21:27:42 +05:30
|
|
|
]);
|
2022-04-05 18:21:25 +05:30
|
|
|
|
2022-03-24 12:06:57 +05:30
|
|
|
const { children } = props;
|
2021-05-23 14:15:13 +05:30
|
|
|
|
2022-04-05 18:21:25 +05:30
|
|
|
const dispatch = useDispatch<Dispatch<AppActions>>();
|
|
|
|
|
|
|
|
|
|
const latestCurrentCounter = useRef(0);
|
|
|
|
|
const latestVersionCounter = useRef(0);
|
2022-11-14 14:29:13 +05:30
|
|
|
const latestConfigCounter = useRef(0);
|
2022-04-05 18:21:25 +05:30
|
|
|
|
2022-04-01 15:47:39 +05:30
|
|
|
useEffect(() => {
|
2022-04-08 13:49:33 +05:30
|
|
|
if (
|
|
|
|
|
getUserLatestVersionResponse.isFetched &&
|
|
|
|
|
getUserLatestVersionResponse.isError &&
|
|
|
|
|
latestCurrentCounter.current === 0
|
|
|
|
|
) {
|
2022-04-05 18:21:25 +05:30
|
|
|
latestCurrentCounter.current = 1;
|
|
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
|
type: UPDATE_LATEST_VERSION_ERROR,
|
|
|
|
|
payload: {
|
|
|
|
|
isError: true,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
notification.error({
|
|
|
|
|
message: t('oops_something_went_wrong_version'),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-08 13:49:33 +05:30
|
|
|
if (
|
|
|
|
|
getUserVersionResponse.isFetched &&
|
|
|
|
|
getUserVersionResponse.isError &&
|
|
|
|
|
latestVersionCounter.current === 0
|
|
|
|
|
) {
|
2022-04-05 18:21:25 +05:30
|
|
|
latestVersionCounter.current = 1;
|
|
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
|
type: UPDATE_CURRENT_ERROR,
|
|
|
|
|
payload: {
|
|
|
|
|
isError: true,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
notification.error({
|
|
|
|
|
message: t('oops_something_went_wrong_version'),
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-10-04 13:43:58 +05:30
|
|
|
if (
|
|
|
|
|
getFeaturesResponse.isFetched &&
|
|
|
|
|
getFeaturesResponse.isSuccess &&
|
|
|
|
|
getFeaturesResponse.data &&
|
|
|
|
|
getFeaturesResponse.data.payload
|
|
|
|
|
) {
|
|
|
|
|
dispatch({
|
|
|
|
|
type: UPDATE_FEATURE_FLAGS,
|
|
|
|
|
payload: {
|
|
|
|
|
...getFeaturesResponse.data.payload,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-04-05 18:21:25 +05:30
|
|
|
|
2022-04-08 13:49:33 +05:30
|
|
|
if (
|
|
|
|
|
getUserVersionResponse.isFetched &&
|
|
|
|
|
getUserLatestVersionResponse.isSuccess &&
|
|
|
|
|
getUserVersionResponse.data &&
|
|
|
|
|
getUserVersionResponse.data.payload
|
|
|
|
|
) {
|
2022-04-05 18:21:25 +05:30
|
|
|
dispatch({
|
|
|
|
|
type: UPDATE_CURRENT_VERSION,
|
|
|
|
|
payload: {
|
2022-04-08 13:49:33 +05:30
|
|
|
currentVersion: getUserVersionResponse.data.payload.version,
|
2022-04-05 18:21:25 +05:30
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-08 13:49:33 +05:30
|
|
|
if (
|
|
|
|
|
getUserLatestVersionResponse.isFetched &&
|
|
|
|
|
getUserLatestVersionResponse.isSuccess &&
|
|
|
|
|
getUserLatestVersionResponse.data &&
|
|
|
|
|
getUserLatestVersionResponse.data.payload
|
|
|
|
|
) {
|
2022-04-05 18:21:25 +05:30
|
|
|
dispatch({
|
|
|
|
|
type: UPDATE_LATEST_VERSION,
|
|
|
|
|
payload: {
|
2022-05-10 12:59:15 +05:30
|
|
|
latestVersion: getUserLatestVersionResponse.data.payload.tag_name,
|
2022-04-05 18:21:25 +05:30
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-10-03 21:27:42 +05:30
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
getFeaturesResponse.isFetched &&
|
|
|
|
|
getFeaturesResponse.isSuccess &&
|
|
|
|
|
getFeaturesResponse.data &&
|
|
|
|
|
getFeaturesResponse.data.payload
|
|
|
|
|
) {
|
|
|
|
|
dispatch({
|
|
|
|
|
type: UPDATE_FEATURE_FLAGS,
|
|
|
|
|
payload: {
|
|
|
|
|
...getFeaturesResponse.data.payload,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-11-14 14:29:13 +05:30
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
getDynamicConfigsResponse.isFetched &&
|
|
|
|
|
getDynamicConfigsResponse.isSuccess &&
|
|
|
|
|
getDynamicConfigsResponse.data &&
|
|
|
|
|
getDynamicConfigsResponse.data.payload &&
|
|
|
|
|
latestConfigCounter.current === 0
|
|
|
|
|
) {
|
|
|
|
|
latestConfigCounter.current = 1;
|
|
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
|
type: UPDATE_CONFIGS,
|
|
|
|
|
payload: {
|
|
|
|
|
configs: getDynamicConfigsResponse.data.payload,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-04-05 18:21:25 +05:30
|
|
|
}, [
|
|
|
|
|
dispatch,
|
|
|
|
|
isLoggedIn,
|
|
|
|
|
pathname,
|
|
|
|
|
t,
|
2022-04-08 13:49:33 +05:30
|
|
|
getUserLatestVersionResponse.isLoading,
|
|
|
|
|
getUserLatestVersionResponse.isError,
|
|
|
|
|
getUserLatestVersionResponse.data,
|
|
|
|
|
getUserVersionResponse.isLoading,
|
|
|
|
|
getUserVersionResponse.isError,
|
|
|
|
|
getUserVersionResponse.data,
|
|
|
|
|
getUserLatestVersionResponse.isFetched,
|
|
|
|
|
getUserVersionResponse.isFetched,
|
|
|
|
|
getUserLatestVersionResponse.isSuccess,
|
2022-10-03 21:27:42 +05:30
|
|
|
getFeaturesResponse.isFetched,
|
|
|
|
|
getFeaturesResponse.isSuccess,
|
|
|
|
|
getFeaturesResponse.data,
|
2022-11-14 14:29:13 +05:30
|
|
|
getDynamicConfigsResponse.data,
|
|
|
|
|
getDynamicConfigsResponse.isFetched,
|
|
|
|
|
getDynamicConfigsResponse.isSuccess,
|
2022-04-05 18:21:25 +05:30
|
|
|
]);
|
2022-04-01 15:47:39 +05:30
|
|
|
|
2022-05-03 15:27:09 +05:30
|
|
|
const isToDisplayLayout = isLoggedIn;
|
|
|
|
|
|
2021-05-16 18:35:50 +05:30
|
|
|
return (
|
2021-12-02 20:12:38 +05:30
|
|
|
<Layout>
|
2022-05-03 15:27:09 +05:30
|
|
|
{isToDisplayLayout && <Header />}
|
2021-12-02 20:12:38 +05:30
|
|
|
<Layout>
|
2022-05-03 15:27:09 +05:30
|
|
|
{isToDisplayLayout && <SideNav />}
|
|
|
|
|
<Layout.Content>
|
|
|
|
|
<ChildrenContainer>
|
|
|
|
|
{isToDisplayLayout && <TopNav />}
|
|
|
|
|
{children}
|
|
|
|
|
</ChildrenContainer>
|
|
|
|
|
</Layout.Content>
|
2021-05-16 18:35:50 +05:30
|
|
|
</Layout>
|
|
|
|
|
</Layout>
|
|
|
|
|
);
|
2022-03-24 12:06:57 +05:30
|
|
|
}
|
2021-05-16 18:35:50 +05:30
|
|
|
|
2021-10-22 17:05:10 +05:30
|
|
|
interface AppLayoutProps {
|
|
|
|
|
children: ReactNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default AppLayout;
|