Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Feature/edit profile loader #2323

Merged
merged 4 commits into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/actions/updateUserProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export function updateUserProfile(data, profileType, forcePromisify) {
return new Promise(function(resolve, reject) {
putAuthenticatedRequest(profileTypeToReq[profileType], data)
.then(res => {
const {statusText} = res;
if (res.data && res.data instanceof Object) {
if (res.data.merge) {
dispatch(
Expand All @@ -151,11 +152,18 @@ export function updateUserProfile(data, profileType, forcePromisify) {
if (res.data.merge) resolve(res.data);
forcePromisify && resolve(res.data);
dispatch(setProgressModelState(false));
NotificationManager.success(statusText, i18n.t('label.success'), 5000);

})
.catch(err => {
debug(err);
reject(err);
dispatch(setProgressModelState(false));
NotificationManager.error(
err.response.data.message,
i18n.t('label.error'),
5000
);
});
});
};
Expand Down
20 changes: 16 additions & 4 deletions app/components/Common/Button/PrimaryButton.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,34 @@ import React from 'react';
import PropTypes from 'prop-types';
import TouchableItem from '../TouchableItem';
import styles from '../../../styles/common/button';
import { Text, Image, View } from 'react-native';
import {Text, Image, View, ActivityIndicator} from 'react-native';
const PrimaryButton = ({
onClick,
children,
buttonStyle,
textStyle,
image
image,
loading = false,
}) => (
<TouchableItem
activeOpacity={0.6}
onPress={() => onClick()}
style={[styles.primaryButton, buttonStyle]}
disabled={loading}
>
<View style={styles.textContainer}>
<Image source={image} style={image ? styles.image : { width: 0 }} />
<Text style={[styles.primaryButtonText, textStyle]}>{children}</Text>
{loading ? (
<ActivityIndicator
norbertschuler marked this conversation as resolved.
Show resolved Hide resolved
size="large"
color="white"
/>
):(
<>
<Image source={image} style={image ? styles.image : { width: 0 }} />
<Text style={[styles.primaryButtonText, textStyle]}>{children}</Text>
</>

)}
</View>
</TouchableItem>
);
Expand Down
31 changes: 27 additions & 4 deletions app/components/EditUserProfile/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export default class EditUserProfile extends Component {
this.setState({ passwordNotSameError: value });

_renderScene = ({ route }) => {
const { onSave, currentUserProfile } = this.props;
const { onSave, currentUserProfile, loading } = this.props;
const { treecounter: treeCounter } = currentUserProfile;
switch (route.key) {
case 'basic':
Expand All @@ -161,6 +161,7 @@ export default class EditUserProfile extends Component {
onSave={onSave}
currentUserProfile={currentUserProfile}
getFormSchemaOption={this.getFormSchemaOption}
loading={loading}
/>
);
// break;
Expand All @@ -170,6 +171,7 @@ export default class EditUserProfile extends Component {
onSave={onSave}
currentUserProfile={currentUserProfile}
getFormSchemaOption={this.getFormSchemaOption}
loading={loading}
/>
);
case 'following':
Expand Down Expand Up @@ -232,6 +234,7 @@ export default class EditUserProfile extends Component {
navigation={this.props.navigation}
deleteProfile={this.props.deleteProfile}
changeEmail={this.changeEmail}
loading={loading}
onSamePasswordErrorState={this.changePasswordErrorState}
/>
);
Expand Down Expand Up @@ -290,9 +293,9 @@ class BasicTabView extends React.PureComponent {
constructor(props) {
super(props);
}

render() {
const { type } = this.props.currentUserProfile;

return (
<KeyboardAwareScrollView enableOnAndroid>
<CardLayout style={{ flex: 1 }}>
Expand All @@ -311,6 +314,7 @@ class BasicTabView extends React.PureComponent {
/>
</View>
<PrimaryButton
loading={this.props.loading}
onClick={() => {
this.props.onSave(type, 'profile', this.refs);
}}
Expand All @@ -326,6 +330,7 @@ class BasicTabView extends React.PureComponent {
BasicTabView.propTypes = {
onSave: PropTypes.func.isRequired,
currentUserProfile: PropTypes.object,
loading: PropTypes.bool,
getFormSchemaOption: PropTypes.func
};

Expand All @@ -348,6 +353,7 @@ class DescriptionTabView extends React.PureComponent {
/>
</View>
<PrimaryButton
loading={this.props.loading}
onClick={() => {
this.props.onSave(type, 'about_me', this.refs);
}}
Expand All @@ -362,17 +368,25 @@ class DescriptionTabView extends React.PureComponent {

DescriptionTabView.propTypes = {
onSave: PropTypes.func.isRequired,
loading: PropTypes.bool,
currentUserProfile: PropTypes.object,
getFormSchemaOption: PropTypes.func
};

class SecurityTabView extends React.PureComponent {

constructor(props) {
super(props);
this.state={
emailButtonPress: false,
changPassworsdButtonPress: false,
}
}

render() {
const { type } = this.props.currentUserProfile;
const {loading} = this.props;
const {emailButtonPress, changPassworsdButtonPress} = this.state;
return (
<KeyboardAwareScrollView enableOnAndroid>
<CardLayout style={{ flex: 1 }}>
Expand All @@ -387,7 +401,12 @@ class SecurityTabView extends React.PureComponent {
</Text>
</View>
<PrimaryButton
loading={emailButtonPress && loading}
onClick={() => {
this.setState({
emailButtonPress: true,
changPassworsdButtonPress:false,
});
this.props.changeEmail(this.refs.change_email);
}}
>
Expand All @@ -406,6 +425,7 @@ class SecurityTabView extends React.PureComponent {
/>
</View>
<PrimaryButton
loading={changPassworsdButtonPress && loading}
onClick={() => {
let value = this.refs.password.getValue();
if (
Expand All @@ -416,11 +436,13 @@ class SecurityTabView extends React.PureComponent {
//same password
this.props.onSamePasswordErrorState(true);
this.setState({
passwordNotSameError: true
emailButtonPress:false,
passwordNotSameError: true,
changPassworsdButtonPress:true,
});
return;
}
this.props.onSamePasswordErrorState(true);
this.props.onSamePasswordErrorState(false);
this.props.onSave(type, 'password', this.refs);
}}
>
Expand All @@ -444,6 +466,7 @@ class SecurityTabView extends React.PureComponent {

SecurityTabView.propTypes = {
onSave: PropTypes.func.isRequired,
loading: PropTypes.bool,
currentUserProfile: PropTypes.object,
getFormSchemaOption: PropTypes.func,
navigation: PropTypes.object,
Expand Down
6 changes: 4 additions & 2 deletions app/containers/EditUserProfile/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { bindActionCreators } from 'redux';
import PropTypes from 'prop-types';
import { debug } from '../../debug';
import EditUserProfile from '../../components/EditUserProfile';
import { currentUserProfileSelector } from '../../selectors/index';
import {currentUserProfileSelector, getProgressModelSelector} from '../../selectors/index';
import {
updateUserProfile,
updatePlantProject,
Expand Down Expand Up @@ -250,6 +250,7 @@ class EditUserProfileContainer extends React.Component {
navigation={this.props.navigation}
followeeList={this.state.followeeInfo}
unfollowUser={this.props.unfollowUser}
{...this.props}
/>
);
}
Expand All @@ -260,7 +261,8 @@ EditUserProfileContainer.propTypes = {
};

const mapStateToProps = state => ({
currentUserProfile: currentUserProfileSelector(state)
currentUserProfile: currentUserProfileSelector(state),
loading: getProgressModelSelector(state),
});

const mapDispatchToProps = dispatch => {
Expand Down