forked from summit-webapp-themes/maxima
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.tsx
75 lines (70 loc) · 2.9 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import type { NextPage } from "next";
import { CONSTANTS } from "../services/config/app-config";
import MetaTag from "../services/api/general_apis/meta-tag-api";
import HomePage from "../components/HomePage";
import Header from "../components/Header/Header";
import { getMultiCurrencyValue } from "../services/api/general_apis/default-currency-api";
import MultiLangApi from "../services/api/general_apis/multilanguage-api";
import { useDispatch, useSelector } from "react-redux";
import { setDefaultCurrencyValue } from "../store/slices/general_slices/multi-currency-slice";
import { setMultiLingualData } from "../store/slices/general_slices/multilang-slice";
import { setRevalidationTime } from "../store/slices/general_slices/cache-slice";
import { askForPermissionToReceiveNotifications } from "../push-notifications";
const Home: NextPage = (fetchedDataFromServer: any) => {
askForPermissionToReceiveNotifications();
console.log("check data of server obj", fetchedDataFromServer);
const dispatch = useDispatch();
const getCurrentTimestamp = Date.now();
dispatch(setRevalidationTime(getCurrentTimestamp));
dispatch(
setDefaultCurrencyValue(fetchedDataFromServer?.defaultCurrencyValue)
);
dispatch(setMultiLingualData(fetchedDataFromServer?.multiLingualValues));
return (
<>
{CONSTANTS.ENABLE_META_TAGS && (
<Header meta_data={fetchedDataFromServer?.metaTagsDataFromAPI} />
)}
<div>
<HomePage
default_currency_value={fetchedDataFromServer?.defaultCurrencyValue}
multi_lingual_values={fetchedDataFromServer?.multiLingualValues}
/>
</div>
</>
);
};
export async function getServerSideProps(context: any) {
let fetchedDataFromServer: any = {};
const method = "get_meta_tags";
const version = "v1";
const entity = "seo";
const params = `?version=${version}&method=${method}&entity=${entity}`;
const url = `${context.resolvedUrl.split("?")[0]}`;
if (CONSTANTS.ENABLE_META_TAGS) {
let meta_data: any = await MetaTag(
`${CONSTANTS.API_BASE_URL}${CONSTANTS.API_MANDATE_PARAMS}${params}&page_name=${url}`
);
if (meta_data?.status === 200 && Object.keys(meta_data).length > 0) {
fetchedDataFromServer.metaTagsDataFromAPI =
meta_data?.data?.message?.data;
} else {
fetchedDataFromServer = {};
}
}
let get_default_currency_value: any = await getMultiCurrencyValue();
if (get_default_currency_value?.status === 200) {
fetchedDataFromServer.defaultCurrencyValue =
get_default_currency_value?.data?.message;
} else {
fetchedDataFromServer.defaultCurrencyValue = {};
}
let get_multi_lingual_data_value: any = await MultiLangApi();
if (get_multi_lingual_data_value?.length > 0) {
fetchedDataFromServer.multiLingualValues = get_multi_lingual_data_value;
} else {
fetchedDataFromServer.multiLingualValues = [];
}
return { props: fetchedDataFromServer };
}
export default Home;