-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProfileScreen.js
More file actions
193 lines (178 loc) · 4.48 KB
/
ProfileScreen.js
File metadata and controls
193 lines (178 loc) · 4.48 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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import React, { Component } from 'react';
import{
Alert,
StyleSheet,
Image,
ScrollView,
View,
TouchableOpacity,
Text,
TouchableNativeFeedback,
} from 'react-native';
import{
InputWithLabel
} from './UI';
import{
FloatingAction
} from 'react-native-floating-action';
import Mailer from 'react-native-mail';
const actions=[{
text:'Edit',
icon: require('./icons/baseline_edit_white_18dp.png'),
name:'edit',
positon: 1
}];
let config = require('./config');
Date.prototype.formatted = function() {
let day = this.getDay();
let date = this.getDate();
let month = this.getMonth();
let year = this.getFullYear();
let daysText = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];
let monthsText = [
'Jan','Feb','Mar','Apr','May','Jun',
'Jul','Aug','Sep','Oct','Nov','Dec'
];
return `${daysText[day]}, ${monthsText[month]} ${date}, ${year}`;
}
type Props ={};
export default class ProfileScreen extends Component<Props>{
static navigationOptions = {
title: 'Profile',
headerStyle: {
backgroundColor: 'royalblue'
}
};
constructor(props){
super(props)
this.state={
id:this.props.navigation.getParam('id'),
member:null,
};
this.handleEmail = this.handleEmail.bind(this);
this._load = this._load.bind(this);
}
componentDidMount(){
this._load();
}
_load(){
let url= config.settings.serverPath + '/api/members/' + this.state.id;
fetch(url)
.then((response)=>{
if(!response.ok){
Alert.alert('Error', response.status.toString());
throw Error('Error' + response.status);
}
return response.json()
})
.then((member)=>{
this.setState({member:member});
})
.catch((error)=>{
console.error(error);
});
}
handleEmail = () => {
Mailer.mail({
subject: 'Enter Subject Here',
recipients: ['support@awesomemall.com'],
body: 'Enter Description Here',
isHTML: true,
}, (error, event) => {
Alert.alert(
error,
event,
[
{text: 'Ok', onPress: () => console.log('OK: Email Error Response')},
{text: 'Cancel', onPress: () => console.log('CANCEL: Email Error Response')}
],
{ cancelable: true }
)
});
}
render(){
let member = this.state.member;
return(
<View style={styles.container}>
<ScrollView>
<Image style={styles.profilepic} source={require('./icons/twotone_account_circle_black_48dp.png')}/>
<InputWithLabel style={styles.output}
label={'Card Number'}
value={member ? member.cardnumber:''}
orientation={'vertical'}
editable={false}
/>
<InputWithLabel style={styles.output}
label={'Name'}
value={member ? member.name:''}
orientation={'vertical'}
editable={false}
/>
<InputWithLabel style={styles.output}
label={'Contact Number'}
value={member ? member.contactnumber:''}
orientation={'vertical'}
editable={false}
/>
<InputWithLabel style={styles.output}
label={'Reward Point'}
value={member ? member.rewardpoint.toString():''}
orientation={'vertical'}
editable={false}
/>
<InputWithLabel style={styles.output}
label={'Membership'}
value={member ? new Date(member.membership).formatted() : ''}
orientation={'vertical'}
editable={false}
/>
</ScrollView>
<TouchableOpacity
onPress={ () => {this.handleEmail()}}
>
<View>
<Image style={styles.icon} source={require('./icons/baseline_email_black_36dp.png')}/>
<Text>Send Enquiry</Text>
</View>
</TouchableOpacity>
<FloatingAction
actions={actions}
overrideWithAction={true}
color={'#0abab5'}
onPressItem={(name)=>{
this.props.navigation.navigate('Update', {
id: member ? member.id : 0,
headerTitle: member ? member.name : '',
refresh: this._load,
});
}
}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 20,
backgroundColor: '#fff',
},
output: {
fontSize: 24,
color: '#000099',
marginTop: 10,
marginBottom: 10,
},
profilepic:{
width:100,
height:100,
alignSelf:'center'
},
icon:{
marginLeft:10,
marginRight:5,
width: 60,
height: 60,
},
});