bookingReducer.js 1.08 KB
import { BOOKING_DETAILS_SUCCESS, BOOKING_DETAILS_FAIL, FETCH_MY_BOOKINGS_SUCCESS, FETCH_MY_BOOKINGS_FAIL, CLEAR_ERRORS } from "../constants/bookingConstants";

// Get all booked dates.
export const fetchMyBookingsReducer = (state = { bookings: [] }, action) => {
  switch (action.type) {
    case FETCH_MY_BOOKINGS_SUCCESS:
      return {
        loading: false,
        bookings: action.payload
      };

    case FETCH_MY_BOOKINGS_FAIL:
      return {
        loading: false,
        error: action.payload.error.message
      };

    case CLEAR_ERRORS:
      return {
        ...state,
        error: null
      };

    default:
      return state;
  }
};

// Room details reducer.
export const bookingDetailsReducer = (state = { booking: {} }, action) => {
  switch (action.type) {
    case BOOKING_DETAILS_SUCCESS:
      return {
        booking: action.payload.data
      };

    case BOOKING_DETAILS_FAIL:
      return {
        error: action.payload.error.message
      };

    case CLEAR_ERRORS:
      return {
        ...state,
        error: null
      };

    default:
      return state;
  }
};