Commit 19c070d9 authored by Denis Sedura's avatar Denis Sedura

[RNA-779] Wrap ItemHeader

parent 41ad8058
......@@ -127,6 +127,7 @@ export function enhanceAddToCartView(ComposedComponent) {
// const { order: { id: orderId }, navigation } = this.props
// const navigatorApp = navigation.getNavigator('app')
// navigatorApp.push('Cart', { orderId })
console.log('Show Cart')
}
handleRemoveButtonOnPress = () => {
......@@ -164,7 +165,6 @@ export function enhanceAddToCartView(ComposedComponent) {
(order = {}, paginations, entities) => {
const { ids = [] } = paginations.orderProducts[order.id] || {}
const orderProducts = denormalize(ids, Schemas.ORDER_PRODUCT_ARRAY, entities)
console.log(orderProducts)
return { order, orderProducts }
}
)
......
......@@ -2,6 +2,8 @@ import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import { get, isEqual } from 'lodash'
import { Router } from 'tipsi-router'
import {
loadInventoryItem,
loadWine,
......@@ -25,6 +27,15 @@ function enhanceItemDetails(Wine, Drink, AddToCartView) {
class Wrapper extends Component {
static propTypes = {
itemType: PropTypes.oneOf(['wine', 'drink']).isRequired,
storeId: PropTypes.number,
inventory: PropTypes.object,
createUserFavorite: PropTypes.func.isRequired,
removeUserFavorite: PropTypes.func.isRequired,
}
static defaultProps = {
storeId: undefined,
inventory: undefined,
}
static details = {
......@@ -32,15 +43,79 @@ function enhanceItemDetails(Wine, Drink, AddToCartView) {
drink: Drink,
}
shouldComponentUpdate(nextProps) {
return !isEqual(this.props, nextProps)
}
handlePressLabelPreview = () => {
// this.props.navigation.navigator.push('LabelPreview', {
// source: this.props.logo,
// })
console.log('LabelPreview')
}
handlePressItemReviews = () => {
// this.props.navigation.navigator.push('ItemReviews', {
// itemType: this.props.itemType,
// itemId: this.props.itemId,
// })
console.log('ItemReviews')
}
handlePressManageReview = () => {
const { user, inventoryId, itemType, itemId, item } = this.props
if (!user) {
Router.showModal(null, Router.routes.login, {
config: { navigationBar: { visible: false } },
})
return
}
console.log('ManageReview')
// this.props.navigation.navigator.push('ManageReview', {
// itemType,
// itemId,
// inventoryId,
// reviewId: get(item, ['user_review', 0, 'id']),
// })
}
handlePressManageFavorite = () => {
const { user, itemType, item } = this.props
if (!user) {
Router.showModal(null, Router.routes.login, {
config: { navigationBar: { visible: false } },
})
return
}
const { userFavorite } = itemFormatter(itemType, item)
const data = { [`${itemType}_id`]: item.id }
if (userFavorite) {
this.props.removeUserFavorite(user.id, userFavorite.id, data)
} else {
this.props.createUserFavorite(user.id, data)
}
}
render() {
const DetailsComponent = Wrapper.details[this.props.itemType]
return (
<DetailsComponent {...this.props}>
<AddToCartViewHOC
storeId={this.props.storeId}
inventoryId={this.props.inventory.id}
inventoryType={this.props.itemType}
/>
<DetailsComponent
{...this.props}
handlePressLabelPreview={this.handlePressLabelPreview}
handlePressItemReviews={this.handlePressItemReviews}
handlePressManageReview={this.handlePressManageReview}
handlePressManageFavorite={this.handlePressManageFavorite}>
{Boolean(this.props.inventory) &&
<AddToCartViewHOC
storeId={this.props.storeId}
inventoryId={this.props.inventory.id}
inventoryType={this.props.itemType}
/>
}
</DetailsComponent>
)
}
......
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