2022-04-29 17:37:19 -04:00
|
|
|
import React, { useEffect } from 'react';
|
2021-09-02 19:05:13 -07:00
|
|
|
import './App.less';
|
2022-04-29 17:37:19 -04:00
|
|
|
import { THIRD_PARTY_LOGGING_KEY } from './app/analytics/analytics';
|
|
|
|
import { checkAuthStatus } from './app/auth/checkAuthStatus';
|
2021-09-02 19:05:13 -07:00
|
|
|
import { AppConfigContext, DEFAULT_APP_CONFIG } from './appConfigContext';
|
|
|
|
import { useAppConfigQuery } from './graphql/app.generated';
|
|
|
|
|
2022-09-01 17:06:30 -07:00
|
|
|
function changeFavicon(src) {
|
2022-09-13 16:20:09 -07:00
|
|
|
const links = document.querySelectorAll("link[rel~='icon']") as any;
|
|
|
|
if (!links || links.length === 0) {
|
|
|
|
const link = document.createElement('link');
|
2022-09-01 17:06:30 -07:00
|
|
|
link.rel = 'icon';
|
|
|
|
document.getElementsByTagName('head')[0].appendChild(link);
|
|
|
|
}
|
2022-09-13 16:20:09 -07:00
|
|
|
links.forEach((link) => {
|
|
|
|
// eslint-disable-next-line no-param-reassign
|
|
|
|
link.href = src;
|
|
|
|
});
|
2022-09-01 17:06:30 -07:00
|
|
|
}
|
|
|
|
|
2021-09-02 19:05:13 -07:00
|
|
|
const AppConfigProvider = ({ children }: { children: React.ReactNode }) => {
|
|
|
|
const { data: appConfigData, refetch } = useAppConfigQuery();
|
|
|
|
|
|
|
|
const refreshAppConfig = () => {
|
|
|
|
refetch();
|
|
|
|
};
|
|
|
|
|
2022-04-29 17:37:19 -04:00
|
|
|
useEffect(() => {
|
|
|
|
if (appConfigData && appConfigData.appConfig) {
|
|
|
|
if (appConfigData.appConfig.telemetryConfig.enableThirdPartyLogging) {
|
|
|
|
localStorage.setItem(THIRD_PARTY_LOGGING_KEY, 'true');
|
|
|
|
checkAuthStatus(); // identify in analyitcs once we receive config response
|
|
|
|
} else {
|
|
|
|
localStorage.setItem(THIRD_PARTY_LOGGING_KEY, 'false');
|
|
|
|
}
|
2022-09-01 17:06:30 -07:00
|
|
|
changeFavicon(appConfigData.appConfig.visualConfig.faviconUrl);
|
2022-04-29 17:37:19 -04:00
|
|
|
}
|
|
|
|
}, [appConfigData]);
|
|
|
|
|
2021-09-02 19:05:13 -07:00
|
|
|
return (
|
|
|
|
<AppConfigContext.Provider
|
|
|
|
value={{ config: appConfigData?.appConfig || DEFAULT_APP_CONFIG, refreshContext: refreshAppConfig }}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</AppConfigContext.Provider>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default AppConfigProvider;
|