fix(settings/updateEmail): Show message from server
This commit is contained in:
@ -2,11 +2,13 @@ import { isLocationAction } from 'redux-first-router';
|
||||
import {
|
||||
addNS,
|
||||
createAction,
|
||||
createAsyncTypes,
|
||||
createTypes
|
||||
} from 'berkeleys-redux-utils';
|
||||
|
||||
import userUpdateEpic from './update-user-epic.js';
|
||||
import ns from '../ns.json';
|
||||
import { utils } from '../../../Flash/redux';
|
||||
|
||||
export const epics = [
|
||||
userUpdateEpic
|
||||
@ -14,7 +16,7 @@ export const epics = [
|
||||
|
||||
export const types = createTypes([
|
||||
'toggleUserFlag',
|
||||
'updateMyEmail',
|
||||
createAsyncTypes('updateMyEmail'),
|
||||
'updateMyLang',
|
||||
'onRouteSettings',
|
||||
'onRouteUpdateEmail'
|
||||
@ -24,7 +26,18 @@ export const types = createTypes([
|
||||
export const onRouteSettings = createAction(types.onRouteSettings);
|
||||
export const onRouteUpdateEmail = createAction(types.onRouteUpdateEmail);
|
||||
export const toggleUserFlag = createAction(types.toggleUserFlag);
|
||||
export const updateMyEmail = createAction(types.updateMyEmail);
|
||||
export const updateMyEmail = createAction(types.updateMyEmail.start);
|
||||
export const updateMyEmailComplete = createAction(
|
||||
types.updateMyEmail.complete,
|
||||
null,
|
||||
utils.createFlashMetaAction
|
||||
);
|
||||
|
||||
export const updateMyEmailError = createAction(
|
||||
types.updateMyEmail.error,
|
||||
null,
|
||||
utils.createFlashMetaAction
|
||||
);
|
||||
|
||||
export const updateMyLang = createAction(
|
||||
types.updateMyLang,
|
||||
|
@ -24,15 +24,29 @@ export default function settingsController(app) {
|
||||
);
|
||||
};
|
||||
|
||||
const updateMyEmailValidators = [
|
||||
check('email')
|
||||
.isEmail()
|
||||
.withMessage('Email format is invalid.')
|
||||
];
|
||||
|
||||
function updateMyEmail(req, res, next) {
|
||||
const { user, body: { email } } = req;
|
||||
return user.requestUpdateEmail(email)
|
||||
.subscribe(
|
||||
(message) => res.json({ message }),
|
||||
message => res.sendFlash(alertTypes.info, message),
|
||||
next
|
||||
);
|
||||
}
|
||||
|
||||
api.post(
|
||||
'/update-my-email',
|
||||
ifNoUser401,
|
||||
updateMyEmailValidators,
|
||||
createValidatorErrorHandler(alertTypes.danger),
|
||||
updateMyEmail
|
||||
);
|
||||
|
||||
function updateMyLang(req, res, next) {
|
||||
const { user, body: { lang } = {} } = req;
|
||||
const langName = supportedLanguages[lang];
|
||||
@ -130,11 +144,6 @@ export default function settingsController(app) {
|
||||
ifNoUser401,
|
||||
toggleUserFlag('sendQuincyEmail')
|
||||
);
|
||||
api.post(
|
||||
'/update-my-email',
|
||||
ifNoUser401,
|
||||
updateMyEmail
|
||||
);
|
||||
api.post(
|
||||
'/update-my-lang',
|
||||
ifNoUser401,
|
||||
|
Reference in New Issue
Block a user