2023-11-30 17:26:17 +08:00
|
|
|
import React, {PureComponent} from 'react';
|
|
|
|
import PropTypes from "prop-types";
|
|
|
|
import {SummaryPopup} from "./options/SummaryPopup.jsx";
|
|
|
|
import {formatMoney} from "./utils";
|
2023-12-06 16:27:43 +08:00
|
|
|
import {WarningIndicator} from "./CardWarnings.jsx";
|
2023-12-08 16:39:28 +08:00
|
|
|
import {total_order_price} from "./count_resources";
|
|
|
|
import {data as shared_data} from "./utils";
|
2023-11-30 17:26:17 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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,
|
2023-12-08 16:39:28 +08:00
|
|
|
crates: PropTypes.object,
|
2023-11-30 17:26:17 +08:00
|
|
|
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,
|
2023-12-08 16:39:28 +08:00
|
|
|
crates
|
2023-11-30 17:26:17 +08:00
|
|
|
} = this.props;
|
|
|
|
|
2023-12-08 16:39:28 +08:00
|
|
|
const total_price = total_order_price(crates);
|
2023-11-30 17:26:17 +08:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="summary-price">
|
|
|
|
|
|
|
|
<table>
|
|
|
|
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<td colSpan="2" className="summary-remove-all">
|
|
|
|
<span className="item-card-name">Remove all cards</span>
|
|
|
|
|
|
|
|
<button onClick={this.handleOnDeleteAllItems}>
|
|
|
|
<img src="/images/shop/icon-remove.svg" />
|
|
|
|
</button>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
|
2023-12-08 16:39:28 +08:00
|
|
|
{Object.entries(crates).map(([crate_id, crate], _i) => {
|
|
|
|
let crate_type = shared_data.crateModes[crate.crate_type];
|
2023-11-30 17:26:17 +08:00
|
|
|
return (
|
2023-12-08 16:39:28 +08:00
|
|
|
<tbody key={"summary_crate_body"+crate_id}>
|
|
|
|
<tr key={"summary_crate_"+crate_id}>
|
|
|
|
<td className="item-card-name">{crate_type.name}</td>
|
2023-11-30 17:26:17 +08:00
|
|
|
<td className="price">
|
2023-12-08 16:39:28 +08:00
|
|
|
<div>
|
|
|
|
{`${currency} ${formatMoney(crate_type.price)}`}
|
2023-11-30 17:26:17 +08:00
|
|
|
|
2023-12-08 16:39:28 +08:00
|
|
|
<button style={{'opacity': '0', 'cursor': 'initial'}}>
|
2023-11-30 17:26:17 +08:00
|
|
|
<img src="/images/shop/icon-remove.svg" />
|
|
|
|
</button>
|
|
|
|
</div>
|
2023-12-08 16:39:28 +08:00
|
|
|
|
|
|
|
<span style={{
|
|
|
|
'display': 'inline-block',
|
|
|
|
'width': '30px',
|
|
|
|
}}> </span>
|
2023-11-30 17:26:17 +08:00
|
|
|
</td>
|
2023-12-08 16:39:28 +08:00
|
|
|
</tr>
|
|
|
|
{crate.items.map((item, index) => {
|
|
|
|
let options = item && item.options;
|
|
|
|
let options_data = item && item.options_data;
|
|
|
|
const warnings = item && item.show_warnings;
|
|
|
|
|
|
|
|
return (<tr key={"summary_crate_" + crate_id+item.id}
|
|
|
|
className={`hoverable ${item.selected ? 'selected' : ''}`}
|
|
|
|
onClick={this.handleOnClickSelectItem.bind(this, index)}
|
|
|
|
onMouseEnter={this.handleOnMouseEnterItem.bind(this, item.id)}
|
|
|
|
onMouseLeave={this.handleOnMouseLeaveItem}>
|
|
|
|
<td className="item-card-name">
|
|
|
|
<div>{`${item.name_number} ${item.name} ${item.name_codename}`}</div>
|
|
|
|
</td>
|
|
|
|
|
|
|
|
<td className="price">
|
|
|
|
<div className="d-inline-flex align-content-center">
|
|
|
|
{`${currency} ${formatMoney(item.price)}`}
|
|
|
|
|
|
|
|
<button onClick={this.handleOnDeleteItem.bind(this, index)}>
|
|
|
|
<img src="/images/shop/icon-remove.svg" />
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<div style={{'width': '45px', 'height': '20px'}} className="d-inline-flex align-content-center align-self-center justify-content-evenly">
|
|
|
|
{(warnings && warnings.length > 0 ? (
|
|
|
|
<WarningIndicator warnings={warnings}/>
|
|
|
|
) : (
|
|
|
|
<span style={{
|
|
|
|
'display': 'inline-block',
|
|
|
|
'width': '20px',
|
|
|
|
}}> </span>
|
|
|
|
))}
|
|
|
|
{((options && options_data) ? (
|
|
|
|
<SummaryPopup id={item.id + "options"} options={options} data={options_data} />
|
|
|
|
) : (
|
|
|
|
<span style={{
|
|
|
|
'display': 'inline-block',
|
|
|
|
'width': '20px',
|
|
|
|
}}> </span>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</td>
|
|
|
|
</tr>);
|
|
|
|
})}
|
|
|
|
</tbody>
|
|
|
|
)})}
|
2023-11-30 17:26:17 +08:00
|
|
|
|
|
|
|
<tfoot>
|
|
|
|
<tr>
|
|
|
|
<td className="item-card-name">Price estimate</td>
|
|
|
|
<td className="price">
|
|
|
|
<div>
|
2023-12-08 16:39:28 +08:00
|
|
|
${currency} ${formatMoney(total_price)}
|
2023-11-30 17:26:17 +08:00
|
|
|
<button style={{'opacity': '0', 'cursor': 'initial'}}>
|
|
|
|
<img src="/images/shop/icon-remove.svg" alt="icon remove"/>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<span style={{
|
|
|
|
'display': 'inline-block',
|
|
|
|
'width': '30px',
|
|
|
|
}}> </span>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</tfoot>
|
|
|
|
|
|
|
|
</table>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|