-
-
Save maiordom/1c6dcc1ae871c7ef6d41ed18aaa53e22 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { handleActions } from 'redux-actions'; | |
import * as find from 'lodash/find'; | |
import * as each from 'lodash/each'; | |
import * as a from 'src/actions/Shop'; | |
import { IWebShopServices, IWebShopService } from 'src/types/IWebShopServices'; | |
import { IProductCard, IShopService, IShopServices } from 'src/store/ShopService'; | |
import { IShopCategory } from 'src/store/ShopCategories'; | |
export default handleActions({ | |
[a.setProducts]: (state, { payload: { products, serviceName } }) => { | |
const items: Array<IProductCard> = products.items; | |
state.setIn(`shopService.${serviceName}`, { items }); | |
const itemsPerPage: number = state.getIn('shop.controls.perPageCount.selected.value'); | |
const pageCount: number = Math.round(products.total / itemsPerPage); | |
state.setIn(`shopService.${serviceName}.pagination`, { pageCount }); | |
return state; | |
}, | |
[a.setShopServices]: (state, { payload }) => { | |
const services: IWebShopServices = payload.services; | |
const shopService: IShopServices = state.getIn('shopService'); | |
services.forEach((service: IWebShopService) => { | |
each(shopService, (game: IShopService) => { | |
if (game.name === service.name) { | |
game.serviceId = service.id; | |
} | |
}); | |
}); | |
return state; | |
}, | |
[a.setShopCategory]: (state, { payload }) => { | |
const category: IShopCategory = payload.category; | |
const serviceName: string = payload.serviceName; | |
state.setIn(`shopCategories.${serviceName}`, category); | |
return state; | |
} | |
}, {}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment