import React, { Component } from "react";
import { connect } from "react-redux";
import PropTypes from "prop-types";
import ProductService from "../../config/productService";
import { getProductDetail } from "../../actions/productDetail/productDetail";
import { Button, Row, Col, Container } from "reactstrap";
import ModalComponent from "../../components/common/Modal/Modal";
import TableComponent from "../../components/Table/TableComponent";
import ProductDetail from "../../components/ProductDetail/ProductDetail";
class ProductDetailContainer extends Component {
state = {
showModal: false
// tableData: [{name: 'Americano', maxPrice: 11, minPrice: 12, averagePrice: 111, soldOut: 10.000}]
};
toggleModal = () => {
this.setState({
showModal: !this.state.showModal
});
};
componentDidMount() {
const {
match: {
params: { id }
},
getProductDetail
} = this.props;
getProductDetail(id);
}
createTableData = arr => {
return arr.map((element, index) => {
return {
name: element.banner.name,
maxPrice: ProductService.maxPrice(element.pricingDataByWeek),
minPrice: ProductService.minPrice(element.pricingDataByWeek),
averagePrice: ProductService.averagePrice(element.pricingDataByWeek),
soldOut: "10.000"
};
});
};
render() {
const { productDetail, productDetailData, loading } = this.props;
const { showModal, data } = this.state;
return (
<Container>
<ProductDetail data={productDetail} />
<Row>
<Col sm={{ offset: 9 }}>
<Button color="primary" onClick={this.toggleModal}>
Hello
</Button>
</Col>
<Col>
<Button color="primary">Create Report</Button>
</Col>
<ModalComponent showModal={showModal} toggle={this.toggleModal} />
</Row>
{loading
? console.log(`DATA NOT LOADED ${JSON.stringify(productDetailData)}`)
: console.log(`DATA LOADED ${JSON.stringify(productDetailData)}`)};
</Container>
);
}
}
const mapStateToProps = state => {
return {
...state.productDetail
};
};
const mapDispatchToProps = {
getProductDetail
};
ProductDetailContainer.propTypes = {
productDetail: PropTypes.object.isRequired,
getProductDetail: PropTypes.func.isRequired,
productDetailData: PropTypes.array.isRequired
};
export default connect(
mapStateToProps,
mapDispatchToProps
)(ProductDetailContainer);