This repository has been archived by the owner on Aug 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextras.js
118 lines (115 loc) · 3.58 KB
/
extras.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
import React, { Component } from 'react';
import { BackAndroid, BackHandler } from "react-native";
import * as SecureStore from 'expo-secure-store';
import { Container, Header, Content, List, ListItem, Text, Separator, Right, Card, CardItem, Left, Thumbnail, Body, Title, Icon, Button } from 'native-base';
import Signin from './Signin';
export default class Extras extends Component {
constructor(props) {
super(props);
this.state = {
name: null,
roll: null,
token: null,
data: [{ 'Message': 'extra', "value": 10, 'date': "12-23-23", 'token': 1 }],
exit: false
}
this.fetchData = this.fetchData.bind(this)
this.fetchData();
}
componentDidMount() {
BackHandler.addEventListener('hardwareBackPress', this.handleBackButton);
}
componentWillUnmount() {
BackHandler.removeEventListener('hardwareBackPress', this.handleBackButton);
}
handleBackButton() {
if (!this.state.exit) {
ToastAndroid.show('Press again to exit', ToastAndroid.SHORT);
this.setState({
exit: true
});
return true
}
else
BackAndroid.exitApp();
}
async fetchData() {
const token = await SecureStore.getItemAsync('token');
const name = await SecureStore.getItemAsync('name');
const roll = await SecureStore.getItemAsync('roll')
let res = await fetch("http://nitc-mess.anandu.net/api/users/dues",
{
"credentials": "omit", "headers": { "accept": "*/*", "Authorization": `Bearer ${token}` },
"method": "GET"
}
).then(res => res.json())
this.setState({
data: res,
name,
roll,
token
})
}
componentWillUnmount(){
}
render() {
// if(this.state.token==null){
// this.props.navigation.goBack();
// }
this.extras = this.state.data.map((data, key) =>
<ListItem last key={key}>
<Text>{data.message}</Text>
<Text style={{ marginLeft: 'auto' }}>Rs.{data.amount}</Text>
<Text style={{ marginLeft: 50 }}>{(new Date(data.updatedAt)).toLocaleDateString()}</Text>
</ListItem>
);
this.sum = this.state.data.reduce((prev, cur) => cur.amount + prev, 0)
console.log(this.sum)
if (this.state.token) {
return (
<Container>
<Content>
<Card style={{ margin: 0 }}>
<CardItem>
<Left>
<Thumbnail source={require('./assets/thumbnail.png')} />
<Body>
<Text>{this.state.name}</Text>
<Text note>{this.state.roll}</Text>
</Body>
</Left>
<Right>
<Button icon transparent onPress={async () => {
await SecureStore.deleteItemAsync('token');
this.setState({
token: null
})
console.log('ext screen')
}}>
<Icon name="sign-out-alt" type='FontAwesome5' />
</Button>
</Right>
</CardItem>
</Card>
{this.extras}
</Content>
<ListItem />
<ListItem />
<Content style={{ position: 'absolute', left: 0, right: 0, bottom: 0 }}>
<Card>
<CardItem>
<Body>
<Text style={{ marginLeft: 'auto', fontWeight: 'bold' }}>
TOTAL: Rs. {this.sum}
</Text>
</Body>
</CardItem>
</Card>
</Content>
</Container>
);
} else {
return <Signin />
}
}
}