Commit e30ea084 authored by Dmytro Zavgorodniy's avatar Dmytro Zavgorodniy

[RNA-761] Add latest reducers

parent 1e1403b4
......@@ -2,8 +2,9 @@ export sidebarMenu from './sidebarMenu'
export currentLocation from './currentLocation'
export searchQueries from './searchQueries'
export storeFilters from './storeFilters'
export storeCarts from './storeCarts'
export userCards from './userCards'
export userAddresses from './userAddresses'
export userContacts from './userContacts'
export ageConfirmation from './userAgeConfirmation'
export payments from './payments'
export storeCarts from './storeCarts'
......@@ -5,25 +5,25 @@ const initialState = {}
export default function payments(state = initialState, { payload, type }) {
switch (type) {
case PaymentsActionTypes.REQUEST_PAYMENT.LOADING:
return { ...state, [payload.orderId]: { requestPaymentLoading: true } }
return { ...state, [payload.storeId]: { requestPaymentLoading: true } }
case PaymentsActionTypes.REQUEST_PAYMENT.SUCCESS:
return { ...state, [payload.orderId]: { requestPaymentLoading: false } }
return { ...state, [payload.storeId]: { requestPaymentLoading: false } }
case PaymentsActionTypes.REQUEST_PAYMENT.ERROR:
return {
...state,
[payload.orderId]: {
[payload.storeId]: {
requestPaymentLoading: false,
requestPaymentError: payload.error,
},
}
case PaymentsActionTypes.FINALIZE_PAYMENT.LOADING:
return { ...state, [payload.orderId]: { finalizePaymentLoading: true } }
return { ...state, [payload.storeId]: { finalizePaymentLoading: true } }
case PaymentsActionTypes.FINALIZE_PAYMENT.SUCCESS:
return { ...state, [payload.orderId]: { finalizePaymentLoading: false } }
return { ...state, [payload.storeId]: { finalizePaymentLoading: false } }
case PaymentsActionTypes.FINALIZE_PAYMENT.ERROR:
return {
...state,
[payload.orderId]: {
[payload.storeId]: {
finalizePaymentLoading: false,
finalizePaymentError: payload.error,
},
......
import { ActionTypes } from '../actions/storeCarts'
function updateStoreState(state, storeId, data) {
return {
...state,
[storeId]: {
...state[storeId],
...data,
},
}
}
function updateInventoryState(state, storeId, inventoryId, data) {
return updateStoreState(state, storeId, {
[inventoryId]: {
...state[storeId][inventoryId],
...data,
},
})
}
export default function storeCarts(state = {}, action) {
const { type, payload = {} } = action
const { storeId, inventoryId } = payload
import { omit } from 'lodash'
import ActionTypes from 'tipsi_api/constants'
import { MODIFY_STORE_CART } from '../actions/storeCarts'
export default function storeCarts(state = {}, { type, payload }) {
switch (type) {
case ActionTypes.LOAD_STORE_CART.LOADING:
return updateStoreState(state, storeId, { isLoadingCart: true })
case ActionTypes.LOAD_STORE_CART.ERROR:
case ActionTypes.LOAD_STORE_CART.SUCCESS:
return updateStoreState(state, storeId, { isLoadingCart: false })
case ActionTypes.ADD_INVENTORY_TO_CART.LOADING:
return updateInventoryState(state, storeId, inventoryId, { isAddingToCart: true })
case ActionTypes.ADD_INVENTORY_TO_CART.ERROR:
case ActionTypes.ADD_INVENTORY_TO_CART.SUCCESS:
return updateInventoryState(state, storeId, inventoryId, { isAddingToCart: false })
case ActionTypes.INCREASE_INVENTORY_COUNT.LOADING:
return updateInventoryState(state, storeId, inventoryId, { isIncreasingCount: true })
case ActionTypes.INCREASE_INVENTORY_COUNT.ERROR:
case ActionTypes.INCREASE_INVENTORY_COUNT.SUCCESS:
return updateInventoryState(state, storeId, inventoryId, { isIncreasingCount: false })
case ActionTypes.DECREASE_INVENTORY_COUNT.LOADING:
return updateInventoryState(state, storeId, inventoryId, { isDecreasingCount: true })
case ActionTypes.DECREASE_INVENTORY_COUNT.ERROR:
case ActionTypes.DECREASE_INVENTORY_COUNT.SUCCESS:
return updateInventoryState(state, storeId, inventoryId, { isDecreasingCount: false })
case ActionTypes.REMOVE_INVENTORY_FROM_CART.LOADING:
return updateInventoryState(state, storeId, inventoryId, { isRemovingFromCart: true })
case ActionTypes.REMOVE_INVENTORY_FROM_CART.ERROR:
case ActionTypes.REMOVE_INVENTORY_FROM_CART.SUCCESS:
return updateInventoryState(state, storeId, inventoryId, { isRemovingFromCart: false })
case MODIFY_STORE_CART: {
const { storeId, product } = payload
return {
...state,
[storeId]: {
...state[storeId],
[product.inventoryId]: product.count,
},
}
}
case ActionTypes.UPDATE_STORE_CART_PRODUCT_COUNT.SUCCESS: {
return omit(state, payload.storeId)
}
default:
return state
}
......
import { omit, omitBy, isEqual, isEmpty } from 'lodash'
import { UPDATE_STORE_FILTERS, CLEAR_STORE_FILTERS } from '../actions/storeFilters'
import { BUDGET_RANGE, RATING_RANGE, WINE_COLORS_MAP } from '../constants/storeFilters'
import {
RATING_RANGE,
WINE_COLORS_MAP,
ORDER_BY_MAP,
} from '../constants/storeFilters'
export const initialFiltersState = {
budget: BUDGET_RANGE,
price: [],
rating: RATING_RANGE[0],
wineType: [],
color: [],
......@@ -13,6 +17,7 @@ export const initialFiltersState = {
subRegion: [],
tag: [],
unitSize: [],
orderBy: undefined,
}
export function getActiveFilters(filters = {}) {
......@@ -21,13 +26,17 @@ export function getActiveFilters(filters = {}) {
)
}
export function getActiveFiltersCount(filters) {
return Object.keys(omit(getActiveFilters(filters), 'orderBy')).length
}
export function getActiveFiltersLength(filters) {
return Object.keys(getActiveFilters(filters)).length
}
export function convertFiltersToQuery(filters) {
const {
budget: [priceFrom, priceTo] = [],
price: [priceFrom, priceTo] = [],
wineType,
rating,
color,
......@@ -37,13 +46,13 @@ export function convertFiltersToQuery(filters) {
subRegion,
tag,
unitSize,
orderBy,
} = getActiveFilters(filters)
const [minimalPrice, maximumPrice] = BUDGET_RANGE
const query = {}
const standardFilters = {
price_from: priceFrom > minimalPrice ? [{ value: priceFrom }] : [],
price_to: priceTo < maximumPrice ? [{ value: priceTo }] : [],
price_from: priceFrom ? [{ value: priceFrom }] : [],
price_to: priceTo ? [{ value: priceTo }] : [],
wine_type: wineType,
varietal_id: varietal,
country_id: country,
......@@ -61,6 +70,10 @@ export function convertFiltersToQuery(filters) {
}
}
if (ORDER_BY_MAP[orderBy]) {
query.order_by = ORDER_BY_MAP[orderBy]
}
return query
}
......
import { omit } from 'lodash'
import { ADD_CONTACT, REMOVE_CONTACT, SELECT_CONTACT } from '../actions/userContacts'
const initialState = { byId: {}, selected: undefined }
export default function userContacts(state = initialState, { payload, type }) {
switch (type) {
case ADD_CONTACT:
return {
byId: {
...state.byId,
[payload.id]: payload,
},
selected: state.selected,
}
case REMOVE_CONTACT:
return {
byId: omit(state.byId, payload.id),
selected: state.selected,
}
case SELECT_CONTACT:
return {
...state,
selected: payload.id,
}
default:
return state
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment