fix: Update email action should hit API

This commit is contained in:
Mrugesh Mohapatra
2017-12-05 11:55:41 +05:30
parent 35f0b4f0d7
commit 885d5916c0
6 changed files with 15 additions and 9 deletions

View File

@ -22,6 +22,7 @@ const propTypes = {
replace: PropTypes.bool, replace: PropTypes.bool,
routesMap: PropTypes.object, routesMap: PropTypes.object,
shouldDispatch: PropTypes.bool, shouldDispatch: PropTypes.bool,
style: PropTypes.object,
target: PropTypes.string, target: PropTypes.string,
to: PropTypes.oneOfType([ PropTypes.object, PropTypes.string ]).isRequired to: PropTypes.oneOfType([ PropTypes.object, PropTypes.string ]).isRequired
}; };
@ -36,6 +37,7 @@ export const Link = (
replace, replace,
routesMap, routesMap,
shouldDispatch = true, shouldDispatch = true,
style,
target, target,
to to
} }
@ -70,6 +72,7 @@ export const Link = (
return ( return (
<a <a
onClick={ handler } onClick={ handler }
style={ style }
{ ...localProps } { ...localProps }
> >
{children} {children}

View File

@ -24,7 +24,7 @@ export const updateUserFlag = createAction(
); );
// updateUserEmail(username: String, email: String) => Action // updateUserEmail(username: String, email: String) => Action
export const updateUserEmail = createAction( export const updateUserEmail = createAction(
types.updateUserFlag, types.updateUserEmail,
(username, email) => ({ username, email }) (username, email) => ({ username, email })
); );
// updateUserLang(username: String, lang: String) => Action // updateUserLang(username: String, lang: String) => Action

View File

@ -184,7 +184,7 @@ export class Settings extends React.Component {
className='btn-link-social' className='btn-link-social'
onClick={ toggleNightMode } onClick={ toggleNightMode }
> >
NightMode Toggle Night Mode
</Button> </Button>
</Col> </Col>
</Row> </Row>

View File

@ -6,7 +6,6 @@ import { makeToast } from '../../../Toasts/redux';
import { import {
fetchChallenges, fetchChallenges,
doActionOnError, doActionOnError,
userSelector userSelector
} from '../../../redux'; } from '../../../redux';
import { import {
@ -41,7 +40,7 @@ export function updateUserEmailEpic(actions, { getState }) {
const ajaxUpdate = postJSON$('/update-my-email', body) const ajaxUpdate = postJSON$('/update-my-email', body)
.map(({ message }) => makeToast({ message })) .map(({ message }) => makeToast({ message }))
.catch(doActionOnError(() => oldEmail ? .catch(doActionOnError(() => oldEmail ?
updateUserFlag(username, oldEmail) : updateUserEmail(username, oldEmail) :
null null
)); ));
return Observable.merge(optimisticUpdate, ajaxUpdate); return Observable.merge(optimisticUpdate, ajaxUpdate);

View File

@ -12,7 +12,7 @@ import { reduxForm } from 'redux-form';
import { isEmail } from 'validator'; import { isEmail } from 'validator';
import { Link } from '../../../../Router'; import { Link } from '../../../../Router';
import { getValidationState } from '../../../../utils/form'; import { getValidationState, DOMOnlyProps } from '../../../../utils/form';
import { import {
onRouteSettings, onRouteSettings,
updateMyEmail updateMyEmail
@ -93,10 +93,10 @@ export class UpdateEmail extends React.Component {
validationState={ getValidationState(email) } validationState={ getValidationState(email) }
> >
<FormControl <FormControl
autofocus={ true } autoFocus={ true }
placeholder='Enter your new email' placeholder='Enter your new email'
type='email' type='email'
{ ...email } { ...DOMOnlyProps(email) }
/> />
{ {
!email.error ? !email.error ?
@ -112,7 +112,7 @@ export class UpdateEmail extends React.Component {
<FormControl <FormControl
placeholder='re-type your email address' placeholder='re-type your email address'
type='email' type='email'
{ ...duplicate } { ...DOMOnlyProps(duplicate) }
/> />
{ {
!duplicate.error ? !duplicate.error ?
@ -131,7 +131,10 @@ export class UpdateEmail extends React.Component {
{ buttonCopy } { buttonCopy }
</Button> </Button>
<div className='button-spacer' /> <div className='button-spacer' />
<Link to={ onRouteSettings() }> <Link
style={{ textDecoration: 'none' }}
to={ onRouteSettings() }
>
<Button <Button
block={ true } block={ true }
bsSize='lg' bsSize='lg'

View File

@ -574,6 +574,7 @@ module.exports = function(User) {
) { ) {
const ownEmail = newEmail === this.email; const ownEmail = newEmail === this.email;
if (!isEmail('' + newEmail)) { if (!isEmail('' + newEmail)) {
debug('invalid email:', newEmail );
return Observable.throw(createEmailError()); return Observable.throw(createEmailError());
} }
// email is already associated and verified with this account // email is already associated and verified with this account