-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.tsx
57 lines (53 loc) · 2.25 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import React, { useEffect } from 'react';
import MultiLangApi from '../services/api/general-apis/multilanguage-api';
import { CONSTANTS } from '../services/config/app-config';
import { useDispatch } from 'react-redux';
import { setMultiLingualData } from '../store/slices/general_slices/multilang-slice';
import MetaTag from '../services/api/general-apis/meta-tag-api';
import useGoogleAnalyticsOperationsHandler from '../hooks/GoogleAnalytics/useGoogleAnalyticsOperationsHandler';
import PageMetaData from '../components/PageMetaData';
import HomePageMaster from '../components/HomePage/HomePageMaster';
const Home = ({ fetchedDataFromServer }: any) => {
const dispatch = useDispatch();
const { sendPageViewToGA } = useGoogleAnalyticsOperationsHandler();
useEffect(() => {
sendPageViewToGA(window.location.pathname + window.location.search, 'Home Page');
if (fetchedDataFromServer?.multiLingualListTranslationTextList) {
dispatch(setMultiLingualData(fetchedDataFromServer.multiLingualListTranslationTextList));
}
}, []);
return (
<>
{CONSTANTS.ENABLE_META_TAGS && <PageMetaData meta_data={fetchedDataFromServer?.metaTagsData} />}
<HomePageMaster />
</>
);
};
export async function getServerSideProps(context: any) {
const { SUMMIT_APP_CONFIG } = CONSTANTS;
let fetchedDataFromServer: any = {};
const method = 'get_meta_tags';
const version = SUMMIT_APP_CONFIG.version;
const entity = 'seo';
const params = `?version=${version}&method=${method}&entity=${entity}`;
const url = `${context.resolvedUrl.split('?')[0]}`;
if (CONSTANTS.ENABLE_META_TAGS) {
let metaData: any = await MetaTag(`${CONSTANTS.API_BASE_URL}${SUMMIT_APP_CONFIG.app_name}${params}&page_name=${url}`);
if (metaData.status === 200 && metaData?.data?.message?.msg === 'success' && metaData?.data?.message?.data !== 'null') {
fetchedDataFromServer.metaTagsData = metaData?.data?.message?.data;
}
}
const multiLangParams = {
appConfig: SUMMIT_APP_CONFIG,
};
const MultilanguageData = await MultiLangApi(multiLangParams.appConfig);
if (MultilanguageData?.length > 0) {
fetchedDataFromServer.multiLingualListTranslationTextList = MultilanguageData;
}
return {
props: {
fetchedDataFromServer,
},
};
}
export default Home;