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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import stringify from 'json-stable-stringify'
import {createAction} from 'redux-actions'
export const receiveCartData = createAction('Receive Cart Data', (payload) => payload)
export const receiveCartShippingMethods = createAction('Receive Cart Shipping Methods Data', (payload) => payload)
export const receiveCartPaymentMethods = createAction('Receive Cart Payment Methods Data', (payload) => payload)
export const receiveCategoryData = createAction('Receive Category Data', (payload) => payload)
export const receiveCustomerData = createAction('Receive Customer Data', (payload) => payload)
export const receiveProductData = createAction('Receive Product Data', (payload) => payload)
export const receiveProductSearchData = createAction('Receive Product Search Data', (payload) => payload)
export const receiveStoreData = createAction('Receive Store Data', (payload) => payload)
export const createCart = (oldCart, opts) => (dispatch, _, {api}) => {
return api.createCart(oldCart, opts)
.then((cart) => dispatch(receiveCartData(cart)))
}
export const getCart = (cartId, opts) => (dispatch, _, {api}) => {
return api.getCart(cartId, opts)
.then((cart) => dispatch(receiveCartData(cart)))
}
export const addCartItem = (cart, cartItem, opts) => (dispatch, _, {api}) => {
return api.addCartItem(cart, cartItem, opts)
.then((cart) => dispatch(receiveCartData(cart)))
}
export const updateCartItem = (cart, cartItem, opts) => (dispatch, _, {api}) => {
return api.updateCartItem(cart, cartItem, opts)
.then((cart) => dispatch(receiveCartData(cart)))
}
export const removeCartItem = (cart, cartItemId, opts) => (dispatch, _, {api}) => {
return api.removeCartItem(cart, cartItemId, opts)
.then((cart) => dispatch(receiveCartData(cart)))
}
export const setPayment = (cart, payment, opts) => (dispatch, _, {api}) => {
return api.setPayment(cart, payment, opts)
.then((cart) => dispatch(receiveCartData(cart)))
}
export const setCustomerInformation = (cart, customerInformation, opts) => (dispatch, _, {api}) => {
return api.setCustomerInformation(cart, customerInformation, opts)
.then((cart) => dispatch(receiveCartData(cart)))
}
export const setBillingAddress = (cart, billingAddress, opts) => (dispatch, _, {api}) => {
return api.setBillingAddress(cart, billingAddress, opts)
.then((cart) => dispatch(receiveCartData(cart)))
}
export const setShippingAddress = (cart, shippingAddress, opts) => (dispatch, _, {api}) => {
return api.setShippingAddress(cart, shippingAddress, opts)
.then((cart) => dispatch(receiveCartData(cart)))
}
export const setShippingMethod = (cart, shippingMethod, opts) => (dispatch, _, {api}) => {
return api.setShippingMethod(cart, shippingMethod, opts)
.then((cart) => dispatch(receiveCartData(cart)))
}
export const getShippingMethods = (cart, opts) => (dispatch, _, {api}) => {
return api.getShippingMethods(cart, opts)
.then((shippingMethods) => dispatch(receiveCartShippingMethods(shippingMethods)))
}
export const getPaymentMethods = (cart, opts) => (dispatch, _, {api}) => {
return api.getPaymentMethods(cart, opts)
.then((paymentMethods) => dispatch(receiveCartPaymentMethods(paymentMethods)))
}
export const deleteCart = (cartId, opts) => (dispatch, _, {api}) => {
return api.deleteCart(cartId, opts)
.then(() => dispatch(receiveCartData(null)))
}
export const login = (username, password) => (dispatch, _, {api}) => {
return api.login(username, password)
.then((customer) => dispatch(receiveCustomerData(customer)))
}
export const logout = () => (dispatch, _, {api}) => {
return api.logout()
.then(() => dispatch(receiveCustomerData(null)))
}
export const getCustomer = (id, opts) => (dispatch, _, {api}) => {
return api.getCustomer(id, opts)
.then((customer) => dispatch(receiveCustomerData(customer)))
}
export const getCategory = (id, opts) => (dispatch, _, {api}) => {
return api.getCategory(id, opts)
.then((category) => dispatch(receiveCategoryData({
[id]: category
})))
}
export const getCategories = (ids, opts) => (dispatch, _, {api}) => {
return api.getCategories(ids, opts)
.then((categories) => {
// This accumulator will make sure if we have requested a category that
// isn't in the result set, that a null value is added to the redux store.
// This will allow the UI to know that a value wasn't found on the server.
const accumulator = (acc, curr) => {
const category = categories.data.find((category) => category.id === curr)
return {
...acc,
[curr]: category ? category : null
}
}
// TODO: We'll have to account for child categories at some point
const payload = ids.reduce(accumulator, {})
dispatch(receiveCategoryData(payload))
})
}
export const getProduct = (id, opts) => (dispatch, _, {api}) => {
return api.getProduct(id, opts)
.then((product) => dispatch(receiveProductData({
[id]: product
})))
}
export const getProducts = (ids, opts) => (dispatch, _, {api}) => {
return api.getProducts(ids, opts)
.then((products) => {
// This accumulator will make sure if we have requested a product that
// isn't in the result set, that a null value is added to the redux store.
// This will allow the UI to know that a value wasn't found on the server.
const accumulator = (acc, curr) => {
const product = products.data.find((product) => product.id === curr)
return {
...acc,
[curr]: product ? product : null
}
}
const payload = ids.reduce(accumulator, {})
return dispatch(receiveProductData(payload))
})
}
export const searchProducts = (searchParams) => (dispatch, _, {api}) => {
const resultKey = stringify(searchParams)
return api.searchProducts(searchParams)
.then((productSearch) => dispatch(receiveProductSearchData({
[resultKey]: productSearch
})))
}
export const getStore = (id, opts) => (dispatch, _, {api}) => {
return api.getStore(id, opts)
.then((store) => dispatch(receiveStoreData({
[id]: store
})))
}
|