-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProfile.js
181 lines (175 loc) · 5.01 KB
/
Profile.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
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
import * as React from "react";
import {
StyleSheet,
Text,
TextInput,
View,
TouchableOpacity,
} from "react-native";
class Profile extends React.Component {
constructor(props) {
super(props);
this.state = {
username: "",
firstName: "",
lastName: "",
calorieGoal: "",
activityGoal: "",
};
}
static navigationOptions = {
title: "Profile",
};
async componentDidMount() {
const username = this.props.navigation.state.params.username;
let response = await fetch(
"https://avigael-shop-fitness.herokuapp.com/users/" + username,
{
method: "GET",
headers: {
Accept: "*/*",
"x-access-token": this.props.navigation.state.params.token,
Connection: "keep-alive",
"cache-control": "no-cache",
},
}
);
response = await response.json();
this.setState({
username: response.username,
firstName: response.firstName,
lastName: response.lastName,
calorieGoal: response.goalDailyCalories,
activityGoal: response.goalDailyActivity,
});
}
update = () => {
fetch(
"https://avigael-shop-fitness.herokuapp.com/users/" + this.state.username,
{
method: "PUT",
headers: {
Accept: "*/*",
Connection: "keep-alive",
"cache-control": "no-cache",
"Content-Type": "application/json",
"x-access-token": this.props.navigation.state.params.token,
},
body: JSON.stringify({
username: this.state.username,
firstName: this.state.firstName,
lastName: this.state.lastName,
goalDailyCalories: this.state.calorieGoal,
goalDailyActivity: this.state.activityGoal,
}),
}
)
.then((response) => {
return response.json();
})
.then((response) => {
alert(response.message);
});
};
render() {
const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: "column",
justifyContent: "center",
alignItems: "center",
},
input_box: {
width: "75%",
height: 40,
marginBottom: 25,
},
input_title: {
color: "#121212",
marginTop: -20,
},
input_placeholder: {
flex: 1,
padding: 10,
borderRadius: 10,
color: "#121212",
backgroundColor: "rgba(230,230,230,1)",
},
btn_shape: {
backgroundColor: "rgba(99,206,237,1)",
borderRadius: 10,
width: "40%",
height: 40,
marginBottom: 15,
justifyContent: "center",
},
btn_text: {
color: "rgba(255,255,255,1)",
fontSize: 16,
textAlign: "center",
fontWeight: "bold",
},
});
return (
<View style={styles.container}>
<View style={styles.input_box}>
<Text style={styles.input_title}>First Name</Text>
<TextInput
style={styles.input_placeholder}
placeholder={"First name"}
value={this.state.firstName}
onChangeText={(text) => {
this.setState({ firstName: text });
}}
/>
</View>
<View style={styles.input_box}>
<Text style={styles.input_title}>Last Name</Text>
<TextInput
style={styles.input_placeholder}
placeholder={"Last name"}
value={this.state.lastName}
onChangeText={(text) => {
this.setState({ lastName: text });
}}
/>
</View>
<View style={styles.input_box}>
<Text style={styles.input_title}>Calorie Goal</Text>
<TextInput
style={styles.input_placeholder}
placeholder={"Set your calorie goal"}
value={this.state.calorieGoal + ""}
onChangeText={(text) => {
this.setState({ calorieGoal: text });
}}
/>
</View>
<View style={styles.input_box}>
<Text style={styles.input_title}>Activity Goal</Text>
<TextInput
style={styles.input_placeholder}
placeholder={"Set your activity goal"}
value={this.state.activityGoal + ""}
onChangeText={(text) => {
this.setState({ activityGoal: text });
}}
/>
</View>
<TouchableOpacity
onPress={() => this.update()}
style={styles.btn_shape}
>
<Text style={styles.btn_text}>Update</Text>
</TouchableOpacity>
<TouchableOpacity
onPress={() => this.props.navigation.navigate("Login")}
style={[styles.btn_shape, { backgroundColor: "red" }]}
>
<Text style={styles.btn_text}>Log Out</Text>
</TouchableOpacity>
</View>
);
}
}
export default Profile;