<commit_before>import axios from 'axios'
import { FETCH_USER_CART, CREATE_USER_CART } from '../constants';

export const fetchCart = cart => ({
  type: FETCH_USER_CART,
  cart
});



export const createNewCart = () => {
  return dispatch => {
    axios.post('/api/cart/')
    .then(res => {
      console.log('created cart!', res.data);
      dispatch(fetchCart(res.data));
    });
  };
};

export const getCartByUserId = cartId => {
  return dispatch => {
    axios.get(`/api/cart/${cartId}`)
    .then(res => {
      console.log('got cart!', res.data);
      dispatch(fetchCart(res.data));
    });
  };
};




export const addAvailabilityToCartAC = (homeId, startDate, endDate) => {

      homeId=homeId.toString()

  return dispatch => {
    axios.get('/api/auth/whoami')
    .then(user=>{

        if(user.data!==""){
            axios.post(`/api/cart/${user.data.id}`, {homeId:homeId, startDate:startDate, endDate:endDate})
        }else{
            console.log("CANNOT ADD CART ITEMS WHEN NOT SIGNED IN")
        }
      })

  }
}<commit_msg>add to cart redirects to cart when adding home avail to cart and also updates state with dispatch(getcartbyuserid)<commit_after>import axios from 'axios'
import {browserHistory} from 'react-router';
import { FETCH_USER_CART, CREATE_USER_CART } from '../constants';

export const fetchCart = cart => ({
  type: FETCH_USER_CART,
  cart
});



export const createNewCart = () => {
  return dispatch => {
    axios.post('/api/cart/')
    .then(res => {
      console.log('created cart!', res.data);
      dispatch(fetchCart(res.data));
    });
  };
};

export const getCartByUserId = cartId => {
  return dispatch => {
    axios.get(`/api/cart/${cartId}`)
    .then(res => {
      console.log('got cart!', res.data);
      dispatch(fetchCart(res.data));
    });
  };
};




export const addAvailabilityToCartAC = (homeId, startDate, endDate) => {

      homeId=homeId.toString()

  return dispatch => {
    axios.get('/api/auth/whoami')
    .then(user=>{

        if(user.data!==""){
            axios.post(`/api/cart/${user.data.id}`, {homeId:homeId, startDate:startDate, endDate:endDate})
            .then(()=>{
              dispatch(getCartByUserId(user.data.id))
              browserHistory.push(`/cart/${user.data.id}`)
            })
        }else{
            console.log("CANNOT ADD CART ITEMS WHEN NOT SIGNED IN")
        }
      })

  }
}
{'fraction_non_alphanumeric': 0.16736227045075125, 'fraction_numerical': 0.0, 'mean_word_length': 2.7394695787831513, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 24, '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': '4795169', 'n_tokens_mistral': 827, 'n_tokens_neox': 805, 'n_words': 152}