App.js
2.9 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
import React,{ Component } from 'react'
import { StyleSheet, Text, View, AppRegistry,Linking } from 'react-native';
import App from './components/Navigation/Navigation'
import {post,all } from 'axios'
import withDeepLinking,{ setTopLevelNavigator } from './withDeepLinking';
import firebase from '@react-native-firebase/dynamic-links'
import AsyncStorage from '@react-native-community/async-storage';
import Listen from './components/ListenonBackground'
import { SERVER } from './common/servername';
import { addNavigationHelpers } from 'react-navigation';
class RootApp extends Component {
constructor(props) {
super(props);
this.state = {
loaded: false,
notification: null,
messageText: ''
};
}
async componentDidMount() {
try {
let url = await firebase().getInitialLink();
//console.log(url.url)
if(url && url.url.indexOf("sanggatalk.io/app/coupon") > 0) {
AsyncStorage.getItem("user",(err,res) => {
if(res) {
console.log({UserId:JSON.parse(res).id,id:url.url.split('?params=')[1]})
post(`http://${SERVER}/coupons/private/gift`,{UserId:JSON.parse(res).id,id:url.url.split('?params=')[1]}).then(Res => {
if(Res.data.success) {
alert("쿠폰이 성공적으로 지급되었습니다.")
}
})
}
else {
AsyncStorage.setItem("present",JSON.stringify(true))
}
})
}
if(url && url.url.indexOf("sanggatalk.io/app/stamp") > 0) {
AsyncStorage.getItem("user",(err,res) => {
if(res) {
const num = parseInt(url.url.split('?params=')[1].split(',')[2])
all([...Array(num)].map((e,i) => post(`http://${SERVER}/stamps/users`,{UserId:JSON.parse(res).id,StampId:url.url.split('?params=')[1].split(',')[1],StoreId:url.url.split('?params=')[1].split(',')[0]}))).then(res => {
if(res[0].data.success) {
alert("스탬프가 성공적으로 지급되었습니다.")
}
})
}
else {
AsyncStorage.setItem("present",JSON.stringify(true))
}
})
}
}
catch(err) {
console.log(err)
}
}
render() {
const { loaded } = this.state;
return (
<>
<App uriPrefix='sanggatalk://' ref={
navigatorRef => {
setTopLevelNavigator(navigatorRef);
}}/>
</>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
AppRegistry.registerComponent('main', () => RootApp);
export default RootApp