teamdigitale/italia-app

View on GitHub
ts/store/middlewares/contentAnalytics.ts

Summary

Maintainability
A
0 mins
Test Coverage
import { getType } from "typesafe-actions";
import { mixpanel } from "../../mixpanel";
import { Action } from "../actions/types";
import { loadContextualHelpData, loadIdps } from "../actions/content";

export const trackContentAction =
  (mp: NonNullable<typeof mixpanel>) =>
  (action: Action): void => {
    switch (action.type) {
      case getType(loadContextualHelpData.request):
      case getType(loadContextualHelpData.success):
      case getType(loadIdps.request):
      case getType(loadIdps.success):
        return mp.track(action.type);
      case getType(loadContextualHelpData.failure):
      case getType(loadIdps.failure):
        return mp.track(action.type, {
          reason: action.payload
        });
    }
  };