diff --git a/app/soapbox/actions/security.js b/app/soapbox/actions/security.js index 5005c2017..0df6b9fe6 100644 --- a/app/soapbox/actions/security.js +++ b/app/soapbox/actions/security.js @@ -11,13 +11,14 @@ export const CHANGE_PASSWORD_FAIL = 'CHANGE_PASSWORD_FAIL'; export function changeEmail(email, password) { return (dispatch, getState) => { dispatch({ type: CHANGE_EMAIL_REQUEST, email }); - api(getState).post('/api/pleroma/change_email', { + return api(getState).post('/api/pleroma/change_email', { email, password, }).then(response => { dispatch({ type: CHANGE_EMAIL_SUCCESS, email, response }); }).catch(error => { - dispatch({ type: CHANGE_EMAIL_FAIL, email, error }); + dispatch({ type: CHANGE_EMAIL_FAIL, email, error, skipAlert: true }); + throw error; }); }; } @@ -25,7 +26,7 @@ export function changeEmail(email, password) { export function changePassword(oldPassword, newPassword, confirmation) { return (dispatch, getState) => { dispatch({ type: CHANGE_PASSWORD_REQUEST }); - api(getState).post('/api/pleroma/change_password', { + return api(getState).post('/api/pleroma/change_password', { password: oldPassword, new_password: newPassword, new_password_confirmation: confirmation, diff --git a/app/soapbox/features/security/index.js b/app/soapbox/features/security/index.js index df3224b58..8c36a3e45 100644 --- a/app/soapbox/features/security/index.js +++ b/app/soapbox/features/security/index.js @@ -11,10 +11,13 @@ import { TextInput, } from 'soapbox/features/forms'; import { changeEmail } from 'soapbox/actions/security'; +import { showAlert } from 'soapbox/actions/alerts'; const messages = defineMessages({ heading: { id: 'column.security', defaultMessage: 'Security' }, submit: { id: 'security.submit', defaultMessage: 'Save changes' }, + updateEmailSuccess: { id: 'security.update_email.success', defaultMessage: 'Email successfully updated.' }, + updateEmailFail: { id: 'security.update_email.fail', defaultMessage: 'Update email failed.' }, }); export default @connect() @@ -27,7 +30,10 @@ class Security extends ImmutablePureComponent { intl: PropTypes.object.isRequired, }; - state = {} + state = { + email: '', + password: '', + } handleInputChange = e => { this.setState({ [e.target.name]: e.target.value }); @@ -35,7 +41,12 @@ class Security extends ImmutablePureComponent { handleSubmit = e => { const { email, password } = this.state; - this.props.dispatch(changeEmail(email, password)); + const { dispatch, intl } = this.props; + dispatch(changeEmail(email, password)).then(() => { + dispatch(showAlert('', intl.formatMessage(messages.updateEmailSuccess))); + }).catch(error => { + dispatch(showAlert('', intl.formatMessage(messages.updateEmailFail))); + }); } render() {