web2019/static/js/shop/Crate.jsx
Egor Savkin 9edf410e4d Start refactor to state manager zustand
Signed-off-by: Egor Savkin <es@m-labs.hk>
2024-01-09 10:14:53 +08:00

44 lines
1.2 KiB
JavaScript

import React from 'react';
import {Cart} from "./Cart.jsx";
import {CrateMode} from "./CrateMode.jsx";
import {CrateWarnings} from "./CrateWarnings.jsx";
import {useShopStore} from "./shop_store";
import {TriggerCrateWarnings} from "./warnings";
/**
* Component that displays the main crate with reminder rules.
* It includes <Cart> and rules
*/
export function Crate({crate_index}) {
const {
onDeleteCrate,
crate
} = useShopStore(state => ({
onDeleteCrate: state.delCrate,
crate: state.crates[crate_index]
}))
return (
<div className="crate">
<CrateMode crate_index={crate_index}/>
<div>
Delete crate
<button style={{width: "32px"}} onClick={() => onDeleteCrate(crate.id)}>
<img src="/images/shop/icon-remove.svg" alt="remove"/>
</button>
</div>
<div className="crate-products">
<Cart crate_index={crate_index}/>
{1 || (rules && rules.length > 0) && (
<CrateWarnings crate_index={crate_index} />
)}
</div>
</div>
);
}