import React, {PureComponent} from 'react'; import PropTypes from "prop-types"; import {SummaryPopup} from "./options/SummaryPopup.jsx"; import {formatMoney} from "./utils"; import {WarningIndicator} from "./CardWarnings.jsx"; import {total_order_price} from "./count_resources"; import {data as shared_data} from "./utils"; /** * Components that displays the list of card that are used in the crate. * It is a summary of purchase */ export class OrderSummary extends PureComponent { static get propTypes() { return { currency: PropTypes.string, crates: PropTypes.object, onDeleteItem: PropTypes.func, onDeleteAllItems: PropTypes.func, onMouseEnterItem: PropTypes.func, onMouseLeaveItem: PropTypes.func, onClickSelectItem: PropTypes.func, }; } constructor(props) { super(props); this.handleOnDeleteItem = this.handleOnDeleteItem.bind(this); this.handleOnDeleteAllItems = this.handleOnDeleteAllItems.bind(this); this.handleOnMouseEnterItem = this.handleOnMouseEnterItem.bind(this); this.handleOnMouseLeaveItem = this.handleOnMouseLeaveItem.bind(this); this.handleOnClickSelectItem = this.handleOnClickSelectItem.bind(this); } handleOnDeleteItem(index, e) { if (this.props.onDeleteItem) { this.props.onDeleteItem(index); } e.preventDefault(); } handleOnDeleteAllItems(e) { if (this.props.onDeleteAllItems) { this.props.onDeleteAllItems(); } e.preventDefault(); } handleOnMouseEnterItem(id, e) { if (this.props.onMouseEnterItem) { this.props.onMouseEnterItem(id); } e.preventDefault(); } handleOnMouseLeaveItem(e) { if (this.props.onMouseLeaveItem) { this.props.onMouseLeaveItem(); } e.preventDefault(); } handleOnClickSelectItem(index, e) { if (e.target.tagName !== 'IMG') { if (this.props.onClickSelectItem) { this.props.onClickSelectItem(index); } } return e.preventDefault(); } render() { const { currency, crates } = this.props; const total_price = total_order_price(crates); return (
{Object.entries(crates).map(([crate_id, crate], _i) => { let crate_type = shared_data.crateModes[crate.crate_type]; return ( {crate.items.map((item, index) => { let options = item && item.options; let options_data = item && item.options_data; const warnings = item && item.show_warnings; return (); })} )})}
Remove all cards
{crate_type.name}
{`${currency} ${formatMoney(crate_type.price)}`}
 
{`${item.name_number} ${item.name} ${item.name_codename}`}
{`${currency} ${formatMoney(item.price)}`}
{(warnings && warnings.length > 0 ? ( ) : (   ))} {((options && options_data) ? ( ) : (   ))}
Price estimate
${currency} ${formatMoney(total_price)}
 
); } }