<commit_before>import axios from 'axios';

const initialState = {
    pastOrders: [],
    currentOrder: {}
  }


/* -----------------    ACTION TYPES     ------------------ */
const CREATE_ORDER = 'CREATE_ORDER'
const SET_CURRENT_ORDER = 'SET_CURRENT_ORDER'
const ADD_PRODUCT_TO_ORDER = 'ADD_PRODUCT_TO_ORDER'
const UPDATE_PRODUCT_IN_ORDER = 'UPDATE_PRODUCT_IN_ORDER'
const REMOVE_PRODUCT_FROM_ORDER = 'REMOVE_PRODUCT_FROM_ORDER'
const COMPLETE_ORDER = 'COMPLETE_ORDER'
const SET_PAST_ORDER = 'SET_PAST_ORDER'


/* ------------   ACTION CREATORS     ------------------ */

export const createOrder = (order) => ({
  type: CREATE_ORDER,
  currentOrder: order
})

export const setCurrentOrder = (order) => ({
  type: SET_CURRENT_ORDER,
  currentOrder: order
})

export const updateProductInOrder = (productId, price, quantity) => ({
  type: UPDATE_PRODUCT_IN_ORDER,
  productId: productId,
  price: price,
  quantity: quantity
})

export const addProductToOrder = (productId) => ({
  type: ADD_PRODUCT_TO_ORDER,
  productId: productId
})

export const removeProductFromOrder = (productId) => ({
  type: REMOVE_PRODUCT_FROM_ORDER,
  productId: productId
})

export const completeOrder = () => ({
  type: COMPLETE_ORDER,
})

export const setPastOrder = (orders) => ({
  type: SET_PAST_ORDER,
  pastOrders: orders
})
/* ------------       REDUCERS     ------------------ */
export default function(state = initialState, action) {

  const newState = Object.assign({}, state);

  switch (action.type) {
    case SET_CAMPUSES:
      newState.currentCampuses = action.campuses;
      break;

    case SET_SELECTED_CAMPUS:
      newState.selectedCampus = action.selectedCampus;
      break;

    case CREATE_CAMPUS:
      newState.currentCampuses = newState.currentCampuses.concat([action.campus]);
      break;

    case UPDATE_CAMPUS:
      newState.currentCampuses = newState.currentCampuses.map((campus) => (
        (campus.id === action.campus.id) ? action.campus : campus
      ))
      break;

    case DELETE_CAMPUS:
      newState.currentCampuses = newState.currentCampuses.filter((currentCampus) => (
        (currentCampus.id !== action.campusId && action.studentId !== 1)
      ))
      break;

    case ADD_STUDENT_TO_CAMPUS:
      newState.selectedCampus.students = newState.selectedCampus.students.concat([action.student])
      break;

    case REMOVE_STUDENT_FROM_CAMPUS:
      newState.selectedCampus.students =
        newState.selectedCampus.students.filter((student) => (student.id !== action.student.id))
      break;

    default:
      return state;

  }

  return newState;
}


/* ------------       DISPATCHERS     ------------------ */

export const fetchUsers = () => dispatch => {
  axios.get('/api/users')
       .then(res => dispatch(init(res.data)));
};

export const removeUser = id => dispatch => {
  dispatch(remove(id));
  axios.delete(`/api/users/`)
       .catch(err => console.error(`Removing user:  unsuccesful`, err));<commit_msg>feat: add actions on order reducer<commit_after>import axios from 'axios';

const initialState = {
    pastOrders: [],
    currentOrder: {}
  }


/* -----------------    ACTION TYPES     ------------------ */
const CREATE_ORDER = 'CREATE_ORDER'
const SET_CURRENT_ORDER = 'SET_CURRENT_ORDER'
const ADD_PRODUCT_TO_ORDER = 'ADD_PRODUCT_TO_ORDER'
const UPDATE_PRODUCT_IN_ORDER = 'UPDATE_PRODUCT_IN_ORDER'
const REMOVE_PRODUCT_FROM_ORDER = 'REMOVE_PRODUCT_FROM_ORDER'
const COMPLETE_ORDER = 'COMPLETE_ORDER'
const SET_PAST_ORDERS = 'SET_PAST_ORDERS'


/* ------------   ACTION CREATORS     ------------------ */

export const createOrder = (order) => ({
  type: CREATE_ORDER,
  currentOrder: order
})

export const setCurrentOrder = (order) => ({
  type: SET_CURRENT_ORDER,
  currentOrder: order
})

export const updateProductInOrder = (productId, price, quantity) => ({
  type: UPDATE_PRODUCT_IN_ORDER,
  productId: productId,
  price: price,
  quantity: quantity
})

export const addProductToOrder = (productId) => ({
  type: ADD_PRODUCT_TO_ORDER,
  productId: productId
})

export const removeProductFromOrder = (productId) => ({
  type: REMOVE_PRODUCT_FROM_ORDER,
  productId: productId
})

export const completeOrder = () => ({
  type: COMPLETE_ORDER,
})

export const setPastOrders = (orders) => ({
  type: SET_PAST_ORDERS,
  pastOrders: orders
})
/* ------------       REDUCERS     ------------------ */
export default function(state = initialState, action) {

  const newState = Object.assign({}, state)

  switch (action.type) {
    // case CREATE_ORDER:
    //   newState.currentOrder = action.currentOrder
    //   break

    case SET_CURRENT_ORDER:
      newState.currentOrder = action.currentOrder
      break

    case SET_PAST_ORDERS:
      newState.pastOrders = action.pastOrders
      break
    // case UPDATE_PRODUCT_IN_ORDER:
    //   newState.currentOrder = newState.currentCampuses.concat([action.campus])
    //   break
    //
    //
    // case DELETE_CAMPUS:
    //   newState.currentCampuses = newState.currentCampuses.filter((currentCampus) => (
    //     (currentCampus.id !== action.campusId && action.studentId !== 1)
    //   ))
    //   break;
    //
    // case ADD_STUDENT_TO_CAMPUS:
    //   newState.selectedCampus.students = newState.selectedCampus.students.concat([action.student])
    //   break;
    //
    // case REMOVE_STUDENT_FROM_CAMPUS:
    //   newState.selectedCampus.students =
    //     newState.selectedCampus.students.filter((student) => (student.id !== action.student.id))
    //   break;

    default:
      return state

  }

  return newState
}


/* ------------       DISPATCHERS     ------------------ */

export const fetchOrders = () => dispatch => {
  axios.get('/api/orders')
       .then(res => dispatch(setPastOrders(res.data)))
}

export const findOrCreateCurrentOrder = () => dispatch => {
  dispatch(remove(id))
  axios.delete(`/api/users/`)
       .catch(err => console.error(`Removing user:  unsuccesful`, err));
{'fraction_non_alphanumeric': 0.15723905723905723, 'fraction_numerical': 0.0003367003367003367, 'mean_word_length': 2.8855461085676914, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3911244', 'n_tokens_mistral': 1922, 'n_tokens_neox': 1874, 'n_words': 347}