/
ShopView.js
74 lines (66 loc) · 2.9 KB
/
ShopView.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import React, {Component} from "react";
import {connect} from "react-redux";
import CategoryList from "./CategoryList";
import CategoryForm from "./CategoryForm";
import {
AppSlidingPanel,
KitPanelHeading,
KitPanelTitle,
KitPanelBody,
KitButton
} from "./theme";
import {toggleTypeForm, createNewSKUType, nameChanged, descChanged} from "../store/sku_type/SKUTypeActions";
class ShopView extends Component {
// Render the Shop panel
render() {
const {
shop,
toggleTypeForm,
skuTypeFormDisplayed,
skuFormDisplayed,
skuTypesFetched
} = this.props;
return <AppSlidingPanel>
<KitPanelHeading>
<KitPanelTitle>
{shop.name}
<div className="pull-right">
{!skuTypesFetched || skuTypeFormDisplayed || skuFormDisplayed
? null
: <KitButton onClick={toggleTypeForm}>Add Category</KitButton>}
</div>
</KitPanelTitle>
{shop.description}
</KitPanelHeading>
<KitPanelBody>
<CategoryList {...this.props}/>
{skuTypeFormDisplayed ? <CategoryForm {...this.props}/> : null}
</KitPanelBody>
</AppSlidingPanel>;
}
}
const mapStateToProps = (state) => ({
selectedAccount: state.accountState.selectedAccount,
selectedShopId: state.shopState.selectedShopId,
selectedSKUTypeId: state.skuTypeState.selectedSKUTypeId,
shops: state.shopState.shops,
shop: state.shopState.shops.find(shop => shop.shopId === state.shopState.selectedShopId),
skuTypes: state.skuTypeState.skuTypes,
skuType: state.shopState.shops.find(skuType => skuType.skuTypeId === state.shopState.selectedSKUTypeId),
skuTypesFetched: state.skuTypeState.skuTypesFetched,
creatingSKUType: state.skuTypeState.creatingSKUType,
skuTypeFormDisplayed: state.skuTypeState.skuTypeFormDisplayed,
skuFormDisplayed: state.skuState.skuFormDisplayed,
name: state.skuTypeState.newSKUType.name,
description: state.skuTypeState.newSKUType.description,
selectedShopBalance: state.shopState.selectedShopBalance,
shopBalanceFetched: state.shopState.shopBalanceFetched,
fetchingShopBalance: state.shopState.fetchingShopBalance
});
const mapDispatchToProps = (dispatch) => ({
createNewSKUType: (contract, owner, shopId, name, description) => dispatch(createNewSKUType(contract, owner, shopId, name, description)),
toggleTypeForm: () => dispatch(toggleTypeForm()),
nameChanged: name => {dispatch(nameChanged(name))},
descChanged: description => {dispatch(descChanged(description))},
});
export default connect(mapStateToProps, mapDispatchToProps)(ShopView);