bensaufley/code-words-web

View on GitHub
src/ducks/modal.js

Summary

Maintainability
A
0 mins
Test Coverage
export const MODAL_SHOW = 'MODAL_SHOW',
      MODAL_HIDE = 'MODAL_HIDE';

const initialState = {
  content: '',
  shown: false
};

export default function modalReducer(state = initialState, action) {
  switch (action.type) {
    case MODAL_SHOW:
      return {
        ...state,
        shown: true,
        content: action.payload.message,
        type: action.payload.type
      };
    case MODAL_HIDE:
      return initialState;
    default:
      return state;
  }
}

export function showModal(message, type = 'notice') {
  return {
    type: MODAL_SHOW,
    payload: {
      message,
      type
    }
  };
}

export function closeModal() {
  return {
    type: MODAL_HIDE,
    payload: {}
  };
}