-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
125 lines (116 loc) · 5.49 KB
/
App.js
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import React, { Component } from 'react';
import AsyncStorage from '@react-native-community/async-storage';
import { NativeRouter as Router, Route, Switch } from "react-router-native";
import { DefaultTheme, Provider as PaperProvider } from 'react-native-paper';
import jwt_decode from 'jwt-decode';
import { Provider } from 'react-redux';
import SplashScreen from 'react-native-splash-screen'
import store from './store';
import { setCurrentUser } from './src/actions/authActions';
import PrivateRoute from './src/components/common/PrivateRoute';
import setAuthToken from './src/utils/setAuthToken';
import Login from './src/components/log/Login';
import Register from './src/components/log/Register';
import ForgotPass from './src/components/log/ForgotPass';
import Home from './src/components/home/Home';
import Products from './src/components/products/Productos';
import PerfilInfo from './src/components/perfil/PerfilInfo';
import Perfil from './src/components/perfil/Perfil';
import DetailProduct from './src/components/products/DetailProduct';
import Favorites from './src/components/favorites/Favorites';
import Cart from './src/components/common/Cart';
import Direcciones from './src/components/perfil/Direcciones';
import AddDir from './src/components/perfil/AddDir';
import EditAdd from './src/components/perfil/EditAdd';
import Facturas from './src/components/perfil/Facturas';
import AddBills from './src/components/perfil/AddBills';
import Search from './src/components/search/Search';
import Pedidos from './src/components/perfil/Pedidos';
import ProgramarEnvio from './src/components/common/ProgramarEnvio';
import DetalleCompra from './src/components/perfil/DetalleCompra';
import Tracking from './src/components/common/Tracking';
import ReturnMap from './src/components/common/ReturnMap';
import ChangeAddress from './src/components/common/ChangeAddress';
import Password from './src/components/perfil/Password';
//Check for token
AsyncStorage.getItem('jwtToken').then(token => {
if(token){
setAuthToken(token);
const decode = jwt_decode(token);
//Set user and isAuthenticated
store.dispatch(setCurrentUser(decode));
}
});
//Set auth token header auth
//Decode token and get user inf and exp
const theme = {
...DefaultTheme,
roundness: 2,
colors: {
...DefaultTheme.colors,
primary: '#41CE6C',
background: '#F3F0EC'
}
};
class App extends Component {
state = {
numItem: 0,
mapDelivery: false
}
componentDidMount(){
SplashScreen.hide();
this.sumItem()
AsyncStorage.getItem('MAP', (err, res) => {
this.setState({mapDelivery: res})
})
}
sumItem = () => {
AsyncStorage.getItem('CART', (err, res) => {
let json = JSON.parse(res);
if(json){
let numberItems = Object.keys(json).length;
this.setState({numItem: numberItems})
}
})
}
render() {
let mostrar = null;
if(this.state.mapDelivery !== 'true'){
mostrar = <ReturnMap />
}
return (
<Provider store={store}>
<PaperProvider theme={theme}>
<Router>
<Switch>
<Route exact path="/" component={Login} />
<Route exact path="/register" component={Register} />
<Route exact path="/forgot" component={ForgotPass} />
<PrivateRoute exact path="/home" component={Home} numberItems={this.state.numItem} />
<PrivateRoute exact path="/products/:homeSeccion/:idHome" component={Products} numberItems={this.state.numItem} />
<PrivateRoute exact path="/detail-product/:idProduct" component={DetailProduct} addItem={this.sumItem} numberItems={this.state.numItem} />
<PrivateRoute exact path="/perfil-info" component={PerfilInfo} numberItems={this.state.numItem} />
<PrivateRoute exact path="/perfil" component={Perfil} numberItems={this.state.numItem} />
<PrivateRoute exact path="/password" component={Password} numberItems={this.state.numItem} />
<PrivateRoute exact path="/direcciones" component={Direcciones} numberItems={this.state.numItem} />
<PrivateRoute exact path="/add-direccion" component={AddDir} numberItems={this.state.numItem} />
<PrivateRoute exact path="/edit-direccion/:idAdd" component={EditAdd} numberItems={this.state.numItem} />
<PrivateRoute exact path="/datos-facturacion" component={Facturas} numberItems={this.state.numItem} />
<PrivateRoute exact path="/add-facturas/:idBill" component={AddBills} numberItems={this.state.numItem} />
<PrivateRoute exact path="/pedidos" component={Pedidos} numberItems={this.state.numItem} />
<PrivateRoute exact path="/detalle-compra/:idCompra" component={DetalleCompra} numberItems={this.state.numItem} />
<PrivateRoute exact path="/favorites" component={Favorites} numberItems={this.state.numItem} />
<PrivateRoute exact path="/cart" component={Cart} numberItems={this.state.numItem} addItem={this.sumItem} />
<PrivateRoute exact path="/programar-envio" component={ProgramarEnvio} numberItems={this.state.numItem} />
<PrivateRoute exact path="/change-address" component={ChangeAddress} />>
<PrivateRoute exact path="/search" component={Search} numberItems={this.state.numItem} />
<PrivateRoute exact path="/tracking" component={Tracking} numberItems={this.state.numItem}/>
</Switch>
{mostrar}
</Router>
</PaperProvider>
</Provider>
);
}
}
export default App;