All files / @gce/contact/store reducers.js

80% Statements 12/15
100% Branches 5/5
50% Functions 3/6
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94                      1x                                                                   1x   1x                 1x   1x                   1x     1x                                 4x 2x   2x    
import {
  SET_CONTACTS,
  SET_TELEMEDECINES,
  SET_CONTACTS_LOADING,
  SET_TELEMEDECINES_LOADING,
  SET_HEALTH_INSUR_CONTACT,
} from './constants';
 
/**
   * /v1/contacts + graphQL for telemedecines
   */
const initialState = {
  healthInsuranceContact: null,
  contacts: [
    {
      title: 'contacts.abroad_hotline.title',
      description: 'contacts.abroad_hotline.description',
      phone: 'contacts.abroad_hotline.phone',
      code: 'PHONE',
    },
    {
      title: 'contacts.hotline_gmapp_title',
      description: 'contacts.hotline_description',
      phone: 'contacts.phone_hotline',
      code: 'PHONE',
    },
    {
      title: 'contacts.medi24_title',
      description: 'contacts.service_urgence_description',
      phone: 'contacts.phone_medi24',
      code: 'EMERGENCY',
    },
  ],
  telemedecines: {},
  contactsLoading: true,
  telemedecinesLoading: true,
};
 
/**
 * Set fetched contacts
 *
 * @param {Object} state
 * @param {Object} action
 * @param {Array} action.payload.contacts
 */
const setContacts = (state, action) => ({ ...state, contacts: action.payload.contacts });
 
const setContactsLoading = (state, action) => ({ ...state, contactsLoading: action.payload.contactsLoading });
 
/**
 * Set fetched telemedecines
 *
 * @param {Object} state
 * @param {Object} action
 * @param {Object} action.payload.telemedecines
 */
const setTelemedecines = (state, action) => ({ ...state, telemedecines: action.payload.telemedecines });
 
const setTelemedecinesLoading = (state, action) => ({ ...state, telemedecinesLoading: action.payload.telemedecinesLoading });
 
 
/**
 * Set fetched health insur contact
 *
 * @param {Object} state
 * @param {Object} action
 * @param {Array} action.payload.contact
 */
const setHealthInsurContact = (state, action) => ({ ...state, healthInsuranceContact: action.payload.contact });
 
// convenience object to map actions to functions
const FUNCTION_BY_ACTION = {
  [SET_CONTACTS]: setContacts,
  [SET_TELEMEDECINES]: setTelemedecines,
  [SET_CONTACTS_LOADING]: setContactsLoading,
  [SET_TELEMEDECINES_LOADING]: setTelemedecinesLoading,
  [SET_HEALTH_INSUR_CONTACT]: setHealthInsurContact,
};
 
/**
 * Reducer function
 *
 * @param {Object} state
 * @param {Object=} action
 *
 * @returns {Object}
 */
export default (state = initialState, action) => {
  if (action && action.type in FUNCTION_BY_ACTION) {
    return FUNCTION_BY_ACTION[action.type](state, action);
  }
  return state;
};