2023-12-12 16:09:29 +08:00
|
|
|
import React from 'react';
|
2023-12-12 18:21:09 +08:00
|
|
|
import {SummaryPopup} from "./options/SummaryPopup";
|
2023-11-30 17:26:17 +08:00
|
|
|
import {formatMoney} from "./utils";
|
2023-12-12 18:21:09 +08:00
|
|
|
import {WarningIndicator} from "./CardWarnings";
|
2023-12-12 16:09:29 +08:00
|
|
|
import {useShopStore} from "./shop_store";
|
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
|
|
|
|
*/
|
2023-12-12 16:09:29 +08:00
|
|
|
export function OrderSummary() {
|
|
|
|
|
|
|
|
const {
|
|
|
|
currency,
|
|
|
|
crates,
|
|
|
|
total_price,
|
|
|
|
crateParams,
|
|
|
|
deleteCard,
|
|
|
|
setHighlight,
|
|
|
|
resetHighlight,
|
|
|
|
highlighted,
|
|
|
|
clearCrate,
|
|
|
|
clearAll
|
|
|
|
} = useShopStore(state =>({
|
|
|
|
currency: state.currency,
|
|
|
|
crates: state.crates,
|
|
|
|
total_price: state.totalOrderPrice(),
|
|
|
|
crateParams: state.crateParams,
|
|
|
|
deleteCard: state.deleteCard,
|
|
|
|
setHighlight: state.highlightCard,
|
|
|
|
resetHighlight: state.highlightReset,
|
|
|
|
highlighted: state.highlighted,
|
|
|
|
clearAll: state.clearAll,
|
|
|
|
clearCrate: state.clearCrate
|
|
|
|
}));
|
|
|
|
|
|
|
|
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={clearAll}>
|
|
|
|
<img src="/images/shop/icon-remove.svg"/>
|
|
|
|
</button>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
|
|
|
|
{crates.map((crate, _i) => {
|
|
|
|
let crate_type = crateParams(crate.crate_mode);
|
|
|
|
return (
|
|
|
|
<tbody key={"summary_crate_body" + crate.id}>
|
|
|
|
<tr key={"summary_crate_" + crate.id}>
|
|
|
|
<td className="item-card-name">{crate_type.name}</td>
|
|
|
|
<td className="price">
|
|
|
|
<div>
|
|
|
|
{`${currency} ${formatMoney(crate_type.price)}`}
|
|
|
|
|
|
|
|
<button style={{'opacity': '0', 'cursor': 'initial'}}>
|
|
|
|
<img src="/images/shop/icon-remove.svg"/>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<span style={{
|
|
|
|
'display': 'inline-block',
|
|
|
|
'width': '30px',
|
|
|
|
}}> </span>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
{crate.items.map((item, index) => {
|
|
|
|
const options = item && item.options;
|
|
|
|
const options_data = item && item.options_data;
|
|
|
|
const warnings = item && item.show_warnings;
|
|
|
|
const selected = crate.id === highlighted.crate && index === highlighted.card;
|
|
|
|
|
|
|
|
return (<tr key={"summary_crate_" + crate.id + item.id}
|
|
|
|
className={`hoverable ${selected ? 'selected' : ''}`}
|
|
|
|
onClick={() => setHighlight(crate.id, index)}
|
|
|
|
onMouseEnter={() => setHighlight(crate.id, index)}
|
|
|
|
onMouseLeave={() => resetHighlight()}>
|
|
|
|
<td className="item-card-name">
|
|
|
|
<div>{`${item.name_number} ${item.name} ${item.name_codename}`}</div>
|
|
|
|
</td>
|
|
|
|
|
2023-11-30 17:26:17 +08:00
|
|
|
<td className="price">
|
2023-12-12 16:09:29 +08:00
|
|
|
<div className="d-inline-flex align-content-center">
|
|
|
|
{`${currency} ${formatMoney(item.price)}`}
|
2023-11-30 17:26:17 +08:00
|
|
|
|
2023-12-12 16:09:29 +08:00
|
|
|
<button onClick={() => deleteCard(crate.id, index)}>
|
|
|
|
<img src="/images/shop/icon-remove.svg"/>
|
2023-11-30 17:26:17 +08:00
|
|
|
</button>
|
2023-12-08 16:39:28 +08:00
|
|
|
|
2023-12-12 16:09:29 +08:00
|
|
|
<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>
|
2023-11-30 17:26:17 +08:00
|
|
|
</td>
|
2023-12-12 16:09:29 +08:00
|
|
|
</tr>);
|
|
|
|
})}
|
|
|
|
</tbody>
|
|
|
|
)
|
|
|
|
})}
|
|
|
|
|
|
|
|
<tfoot>
|
|
|
|
<tr>
|
|
|
|
<td className="item-card-name">Price estimate</td>
|
|
|
|
<td className="price">
|
|
|
|
<div>
|
|
|
|
{currency} {formatMoney(total_price)}
|
|
|
|
<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>
|
|
|
|
);
|
2023-11-30 17:26:17 +08:00
|
|
|
}
|