Commit 224d863e authored by nanahira's avatar nanahira

fix redirect on error

parent e585632f
Pipeline #42171 failed with stages
in 4 seconds
......@@ -29,12 +29,22 @@ class EmailForm extends React.Component {
const { email, password } = values;
dispatch({ type: 'user/updateEmail', payload: { email, password, user_id: id } });
this.setState({ countdown: 5, inCountdown: true });
this.countdownTimer = setInterval(this.handleCountdown, 1000);
dispatch({
type: 'user/updateEmail',
payload: {
email,
password,
user_id: id,
onSuccess: this.startCountdown,
},
});
}
});
};
startCountdown = () => {
this.setState({ countdown: 5, inCountdown: true });
this.countdownTimer = setInterval(this.handleCountdown, 1000);
};
handleCountdown = () => {
// 倒计时减1
this.setState(prevState => ({ countdown: prevState.countdown - 1 }));
......@@ -170,4 +180,3 @@ function mapStateToProps(state) {
const WrapperEmailForm = Form.create()(EmailForm);
export default connect(mapStateToProps)(WrapperEmailForm);
......@@ -28,14 +28,23 @@ class EmailForm extends React.Component {
const { new_password, password } = values;
dispatch({ type: 'user/updateAccount', payload: { new_password, password, user_id: id } });
dispatch({
type: 'user/updateAccount',
payload: {
new_password,
password,
user_id: id,
onSuccess: this.startCountdown,
},
});
}
});
};
startCountdown = () => {
// 设置倒计时状态为5秒
this.setState({ countdown: 5, inCountdown: true });
// 启动倒计时
this.countdownTimer = setInterval(this.handleCountdown, 1000);
}
});
};
handleCountdown = () => {
// 倒计时减1
......@@ -202,4 +211,3 @@ function mapStateToProps(state) {
const WrapperEmailForm = Form.create()(EmailForm);
export default connect(mapStateToProps)(WrapperEmailForm);
......@@ -29,12 +29,22 @@ class EmailForm extends React.Component {
if (!err) {
console.log('Received values of form: ', values);
const { username, password } = values;
dispatch({ type: 'user/updateAccount', payload: { username, password, user_id: id } });
this.setState({ countdown: 5, inCountdown: true });
this.countdownTimer = setInterval(this.handleCountdown, 1000);
dispatch({
type: 'user/updateAccount',
payload: {
username,
password,
user_id: id,
onSuccess: this.startCountdown,
},
});
}
});
};
startCountdown = () => {
this.setState({ countdown: 5, inCountdown: true });
this.countdownTimer = setInterval(this.handleCountdown, 1000);
};
handleCountdown = () => {
// 倒计时减1
this.setState(prevState => ({ countdown: prevState.countdown - 1 }));
......
......@@ -157,46 +157,85 @@ export default {
const token = yield select(state => state.user.token);
const { messages } = yield select(state => state.common);
const { onSuccess, onError, ...restPayload } = payload || {};
try {
const { data } = yield call(updateProfile, { ...payload, token });
const { data } = yield call(updateProfile, { ...restPayload, token });
if (data) {
yield put({ type: 'updateProfileSuccess', payload: { user: data, token } });
message.info(messages.update_success, 3);
if (onSuccess) {
onSuccess(data);
}
return true;
}
} catch (error) {
yield put({ type: 'updateProfileFail' });
message.error(error.message, 3);
if (onError) {
onError(error);
}
return false;
}
if (onError) {
onError(new Error('empty_response'));
}
return false;
},
*updateEmail({ payload }, { call, put, select }) {
const { messages } = yield select(state => state.common);
const { onSuccess, onError, ...restPayload } = payload || {};
try {
const token = yield select(state => state.user.token);
const { data } = yield call(updateAccount, { ...payload, token });
const { data } = yield call(updateAccount, { ...restPayload, token });
if (data) {
yield put({ type: 'updateAccountSuccess', payload: { user: data, token } });
message.info(messages['A-verification-email-has-been-sent-to-you,please-check-the-mail-to-complete.'], 3);
if (onSuccess) {
onSuccess(data);
}
return true;
}
} catch (error) {
yield put({ type: 'updateAccountFail' });
message.error(messages[error.message] || error.message, 3);
if (onError) {
onError(error);
}
return false;
}
if (onError) {
onError(new Error('empty_response'));
}
return false;
},
*updateAccount({ payload }, { call, put, select }) {
const { messages } = yield select(state => state.common);
const { onSuccess, onError, ...restPayload } = payload || {};
try {
const token = yield select(state => state.user.token);
const { data } = yield call(updateAccount, { ...payload, token });
const { data } = yield call(updateAccount, { ...restPayload, token });
if (data) {
yield put({ type: 'updateAccountSuccess', payload: { user: data, token } });
message.info(messages.update_success, 3);
if (onSuccess) {
onSuccess(data);
}
return true;
}
} catch (error) {
yield put({ type: 'updateAccountFail' });
message.error(messages[error.message] || error.message, 3);
if (onError) {
onError(error);
}
return false;
}
if (onError) {
onError(new Error('empty_response'));
}
return false;
},
},
subscriptions: {
......
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