feat(Flash): Normalize flash types with object
help prevent typo errors
This commit is contained in:
@ -4,7 +4,7 @@ import { CloseButton } from 'react-bootstrap';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
import ns from './ns.json';
|
||||
import { alertTypes } from './redux/utils.js';
|
||||
import { alertTypes } from '../../utils/flash.js';
|
||||
import {
|
||||
latestMessageSelector,
|
||||
clickOnClose
|
||||
|
@ -1,13 +1,5 @@
|
||||
import _ from 'lodash/fp';
|
||||
|
||||
export const alertTypes = _.keyBy(_.identity)([
|
||||
'success',
|
||||
'info',
|
||||
'warning',
|
||||
'danger'
|
||||
]);
|
||||
|
||||
export const normalizeAlertType = alertType => alertTypes[alertType] || 'info';
|
||||
import { alertTypes, normalizeAlertType } from '../../../utils/flash.js';
|
||||
|
||||
// interface ExpressFlash {
|
||||
// [alertType]: [String...]
|
||||
@ -16,7 +8,6 @@ export const normalizeAlertType = alertType => alertTypes[alertType] || 'info';
|
||||
// type: AlertType,
|
||||
// message: String
|
||||
// }
|
||||
|
||||
export const expressToStack = _.flow(
|
||||
_.toPairs,
|
||||
_.flatMap(([ type, messages ]) => messages.map(msg => ({
|
||||
|
10
common/utils/flash.js
Normal file
10
common/utils/flash.js
Normal file
@ -0,0 +1,10 @@
|
||||
import _ from 'lodash';
|
||||
|
||||
export const alertTypes = _.keyBy([
|
||||
'success',
|
||||
'info',
|
||||
'warning',
|
||||
'danger'
|
||||
], _.identity);
|
||||
|
||||
export const normalizeAlertType = alertType => alertTypes[alertType] || 'info';
|
@ -6,6 +6,7 @@ import {
|
||||
} from '../utils/middleware';
|
||||
import supportedLanguages from '../../common/utils/supported-languages.js';
|
||||
import { themes } from '../../common/utils/themes.js';
|
||||
import { alertTypes } from '../../common/utils/flash.js';
|
||||
|
||||
export default function settingsController(app) {
|
||||
const api = app.loopback.Router();
|
||||
@ -76,7 +77,7 @@ export default function settingsController(app) {
|
||||
'/update-my-current-challenge',
|
||||
ifNoUser401,
|
||||
updateMyCurrentChallengeValidators,
|
||||
createValidatorErrorHandler('errors'),
|
||||
createValidatorErrorHandler(alertTypes.danger),
|
||||
updateMyCurrentChallenge
|
||||
);
|
||||
|
||||
@ -88,11 +89,11 @@ export default function settingsController(app) {
|
||||
function updateMyTheme(req, res, next) {
|
||||
const { body: { theme } } = req;
|
||||
if (req.user.theme === theme) {
|
||||
return res.sendFlash('info', 'Theme already set');
|
||||
return res.sendFlash(alertTypes.info, 'Theme already set');
|
||||
}
|
||||
return req.user.updateTheme(theme)
|
||||
.then(
|
||||
() => res.sendFlash('info', 'Your theme has been updated'),
|
||||
() => res.sendFlash(alertTypes.info, 'Your theme has been updated'),
|
||||
next
|
||||
);
|
||||
}
|
||||
@ -100,7 +101,7 @@ export default function settingsController(app) {
|
||||
'/update-my-theme',
|
||||
ifNoUser401,
|
||||
updateMyThemeValidators,
|
||||
createValidatorErrorHandler('errors'),
|
||||
createValidatorErrorHandler(alertTypes.danger),
|
||||
updateMyTheme
|
||||
);
|
||||
|
||||
|
Reference in New Issue
Block a user