Skip to content

Instantly share code, notes, and snippets.

View actions.js
import constants from '../../constants';
export function loadedDashboardState(website, status, news, revenues) {
return trackable({
type: constants.DASHBOARD_STATE_LOADED,
payload: { website, status, news, revenues }
},
'Dashboard opened', // <- event name
{ name: website.name } // <- additional event data
);
View configureStore.js
import { createStore, applyMiddleware } from 'redux';
import { createAnalytics } from '../middleware';
const middlewares = [
thunk,
createLogger(),
createAnalytics({ host: 'ANALYTICS_HOST', token: 'ANALYTICS_TOKEN' })
];
const enchancer = applyMiddleware(...middlewares);
View createAnalytics.js
import { client } from '../analytics';
const handleAction = (store, next, action, options) => {
if (!action.meta || !action.meta.analytics) {
return next(action);
}
const { eventType, eventPayload } = action.meta.analytics;
client(options).track(eventType, eventPayload);
View actions.js
import { createConstants } from '../utils';
const constants = createConstants(
// account actions
'ACCOUNT_FORM_RESET',
'ACCOUNT_FORM_CHANGE',
'ACCOUNT_FORM_ERRORS',
'ACCOUNT_FORM_ERRORS_CLEAN',
'ACCOUNT_ACCESS_TOKEN_FETCHING',
'ACCOUNT_ACCESS_TOKEN_FETCHED',
View composeComponents.js
export function composeComponents(component, wrappers = []) {
return wrappers.reduce((c, wrapper) => wrapper(c), component);
}
View compose.js
const CheckedWelcome = composeComponents(
Welcome,
[
(c) => checkBoarded(c, { withValue: true, redirectTo: '/app/dashboard' }),
(c) => requiresAuth(c)
]
);
const CheckApp = composeComponents(
App,
View routes_5.js
const routes = (
<Route path="">
<Route path="/signup" component={SignUp} />
<Route path="/signin" component={SignIn} />
// applied here..
<Route path="/welcome-on-board" component={checkBoarded(Welcome, { withValue: true, redirectTo: '/app/dashboard'}) } />
<Route path="/forgot-password" component={ForgotPassword} />
<Route path="/signout" component={SignOut} />
View set_context.js
export default function websiteContext(Component) {
class WebsiteContextComponent extends React.Component {
static propTypes = {
dispatch: PropTypes.func.isRequired,
state: PropTypes.object.isRequire,
params: PropTypes.shape({
websiteId: PropTypes.string.isRequired
})
};
View routes_4.js
const routes = (
<Route path="">
<Route path="/signup" component={SignUp} />
<Route path="/signin" component={SignIn} />
// applied here..
<Route path="/welcome-on-board" component={checkBoarded(Welcome, { withValue: true, redirectTo: '/app/dashboard'}) } />
<Route path="/forgot-password" component={ForgotPassword} />
<Route path="/signout" component={SignOut} />
View checkBoarded.js
export default function checkBoarded(Component, { withValue, redirectTo }) {
class CompletedComponent extends React.Component {
static propTypes = {
state: PropTypes.object.isRequired,
dispatch: PropTypes.func.isRequired
};
componentDidMount() {
this._checkAndRedirect();
}