-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathApp.tsx
76 lines (65 loc) · 2.23 KB
/
App.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
76
import React, { useEffect } from 'react';
import { DefaultTheme, Provider as PaperProvider } from 'react-native-paper';
import * as Sentry from 'sentry-expo';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { REACT_NATIVE_SENTRY_DSN } from 'react-native-dotenv';
import _ from 'lodash';
import axios from 'axios';
import { getRootUrl, registerForPushNotificationsAsync } from './src/helpers/helpers';
import MainView from './src/components/mainView/MainView';
import './i18n';
const rootUrl = getRootUrl();
// sentry
Sentry.init({
dsn: REACT_NATIVE_SENTRY_DSN || (process.env.REACT_NATIVE_SENTRY_DSN ? process.env.REACT_NATIVE_SENTRY_DSN : ''),
enableInExpoDevelopment: true,
debug: process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test' ? true : false, // Sentry will try to print out useful debugging information if something goes wrong with sending an event. Set this to `false` in production.
});
const theme = {
...DefaultTheme,
colors: {
...DefaultTheme.colors,
primary: '#ed1f30',
accent: '#2b76f0',
},
};
function App(): JSX.Element {
useEffect(() => {
getPushNotificationToken();
}, []);
const getPushNotificationToken = async () => {
const pushNotificationToken = await registerForPushNotificationsAsync();
console.log('pushNotificationToken = ', pushNotificationToken);
storeAsyncStorageData('@pushNotificationToken', pushNotificationToken);
await addPushNotificationTokenToServer(pushNotificationToken);
};
const storeAsyncStorageData = async (key: string, value: any) => {
try {
await AsyncStorage.setItem(key, value);
} catch (e) {
console.log('error = ', e.message);
}
};
const addPushNotificationTokenToServer = async (pushNotificationToken: string) => {
const response = await axios.post(
`${rootUrl}/expo/add-push-notification-token-to-server`,
{
pushNotificationToken: pushNotificationToken,
},
{
headers: {
'Content-Type': 'application/json',
},
},
);
if (!_.isEmpty(response)) {
console.log('response = ', response);
}
};
return (
<PaperProvider theme={theme}>
<MainView />
</PaperProvider>
);
}
export default App;