Merge pull request #1604 from coralproject/email-attach-fix

Email Attach Fixes
This commit is contained in:
Wyatt Johnson
2018-05-11 13:05:45 -06:00
committed by GitHub
11 changed files with 103 additions and 31 deletions
+11 -5
View File
@@ -37,7 +37,8 @@ export default class Popup extends Component {
this.onBlur();
};
// Use `onunload` instead of `onbeforeunload` which is not supported in IOS Safari.
// Use `onunload` instead of `onbeforeunload` which is not supported in iOS
// Safari.
this.ref.onunload = () => {
this.onUnload();
@@ -46,10 +47,15 @@ export default class Popup extends Component {
}
this.resetCallbackInterval = setInterval(() => {
if (this.ref && this.ref.onload === null) {
clearInterval(this.resetCallbackInterval);
this.resetCallbackInterval = null;
this.setCallbacks();
try {
if (this.ref && this.ref.onload === null) {
clearInterval(this.resetCallbackInterval);
this.resetCallbackInterval = null;
this.setCallbacks();
}
} catch (err) {
// We could be getting a security exception here if the login page
// gets redirected to another domain to authenticate.
}
}, 50);
@@ -0,0 +1,9 @@
import * as actions from './constants';
export const startAttach = () => ({
type: actions.START_ATTACH,
});
export const finishAttach = () => ({
type: actions.FINISH_ATTACH,
});
@@ -45,6 +45,10 @@ class AddEmailAddressDialog extends React.Component {
),
};
componentDidMount() {
this.props.startAttach();
}
onChange = e => {
const { name, value } = e.target;
this.setState(
@@ -99,7 +103,13 @@ class AddEmailAddressDialog extends React.Component {
});
};
confirmChanges = async () => {
finish = () => {
this.props.finishAttach();
};
confirmChanges = async e => {
e.preventDefault();
if (!this.validate()) {
this.showErrors();
return;
@@ -113,7 +123,11 @@ class AddEmailAddressDialog extends React.Component {
email: emailAddress,
password: confirmPassword,
});
this.props.notify('success', 'Email Added!');
this.props.notify(
'success',
t('talk-plugin-local-auth.add_email.added.alert')
);
this.goToNextStep();
} catch (err) {
this.props.notify('error', getErrorMessages(err));
@@ -143,13 +157,13 @@ class AddEmailAddressDialog extends React.Component {
)}
{step === 1 &&
!settings.requireEmailConfirmation && (
<EmailAddressAdded done={() => {}} />
<EmailAddressAdded done={this.finish} />
)}
{step === 1 &&
settings.requireEmailConfirmation && (
<VerifyEmailAddress
emailAddress={formData.emailAddress}
done={() => {}}
done={this.finish}
/>
)}
</Dialog>
@@ -161,6 +175,8 @@ AddEmailAddressDialog.propTypes = {
attachLocalAuth: PropTypes.func.isRequired,
notify: PropTypes.func.isRequired,
root: PropTypes.object.isRequired,
startAttach: PropTypes.func.isRequired,
finishAttach: PropTypes.func.isRequired,
};
export default AddEmailAddressDialog;
@@ -41,7 +41,7 @@ const AddEmailContent = ({
</li>
</ul>
<form autoComplete="off">
<form autoComplete="off" onSubmit={confirmChanges}>
<InputField
id="emailAddress"
label={t('talk-plugin-local-auth.add_email.enter_email_address')}
@@ -82,12 +82,9 @@ const AddEmailContent = ({
showSuccess={false}
/>
<div className={styles.actions}>
<a
className={cn(styles.button, styles.proceed)}
onClick={confirmChanges}
>
<button className={cn(styles.button, styles.proceed)}>
{t('talk-plugin-local-auth.add_email.add_email_address')}
</a>
</button>
</div>
</form>
</div>
@@ -0,0 +1,4 @@
const prefix = 'TALK_LOCAL_AUTH';
export const START_ATTACH = `${prefix}_START_ATTACH`;
export const FINISH_ATTACH = `${prefix}_FINISH_ATTACH`;
@@ -3,10 +3,16 @@ import { bindActionCreators } from 'redux';
import { connect, withFragments, excludeIf } from 'plugin-api/beta/client/hocs';
import AddEmailAddressDialog from '../components/AddEmailAddressDialog';
import { notify } from 'coral-framework/actions/notification';
import { withAttachLocalAuth } from '../hocs';
import { startAttach, finishAttach } from '../actions';
import get from 'lodash/get';
const mapDispatchToProps = dispatch => bindActionCreators({ notify }, dispatch);
const mapStateToProps = ({ talkPluginLocalAuth: state }) => ({
inProgress: state.inProgress,
});
const mapDispatchToProps = dispatch =>
bindActionCreators({ notify, startAttach, finishAttach }, dispatch);
const withData = withFragments({
root: gql`
@@ -14,6 +20,13 @@ const withData = withFragments({
me {
id
email
state {
status {
username {
status
}
}
}
}
settings {
requireEmailConfirmation
@@ -23,8 +36,13 @@ const withData = withFragments({
});
export default compose(
connect(null, mapDispatchToProps),
connect(mapStateToProps, mapDispatchToProps),
withAttachLocalAuth,
withData,
excludeIf(({ root: { me } }) => !me || me.email)
excludeIf(
({ root: { me }, inProgress }) =>
!me ||
get(me, 'state.status.username.status') === 'UNSET' ||
(me.email && !inProgress)
)
)(AddEmailAddressDialog);
@@ -1,10 +1,12 @@
import ChangePassword from './containers/ChangePassword';
import AddEmailAddressDialog from './containers/AddEmailAddressDialog';
import Profile from './containers/Profile';
import translations from './translations.yml';
import translations from '../translations.yml';
import graphql from './graphql';
import reducer from './reducer';
export default {
reducer,
translations,
slots: {
profileHeader: [Profile],
@@ -0,0 +1,20 @@
import * as actions from './constants';
const initialState = {
inProgress: false,
};
export default function reducer(state = initialState, action) {
switch (action.type) {
case actions.START_ATTACH:
return {
inProgress: true,
};
case actions.FINISH_ATTACH:
return {
inProgress: false,
};
default:
return state;
}
}
+1 -1
View File
@@ -4,7 +4,7 @@ const mutators = require('./server/mutators');
const path = require('path');
module.exports = {
translations: path.join(__dirname, 'server', 'translations.yml'),
translations: path.join(__dirname, 'translations.yml'),
typeDefs,
mutators,
resolvers,
@@ -1,9 +0,0 @@
en:
email:
email_change_original:
subject: Email change
body: Your email address has been changed from {0} to {1}. If you did not initiate this change, please contact {2}. # TODO: update translation
error:
NO_LOCAL_PROFILE: No existing email address is associated with this account.
LOCAL_PROFILE: An email address is already associated with this account.
INCORRECT_PASSWORD: Provided password was incorrect.
@@ -1,4 +1,12 @@
en:
email:
email_change_original:
subject: Email change
body: Your email address has been changed from {0} to {1}. If you did not request this change, please contact {2}.
error:
NO_LOCAL_PROFILE: No existing email address is associated with this account.
LOCAL_PROFILE: An email address is already associated with this account.
INCORRECT_PASSWORD: Provided password was incorrect.
talk-plugin-local-auth:
change_password:
change_password: "Change Password"
@@ -43,7 +51,7 @@ en:
email_does_not_match: "Email Address does not match"
insert_password: "Insert Password:"
required_field: "This field is required"
done: "done"
done: "Done"
content:
title: "Add an Email Address"
description: "For your added security, we require users to add an email address to their accounts. Your email address will be used to:"
@@ -59,6 +67,7 @@ en:
subtitle: "Need to change your email address?"
description_2: "You can change your account settings by visiting"
path: "My Profile > Settings"
alert: "Email Added!"
es:
talk-plugin-local-auth:
change_password: