%PDF- %PDF-
Direktori : /home/emergentqj/actioncivile/pre-auth/.632e77b3fb93bc8da5b589b869bc0037/static/js/ |
Current File : /home/emergentqj/actioncivile/pre-auth/.632e77b3fb93bc8da5b589b869bc0037/static/js/index.js |
import React from "react"; import { hydrate, render } from "react-dom"; import { Provider as ReduxProvider } from "react-redux"; import mixpanel from "mixpanel-browser"; import { MixpanelProvider } from "react-mixpanel"; import { ThemeProvider as StyledComponentsThemeProvider } from "styled-components"; import { ThemeProvider } from "@material-ui/styles"; import { CookiesProvider } from "react-cookie"; import { BrowserRouter } from "react-router-dom"; import MIXPANEL_ACTIONS from "constants/mixpanel_actions"; import { initMixpanel, trackMixpanelActions } from "utils/mixpanel"; import App from "containers/AppContainer"; import theme from "common/components/theme"; import { BASE_PATH } from "constants/common"; import configFunc from "config/config"; import "assets/css/global.css"; import TagManager from "react-gtm-module"; import axios from "axios"; import { setLanguageCookie } from "utils/languages"; import { setCountryCookie } from "utils/countries"; import countryConfig from "config/countryData"; import * as Sentry from "@sentry/browser"; import store from "./store"; import init from "./init"; import sagas from "./sagas"; import history from "./utils/history"; import { styledComponentsTheme } from "./themes/styledComponentsTheme"; Sentry.init({ dsn: "https://ee104f5c977b11ebaa1a528878d8d438@sentry.io/5708923", debug: process.env.NODE_ENV !== "production", environment: process.env.NODE_ENV, }); // Google Tag Manager const tagManagerArgs = { gtmId: "GTM-KZ393PS", }; TagManager.initialize(tagManagerArgs); sagas.forEach((saga) => { store.runSaga(saga, store.dispatch); }); init(store); initMixpanel(); // We deal with otp's in the backend, // but, just in case, let's investigate the url, // and if it should contain sso_code, redirect to the backend const urlParams = new URLSearchParams(window.location.search); const country = urlParams.get("country"); const language = urlParams.get("lang"); if (country) { setCountryCookie(country); } if (language) { setLanguageCookie(language); } const availableLanguages = countryConfig.langData.map(({ code }) => code); if ( ((country && !countryConfig.countryData[country]) || (language && !availableLanguages.includes(language))) && !urlParams.has("sso_code")) { window.location = "/"; } if (urlParams.has("sso_code")) { const config = configFunc(); const url = `${config.apiUrl}otp${window.location.search}&returnurl=true`; trackMixpanelActions(MIXPANEL_ACTIONS.SIGN_IN_SSO_ATTEMPT, { url }); axios.get(url, { withCredentials: true }).then((response) => { const props = { requestedUrl: url, sso: true, }; if (response?.data?.auth) { props.id = response?.data?.auth?.currentLoginId; props.accountType = response?.data?.auth?.accountType; props.customerType = response?.data?.auth?.groupedAccesses.length > 0 ? "DUAL" : response?.data?.auth?.customerType; props.CUId = response?.data?.auth?.customerIds[0]; props.countPU = response?.data?.auth?.parkingUserIds.length; props.countBA = response?.data?.auth?.billingAccountIds.length; trackMixpanelActions(MIXPANEL_ACTIONS.SIGN_IN_SUCCESS, props); } else { trackMixpanelActions(MIXPANEL_ACTIONS.SIGN_IN_FAILURE, props); } window.location.replace(response.data.url); return null; }); // window.location.replace(`${config.apiUrl}otp${window.location.search}`); } function Root() { return ( <ReduxProvider history={history} store={store}> <CookiesProvider> <BrowserRouter basename={BASE_PATH} > <MixpanelProvider mixpanel={mixpanel}> <StyledComponentsThemeProvider theme={styledComponentsTheme}> <ThemeProvider theme={theme}> <App store={store} /> </ThemeProvider> </StyledComponentsThemeProvider> </MixpanelProvider> </BrowserRouter> </CookiesProvider> </ReduxProvider> ); } const rootElement = document.getElementById("root"); if (rootElement.hasChildNodes()) { hydrate(<Root />, rootElement); } else { render(<Root />, rootElement); }