* TP-25597 apm integration * update config with default qa TP-25597 * remove unused pacakge TP-255957 * rename cosmos-app APM TP-255957 * remove unnecasary file TP-255957
136 lines
4.3 KiB
TypeScript
136 lines
4.3 KiB
TypeScript
import React, { useEffect } from 'react';
|
|
import {
|
|
AppState,
|
|
KeyboardAvoidingView,
|
|
LogBox,
|
|
Permission,
|
|
PermissionsAndroid,
|
|
Platform,
|
|
StatusBar,
|
|
} from 'react-native';
|
|
import { Provider } from 'react-redux';
|
|
import { init as initApm } from '@cobo/apm-rum-react-native';
|
|
import store, { persistor } from './src/store/store';
|
|
import { PersistGate } from 'redux-persist/integration/react';
|
|
|
|
import { NavigationContainer } from '@react-navigation/native';
|
|
import { navigationRef } from './src/components/utlis/navigationUtlis';
|
|
import FullScreenLoader from './RN-UI-LIB/src/components/FullScreenLoader';
|
|
import { toastConfigs, ToastContainer } from './RN-UI-LIB/src/components/toast';
|
|
|
|
import * as Sentry from '@sentry/browser';
|
|
import { APM_APP_NAME, APM_BASE_URL, ENV, SENTRY_DSN } from './src/constants/config';
|
|
import { COLORS } from './RN-UI-LIB/src/styles/colors';
|
|
import codePush from 'react-native-code-push';
|
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
import { LocalStorageKeys, PermissionsToCheck } from './src/common/Constants';
|
|
import Permissions from './src/screens/permissions/Permissions';
|
|
import { setJsErrorHandler } from './src/services/exception-handler.service';
|
|
import SuspenseLoader from './RN-UI-LIB/src/components/suspense_loader/SuspenseLoader';
|
|
import ErrorBoundary from './src/common/ErrorBoundary';
|
|
import BlockerScreen from './src/common/BlockerScreen';
|
|
import CodePush from 'react-native-code-push';
|
|
import { TDocumentObj } from './src/screens/caseDetails/interface';
|
|
import AuthRouter from './src/screens/auth/AuthRouter';
|
|
|
|
Sentry.init({ dsn: SENTRY_DSN });
|
|
|
|
if (ENV !== 'prod') {
|
|
// mockApiServer();
|
|
}
|
|
setJsErrorHandler();
|
|
LogBox.ignoreAllLogs();
|
|
|
|
export let GlobalDocumentMap: Record<string, TDocumentObj> = {};
|
|
|
|
async function checkCodePushAndSync() {
|
|
try {
|
|
await CodePush.sync({
|
|
installMode: codePush.InstallMode.IMMEDIATE,
|
|
});
|
|
} catch (error) {}
|
|
}
|
|
|
|
function handleAppStateChange(nextAppState: any) {
|
|
if (nextAppState == 'active') {
|
|
checkCodePushAndSync();
|
|
}
|
|
}
|
|
|
|
const askForPermissions = async (setPermissions: React.Dispatch<React.SetStateAction<boolean>>) => {
|
|
if (Platform.OS === 'android') {
|
|
PermissionsAndroid.requestMultiple(PermissionsToCheck)
|
|
.then(async (result) => {
|
|
let isAllPermissionsGranted = true;
|
|
for (const permission in result) {
|
|
if (!(result?.[permission as Permission] === PermissionsAndroid.RESULTS.GRANTED)) {
|
|
isAllPermissionsGranted = false;
|
|
break;
|
|
}
|
|
}
|
|
setPermissions(isAllPermissionsGranted);
|
|
})
|
|
.catch((err) => {
|
|
setPermissions(false);
|
|
});
|
|
}
|
|
};
|
|
|
|
const App = () => {
|
|
const [permissions, setPermissions] = React.useState(true);
|
|
const [isGlobalDocumentMapLoaded, setIsGlobalDocumentMapLoaded] = React.useState(false);
|
|
|
|
initApm({
|
|
serviceName: APM_APP_NAME,
|
|
serverUrl: APM_BASE_URL,
|
|
serviceVersion: '1.0.0',
|
|
environment: ENV,
|
|
active: true,
|
|
});
|
|
|
|
React.useEffect(() => {
|
|
const appStateChange = AppState.addEventListener('change', (change) => {
|
|
handleAppStateChange(change);
|
|
askForPermissions(setPermissions);
|
|
});
|
|
(async () => {
|
|
const data = await AsyncStorage.getItem(LocalStorageKeys.GLOBAL_DOCUMENT_MAP);
|
|
if (data) {
|
|
const parsedData = JSON.parse(data);
|
|
GlobalDocumentMap = parsedData;
|
|
}
|
|
setIsGlobalDocumentMapLoaded(true);
|
|
})();
|
|
checkCodePushAndSync();
|
|
return () => {
|
|
appStateChange.remove();
|
|
};
|
|
}, []);
|
|
|
|
return (
|
|
<Provider store={store}>
|
|
<PersistGate loading={<FullScreenLoader loading />} persistor={persistor}>
|
|
<NavigationContainer ref={navigationRef}>
|
|
<StatusBar backgroundColor={COLORS.BACKGROUND.INDIGO_DARK} />
|
|
<SuspenseLoader
|
|
fallBack={<FullScreenLoader loading />}
|
|
loading={!isGlobalDocumentMapLoaded}
|
|
children={
|
|
<ErrorBoundary>
|
|
<BlockerScreen>{permissions ? <AuthRouter /> : <Permissions />}</BlockerScreen>
|
|
</ErrorBoundary>
|
|
}
|
|
/>
|
|
</NavigationContainer>
|
|
{
|
|
<KeyboardAvoidingView behavior="position">
|
|
<ToastContainer config={toastConfigs} position="bottom" />
|
|
</KeyboardAvoidingView>
|
|
}
|
|
</PersistGate>
|
|
</Provider>
|
|
);
|
|
};
|
|
|
|
export default App;
|