feat(Flash): Normalize flash types with object

help prevent typo errors
This commit is contained in:
Berkeley Martinez
2018-01-29 11:34:44 -08:00
parent ae3ccdd672
commit 1ee9d9259c
4 changed files with 17 additions and 15 deletions

View File

@@ -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

View File

@@ -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
View File

@@ -0,0 +1,10 @@
import _ from 'lodash';
export const alertTypes = _.keyBy([
'success',
'info',
'warning',
'danger'
], _.identity);
export const normalizeAlertType = alertType => alertTypes[alertType] || 'info';