ENEI2019-Public/App/app/screens/Profile.js

427 lines
14 KiB
JavaScript
Raw Normal View History

2019-03-04 16:36:16 +00:00
import React, {Component} from 'react'
2019-03-04 16:38:58 +00:00
import {Card, Divider,} from 'react-native-elements'
2019-03-04 16:36:16 +00:00
import {
Image,
ImageBackground,
Linking,
ListView,
Platform,
ScrollView,
StyleSheet,
Text,
View,
TouchableOpacity,
Dimensions,
TextInput,
2019-03-04 16:38:58 +00:00
Button,
2019-03-04 16:36:16 +00:00
} from 'react-native'
import PropTypes from 'prop-types';
import {connect, Provider} from "react-redux";
import {bindActionCreators} from "redux";
import * as Actions from "../store/actions";
2019-03-04 16:38:58 +00:00
import {Validate} from '../Helpers/Validation'
import {RkTextInput} from 'react-native-ui-kitten';
2019-03-04 16:36:16 +00:00
import {createStore} from 'redux';
import Email from '../components/Email';
import Separator from '../components/Separator';
import Tel from '../components/Telephone';
2019-03-04 16:38:58 +00:00
2019-03-04 16:36:16 +00:00
const SCREEN_HEIGHT = Dimensions.get("window").height;
const SCREEN_WIDTH = Dimensions.get("window").width;
import Icon from "react-native-vector-icons/Ionicons"
class Profile extends Component {
constructor(props) {
super(props);
this.state = {
2019-03-11 18:11:51 +00:00
name: this.props.user.Name,
userDetails: {},
2019-03-04 16:36:16 +00:00
token: false,
tokenData: '',
loggedIn: false,
onHold: true,
user: {},
2019-03-04 16:38:58 +00:00
cenas: {Name: 'as'},
text: '',
formValid: true,
2019-03-04 23:57:08 +00:00
jobs: this.props.user.Company,
2019-03-04 16:38:58 +00:00
jobsError: false,
jobsErrorMessage: '',
email: this.props.user.Email,
emailError: false,
2019-03-13 20:42:20 +00:00
emailErrorMessage: '',
2019-03-04 16:38:58 +00:00
phone: this.props.user.Mobile,
phoneError: false,
phoneErrorMessage: '',
2019-03-04 23:57:08 +00:00
address: this.props.user.Address,
2019-03-04 16:38:58 +00:00
addressError: false,
addressErrorMessage: '',
city: this.props.user.City,
cityError: false,
cityErrorMessage: '',
2019-03-12 07:31:41 +00:00
oldPass:'',
new1:'',
new2:'',
url:this.props.user.Url,
curso:this.props.user.LastName,
2019-03-04 16:36:16 +00:00
};
}
2019-03-04 16:38:58 +00:00
2019-03-12 07:31:41 +00:00
_press=()=>{
this.props.changePassword(
2019-03-15 22:07:22 +00:00
this.props.token,
2019-03-12 07:31:41 +00:00
this.state.oldPass,
this.state.new1,
this.state.new2
)
}
2019-03-04 16:36:16 +00:00
_logout = () => {
2019-03-04 16:38:58 +00:00
this.props.logoutUser();
};
2019-03-04 16:36:16 +00:00
2019-03-11 18:11:51 +00:00
_validateData = (name, jobs, email, phone, address, city) => {
2019-03-04 16:38:58 +00:00
let valid = null;
2019-03-11 18:11:51 +00:00
v = Validate('name', name);
2019-03-04 23:57:08 +00:00
2019-03-04 16:38:58 +00:00
let v = Validate('email', email);
this.setState({emailError: v[0], emailErrorMessage: v[1]});
v = Validate('jobs', jobs);
// setState is asynchronous and so trying to work with state directly after a setState
// call won't work as the update won't necessarily have run. Instead you can use the second argument to setState which is a callback
this.setState({jobsError: v[0], jobsErrorMessage: v[1]}, () => {
console.log('email error: ' + this.state.emailError + ' job Error: ' + this.state.jobsError);
});
v = Validate('city', city);
// setState is asynchronous and so trying to work with state directly after a setState
// call won't work as the update won't necessarily have run. Instead you can use the second argument to setState which is a callback
this.setState({cityError: v[0], cityErrorMessage: v[1]})
v = Validate('address', address);
// setState is asynchronous and so trying to work with state directly after a setState
// call won't work as the update won't necessarily have run. Instead you can use the second argument to setState which is a callback
this.setState({addressError: v[0], addressErrorMessage: v[1]});
v = Validate('city', city);
// setState is asynchronous and so trying to work with state directly after a setState
// call won't work as the update won't necessarily have run. Instead you can use the second argument to setState which is a callback
this.setState({cityError: v[0], cityErrorMessage: v[1]}, () => {
console.log(this.state.cityError + ' Error: ' + this.state.addressError);
if (this.state.emailError || this.state.jobsError || this.state.phoneError || this.state.addressError || this.state.cityError)
this.setState({formValid: false});
});
};
saveData() {
2019-03-12 07:31:41 +00:00
const {name, jobs, email, phone, address, city, formValid, url,curso} = this.state;
2019-03-04 16:38:58 +00:00
2019-03-12 07:31:41 +00:00
// this._validateData(name, jobs, email, phone, address, city,curso);
2019-03-04 16:38:58 +00:00
console.log(formValid);
2019-03-11 18:11:51 +00:00
if (formValid) {
2019-03-04 16:38:58 +00:00
console.log("data valid");
2019-03-04 23:57:08 +00:00
2019-03-15 22:07:22 +00:00
this.props.updateUser(this.props.token, {
2019-03-11 18:11:51 +00:00
Name: this.state.name,
Company: jobs,
2019-03-12 07:31:41 +00:00
LastName: curso,
2019-03-11 18:11:51 +00:00
Address: address,
City: city,
Mobile: phone,
2019-03-12 07:31:41 +00:00
Avatar: "base64",
Url:url,
2019-03-11 18:11:51 +00:00
});
2019-03-12 07:31:41 +00:00
2019-03-04 23:57:08 +00:00
}
2019-03-04 16:38:58 +00:00
else
console.log("data not valid");
2019-03-04 16:36:16 +00:00
}
2019-03-04 16:38:58 +00:00
2019-03-04 16:36:16 +00:00
render() {
return (
2019-03-04 16:38:58 +00:00
<View style={{flex: 1}}>
<ScrollView style={{backgroundColor: '#eee'}}>
<View style={styles.container}>
<View style={styles.userBioRowHeader}>
<View style={styles.userBioRowTitle}>
2019-03-12 07:31:41 +00:00
<Text style={{color: '#CC1A17', fontWeight: 'bold', fontSize: 20}}>Informações Pessoais</Text>
2019-03-04 16:38:58 +00:00
</View>
2019-03-12 07:31:41 +00:00
2019-03-04 16:38:58 +00:00
</View>
<View style={styles.userBio}>
<View style={styles.userBioRow}>
2019-03-12 07:31:41 +00:00
<Text style={styles.userBioLogo} >Nome</Text>
2019-03-04 16:36:16 +00:00
2019-03-04 16:38:58 +00:00
<TextInput style={styles.userBioText}
2019-03-04 23:57:08 +00:00
onChangeText={(n) => {
2019-03-11 18:11:51 +00:00
this.setState({name: n})
2019-03-04 16:38:58 +00:00
}}
2019-03-04 23:57:08 +00:00
value={this.state.name}/>
2019-03-04 16:38:58 +00:00
</View>
<Divider style={{backgroundColor: 'black'}}/>
<View style={styles.userBioRow}>
2019-03-12 07:31:41 +00:00
<Text style={styles.userBioLogo} >Curso</Text>
<TextInput style={styles.userBioText}
onChangeText={(cu) => {
this.setState({curso: cu})
}}
value={this.state.curso}/>
</View>
<Divider style={{backgroundColor: 'black'}}/>
<View style={styles.userBioRow}>
<Text style={styles.userBioLogo} >Faculdade</Text>
2019-03-04 16:38:58 +00:00
<TextInput style={styles.userBioText}
2019-03-04 23:57:08 +00:00
onChangeText={(job) => {
this.setState({jobs: job})
2019-03-04 16:38:58 +00:00
}}
2019-03-04 23:57:08 +00:00
value={this.state.jobs}/>
2019-03-04 16:38:58 +00:00
</View>
<Divider style={{backgroundColor: 'black'}}/>
<View style={styles.userBioRow}>
2019-03-12 07:31:41 +00:00
<Text style={styles.userBioLogo} >Telemóvel</Text>
2019-03-04 16:38:58 +00:00
<TextInput style={styles.userBioText}
onChangeText={(phone) => {
this.setState({phone: phone})
}}
value={this.state.phone}/>
</View>
<Divider style={{backgroundColor: 'black'}}/>
<View style={styles.userBioRow}>
2019-03-12 07:31:41 +00:00
<Text style={styles.userBioLogo} >Morada</Text>
2019-03-04 16:38:58 +00:00
<TextInput style={styles.userBioText}
onChangeText={(add) => {
this.setState({address: add})
}}
value={this.state.address}/>
</View>
<Divider style={{backgroundColor: 'black'}}/>
<View style={styles.userBioRow}>
2019-03-12 07:31:41 +00:00
<Text style={styles.userBioLogo} >LinkedIn</Text>
2019-03-04 16:38:58 +00:00
<TextInput style={styles.userBioText}
2019-03-12 07:31:41 +00:00
onChangeText={(u) => {
this.setState({url: u})
2019-03-04 16:38:58 +00:00
}}
2019-03-12 07:31:41 +00:00
value={this.state.url}/>
2019-03-04 16:38:58 +00:00
</View>
2019-03-12 07:31:41 +00:00
<Button onPress={() => this.saveData() } title="Guardar Alterações" color="#CC1A17"
/>
2019-03-04 16:36:16 +00:00
</View>
2019-03-04 16:38:58 +00:00
</View>
{/*PassWord Edit*/}
<View style={styles.container}>
<View style={styles.userBioRowHeader}>
<View style={styles.userBioRowTitle}>
2019-03-12 07:31:41 +00:00
<Text style={{color: '#CC1A17', fontWeight: 'bold', fontSize: 20}}>Alterar Password</Text>
2019-03-04 16:38:58 +00:00
</View>
2019-03-04 16:36:16 +00:00
</View>
2019-03-04 16:38:58 +00:00
<View style={styles.userBio}>
2019-03-12 07:31:41 +00:00
2019-03-04 16:38:58 +00:00
2019-03-12 07:31:41 +00:00
<View style={styles.userBioRow}>
2019-03-04 16:38:58 +00:00
<TextInput style={styles.userBioText}
2019-03-12 07:31:41 +00:00
placeholder='Antiga Password'
onChangeText={(old => {
this.setState({oldPass: old})
})}
value={this.state.oldPass}
maxLength = {20}
secureTextEntry={true}
2019-03-04 16:38:58 +00:00
/>
</View>
2019-03-12 07:31:41 +00:00
<Divider style={{backgroundColor: 'black'}}/>
2019-03-04 16:38:58 +00:00
<View style={styles.userBioRow}>
2019-03-12 07:31:41 +00:00
2019-03-04 16:38:58 +00:00
<TextInput style={styles.userBioText}
2019-03-12 07:31:41 +00:00
placeholder='Nova Password'
secureTextEntry={true}
onChangeText={(newz => {
this.setState({new1: newz})
})}
value={this.state.new1}
maxLength = {20}
2019-03-04 16:38:58 +00:00
/>
</View>
2019-03-12 07:31:41 +00:00
<Divider style={{backgroundColor: 'black'}}/>
2019-03-04 16:38:58 +00:00
<View style={styles.userBioRow}>
2019-03-12 07:31:41 +00:00
2019-03-04 16:38:58 +00:00
<TextInput style={styles.userBioText}
2019-03-12 07:31:41 +00:00
placeholder='Repetir Password'
secureTextEntry={true}
onChangeText={(newzz => {
this.setState({new2: newzz})
})}
value={this.state.new2}
maxLength = {20}
2019-03-04 16:38:58 +00:00
/>
</View>
2019-03-12 07:31:41 +00:00
<Button onPress={this._press} title="Alterar Password" color="#CC1A17"
/>
2019-03-04 16:36:16 +00:00
</View>
</View>
2019-03-04 16:38:58 +00:00
2019-03-12 07:31:41 +00:00
<TouchableOpacity onPress={this._logout} style={{
2019-03-11 18:11:51 +00:00
height: 50,
justifyContent: 'center',
alignItems: 'center',
2019-03-12 07:31:41 +00:00
backgroundColor: 'black',
marginTop:30
2019-03-11 18:11:51 +00:00
}}>
<Text style={{color: "#fff", fontWeight: 'bold'}}>Logout</Text>
2019-03-12 07:31:41 +00:00
2019-03-11 18:11:51 +00:00
</TouchableOpacity>
2019-03-04 16:38:58 +00:00
2019-03-12 07:31:41 +00:00
</ScrollView>
2019-03-04 16:38:58 +00:00
</View>
2019-03-04 16:36:16 +00:00
)
}
}
const styles = StyleSheet.create({
2019-03-04 16:38:58 +00:00
container: {
flex: 1,
padding: 10,
margin: 20,
backgroundColor: 'white',
borderRadius: 5,
},
userBioRowHeader: {
flex: 1,
flexDirection: 'row',
alignItems: 'center',
},
userBioRowTitle: {
flex: 1,
flexDirection: 'row',
justifyContent: 'flex-start',
padding: 10,
},
userBioRow: {
flex: 1,
flexDirection: 'row',
justifyContent: 'flex-start',
2019-03-11 18:11:51 +00:00
padding: 10,
2019-03-12 07:31:41 +00:00
// borderWidth: 2,
2019-03-11 18:11:51 +00:00
alignItems: 'center',
2019-03-04 16:36:16 +00:00
},
2019-03-04 16:38:58 +00:00
userBioText: {
2019-03-11 18:11:51 +00:00
width: SCREEN_WIDTH * 0.40,
flex: 2,
2019-03-12 07:31:41 +00:00
// borderWidth: 2,
2019-03-04 16:36:16 +00:00
},
2019-03-04 16:38:58 +00:00
userPassText: {
flex: 1,
2019-03-11 18:11:51 +00:00
//alignSelf: 'flex-start',
justifyContent: 'flex-end',
borderWidth: 2,
2019-03-04 16:36:16 +00:00
},
2019-03-04 16:38:58 +00:00
userBioLogo: {
2019-03-12 07:31:41 +00:00
marginLeft: 10,
width:80,
2019-03-04 16:38:58 +00:00
},
bottomLogOut: {
height: 20,
2019-03-04 16:36:16 +00:00
},
});
mapStateToProps = (state, props) => {
return {
token: state.apiReducer.token,
2019-03-04 23:57:08 +00:00
user: state.apiReducer.user,
userDetails: state.apiReducer.userDetails,
2019-03-04 16:36:16 +00:00
}
};
function mapDispatchToProps(dispatch) {
return bindActionCreators(Actions, dispatch);
}
2019-02-08 14:23:56 +00:00
export default connect(mapStateToProps, mapDispatchToProps)(Profile);