/**
 * mSupply Mobile
 * Sustainable Solutions (NZ) Ltd. 2019
 */

import { ROUTES } from '../navigation/constants';
import { UIDatabase } from '../database';
import { PRESCRIPTION_ACTIONS } from '../actions/PrescriptionActions';

const initialState = () => ({
  currentTab: 0,
  transaction: null,
  items: UIDatabase.objects('Item'),
  itemSearchTerm: '',
});

export const PrescriptionReducer = (state = initialState(), action) => {
  const { type } = action;

  switch (type) {
    case 'Navigation/NAVIGATE': {
      const { routeName, params } = action;

      if (routeName !== ROUTES.PRESCRIPTION) return state;
      const { transaction } = params;

      return { ...state, transaction };
    }
    case PRESCRIPTION_ACTIONS.REFRESH: {
      return { ...state };
    }

    case PRESCRIPTION_ACTIONS.FILTER: {
      const { payload } = action;
      const { itemSearchTerm } = payload;

      return { ...state, itemSearchTerm };
    }

    default:
      return state;
  }
};

@@ -351,16 +351,43 @@
 rm: '',%0A
+  commentModalOpen: false,%0A
 %7D);%0A%0Aexp
@@ -725,16 +725,17 @@
 ;%0A    %7D%0A
+%0A
     case
@@ -964,24 +964,246 @@
 m %7D;%0A    %7D%0A%0A
+    case PRESCRIPTION_ACTIONS.OPEN_COMMENT_MODAL: %7B%0A      return %7B ...state, commentModalOpen: true %7D;%0A    %7D%0A%0A    case PRESCRIPTION_ACTIONS.CLOSE_COMMENT_MODAL: %7B%0A      return %7B ...state, commentModalOpen: false %7D;%0A    %7D%0A%0A
     default:
@@ -1202,16 +1202,18 @@
 default:
+ %7B
 %0A      r
@@ -1225,15 +1225,21 @@
  state;%0A
+    %7D%0A
   %7D%0A%7D;%0A

Add PrescriptionReducer update