Commit 7e4f60cc by Tonk

update edit profile

parent 81ccd73d
import app from '../../firebase';
export const GET_CURRENT_USER = 'GET_CURRENT_USER'; export const GET_CURRENT_USER = 'GET_CURRENT_USER';
export const getCurrentUserAction = (displayName, email, emailVerified, phoneNumber, uid, photoURL) => ({ export const getCurrentUserAction = (displayName, email, emailVerified, phoneNumber, uid, photoURL) => ({
...@@ -18,18 +20,19 @@ export const getCurrentUser = user => async dispatch => { ...@@ -18,18 +20,19 @@ export const getCurrentUser = user => async dispatch => {
export const updateUser = userData => async (dispatch, getState) => { export const updateUser = userData => async (dispatch, getState) => {
const { currentUserReducer } = getState(); const { currentUserReducer } = getState();
const { displayName, email, emailVerified, uid, phoneNumber, photoURL } = currentUserReducer; const { email, emailVerified, uid, photoURL } = currentUserReducer;
try { try {
await user.updateProfile({
displayName: `${userData.firstName} ${userData.lastName}`,
phoneNumber: userData.phoneNumber,
});
const newDisplayName = `${userData.firstName} ${userData.lastName}`; const newDisplayName = `${userData.firstName} ${userData.lastName}`;
const newPhoneNumber = userData.phoneNumber; const newPhoneNumber = userData.phoneNumber;
dispatch(getCurrentUserAction(newDisplayName, email, emailVerified, uid, newPhoneNumber, photoURL)); const user = app.auth().currentUser;
await user.updateProfile({
displayName: newDisplayName,
phoneNumber: newPhoneNumber,
});
dispatch(getCurrentUserAction(newDisplayName, email, emailVerified, newPhoneNumber, uid, photoURL));
} catch (error) { } catch (error) {
console.log('Update user failed!', error); console.log('Update user failed!', error);
} }
......
...@@ -24,11 +24,15 @@ class EditProfileScreen extends React.Component { ...@@ -24,11 +24,15 @@ class EditProfileScreen extends React.Component {
state = { state = {
confirmModal: false, confirmModal: false,
profileImg: this.props.profileImg, photoURL: this.props.photoURL,
firstName: this.props.firstName, firstName: '',
lastName: this.props.lastName, lastName: '',
phoneNumber: this.props.phoneNumber, phoneNumber: this.props.phoneNumber,
}; };
componentDidMount() {
const splitName = this.props.displayName ? this.props.displayName.split(' ') : null;
this.setState({ firstName: splitName[0], lastName: splitName[1] });
}
toggleModal = value => { toggleModal = value => {
this.setState({ confirmModal: value }); this.setState({ confirmModal: value });
}; };
...@@ -41,7 +45,7 @@ class EditProfileScreen extends React.Component { ...@@ -41,7 +45,7 @@ class EditProfileScreen extends React.Component {
}; };
render() { render() {
const { profileImg, firstName, lastName, phoneNumber, confirmModal } = this.state; const { photoURL, firstName, lastName, phoneNumber, confirmModal } = this.state;
return ( return (
<View style={theme.container}> <View style={theme.container}>
<Text style={[theme.normalText, theme.textDark, theme.mt2, { marginLeft: 20 }]}>Edit Profile</Text> <Text style={[theme.normalText, theme.textDark, theme.mt2, { marginLeft: 20 }]}>Edit Profile</Text>
...@@ -131,9 +135,8 @@ const styles = StyleSheet.create({ ...@@ -131,9 +135,8 @@ const styles = StyleSheet.create({
const mapStateToProps = state => ({ const mapStateToProps = state => ({
email: state.currentUserReducer.email, email: state.currentUserReducer.email,
phoneNumber: state.currentUserReducer.phoneNumber, phoneNumber: state.currentUserReducer.phoneNumber,
firstName: state.currentUserReducer.firstName, displayName: state.currentUserReducer.displayName,
lastName: state.currentUserReducer.lastName, photoURL: state.currentUserReducer.photoURL,
profileImg: state.currentUserReducer.profileImg,
}); });
const mapDispatchToProps = { const mapDispatchToProps = {
......
...@@ -32,12 +32,12 @@ class ProfileScreen extends React.Component { ...@@ -32,12 +32,12 @@ class ProfileScreen extends React.Component {
}); });
render() { render() {
const { email, phoneNumber, profileImg, displayName } = this.props; const { email, phoneNumber, photoURL, displayName } = this.props;
return ( return (
<View style={theme.container}> <View style={theme.container}>
<View style={styles.headerStyle}> <View style={styles.headerStyle}>
<Card style={styles.imgProfileContainer}> <Card style={styles.imgProfileContainer}>
{profileImg ? ( {photoURL ? (
<></> <></>
) : ( ) : (
<Icon <Icon
...@@ -136,9 +136,8 @@ const styles = StyleSheet.create({ ...@@ -136,9 +136,8 @@ const styles = StyleSheet.create({
const mapStateToProps = state => ({ const mapStateToProps = state => ({
email: state.currentUserReducer.email, email: state.currentUserReducer.email,
phoneNumber: state.currentUserReducer.phoneNumber, phoneNumber: state.currentUserReducer.phoneNumber,
firstName: state.currentUserReducer.firstName, displayName: state.currentUserReducer.displayName,
lastName: state.currentUserReducer.lastName, photoURL: state.currentUserReducer.photoURL,
profileImg: state.currentUserReducer.profileImg,
}); });
const mapDispatchToProps = {}; const mapDispatchToProps = {};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment