feat(Flash): Get flashes from ssr
This commit is contained in:
@ -5,10 +5,10 @@ import { render } from 'redux-epic';
|
|||||||
import createHistory from 'history/createBrowserHistory';
|
import createHistory from 'history/createBrowserHistory';
|
||||||
import useLangRoutes from './utils/use-lang-routes';
|
import useLangRoutes from './utils/use-lang-routes';
|
||||||
import sendPageAnalytics from './utils/send-page-analytics';
|
import sendPageAnalytics from './utils/send-page-analytics';
|
||||||
import flashToToast from './utils/flash-to-toast';
|
|
||||||
|
|
||||||
import { App, createApp, provideStore } from '../common/app';
|
import { App, createApp, provideStore } from '../common/app';
|
||||||
import { getLangFromPath } from '../common/app/utils/lang';
|
import { getLangFromPath } from '../common/app/utils/lang';
|
||||||
|
import flashReducer, { messagesFoundOnBoot } from '../common/app/Flash/redux';
|
||||||
|
|
||||||
// client specific epics
|
// client specific epics
|
||||||
import epics from './epics';
|
import epics from './epics';
|
||||||
@ -29,7 +29,7 @@ const {
|
|||||||
document,
|
document,
|
||||||
ga,
|
ga,
|
||||||
__fcc__: {
|
__fcc__: {
|
||||||
flash = [],
|
flash = {},
|
||||||
data: ssrState = {},
|
data: ssrState = {},
|
||||||
csrf: {
|
csrf: {
|
||||||
token: csrfToken
|
token: csrfToken
|
||||||
@ -51,7 +51,10 @@ const defaultState = isColdStored() ?
|
|||||||
const primaryLang = getLangFromPath(location.pathname);
|
const primaryLang = getLangFromPath(location.pathname);
|
||||||
|
|
||||||
defaultState.app.csrfToken = csrfToken;
|
defaultState.app.csrfToken = csrfToken;
|
||||||
defaultState.toasts = flashToToast(flash);
|
defaultState.flash = flashReducer(
|
||||||
|
defaultState.flash,
|
||||||
|
messagesFoundOnBoot(flash)
|
||||||
|
);
|
||||||
|
|
||||||
const serviceOptions = { xhrPath: '/services', context: { _csrf: csrfToken } };
|
const serviceOptions = { xhrPath: '/services', context: { _csrf: csrfToken } };
|
||||||
|
|
||||||
@ -78,7 +81,7 @@ createApp({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.doOnNext(() => log('rendering'))
|
.do(() => log('rendering'))
|
||||||
.flatMap(({ store }) => render(provideStore(App, store), DOMContainer))
|
.flatMap(({ store }) => render(provideStore(App, store), DOMContainer))
|
||||||
.subscribe(
|
.subscribe(
|
||||||
() => debug('react rendered'),
|
() => debug('react rendered'),
|
||||||
|
@ -8,18 +8,13 @@ import {
|
|||||||
|
|
||||||
import ns from '../ns.json';
|
import ns from '../ns.json';
|
||||||
|
|
||||||
export const types = createTypes([
|
|
||||||
'clickOnClose'
|
|
||||||
], ns);
|
|
||||||
|
|
||||||
export const clickOnClose = createAction(types.clickOnClose, _.noop);
|
|
||||||
|
|
||||||
export const alertTypes = _.keyBy(_.identity)([
|
export const alertTypes = _.keyBy(_.identity)([
|
||||||
'success',
|
'success',
|
||||||
'info',
|
'info',
|
||||||
'warning',
|
'warning',
|
||||||
'danger'
|
'danger'
|
||||||
]);
|
]);
|
||||||
|
export const normalizeAlertType = _.get(alertTypes, 'info');
|
||||||
|
|
||||||
export const getFlashAction = _.flow(
|
export const getFlashAction = _.flow(
|
||||||
_.property('meta'),
|
_.property('meta'),
|
||||||
@ -31,8 +26,24 @@ export const isFlashAction = _.flow(
|
|||||||
Boolean
|
Boolean
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const types = createTypes([
|
||||||
|
'clickOnClose',
|
||||||
|
'messagesFoundOnBoot'
|
||||||
|
], ns);
|
||||||
|
|
||||||
|
export const clickOnClose = createAction(types.clickOnClose, _.noop);
|
||||||
|
export const messagesFoundOnBoot = createAction(types.messagesFoundOnBoot);
|
||||||
|
|
||||||
|
export const expressToStack = _.flow(
|
||||||
|
_.toPairs,
|
||||||
|
_.flatMap(([ type, messages ]) => messages.map(({ msg }) => ({
|
||||||
|
message: msg,
|
||||||
|
alertType: normalizeAlertType(type)
|
||||||
|
})))
|
||||||
|
);
|
||||||
|
|
||||||
const defaultState = {
|
const defaultState = {
|
||||||
stack: [{ alertType: 'danger', message: 'foo bar' }]
|
stack: [{ alertType: 'danger', message: 'foo nar' }]
|
||||||
};
|
};
|
||||||
|
|
||||||
const getNS = _.property(ns);
|
const getNS = _.property(ns);
|
||||||
@ -51,6 +62,10 @@ export default composeReducers(
|
|||||||
[types.clickOnClose]: (state) => ({
|
[types.clickOnClose]: (state) => ({
|
||||||
...state,
|
...state,
|
||||||
stack: _.tail(state.stack)
|
stack: _.tail(state.stack)
|
||||||
|
}),
|
||||||
|
[types.messagesFoundOnBoot]: (state, { payload }) => ({
|
||||||
|
...state,
|
||||||
|
stack: [...state.stack, ...expressToStack(payload)]
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
defaultState,
|
defaultState,
|
||||||
@ -63,7 +78,7 @@ export default composeReducers(
|
|||||||
stack: [
|
stack: [
|
||||||
...state.stack,
|
...state.stack,
|
||||||
{
|
{
|
||||||
alertType: alertTypes[alertType] || 'info',
|
alertType: normalizeAlertType(alertType),
|
||||||
message: _.escape(message)
|
message: _.escape(message)
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
Reference in New Issue
Block a user