Professional Documents
Culture Documents
Seller Dashboard
Seller Dashboard
componentDidMount() {
const { companyItems, items } = this.state;
this.props.getItems();
this.props.fetchCompanyDetails();
// store.subscribe(this.companyItemsUpdate); //@todo: find why not updating
through connect on item update
}
shouldComponentUpdate(nextProps, nextState) {
if (nextProps.items.length === 0 && nextProps.companyItems.length > 0)
return false;
return true;
}
// componentDidUpdate(prevProps, prevState){
// if(!isEqual(this.state.companyItems, prevState.companyItems)){
// this.props.getItems();
// }
// }
renderTable = () => {
const { companyItems, companyNewItemProps, multipleSelect } = this.state;
const myItems = multipleSelect.map(
(si) => companyItems.filter((item) => item.itemId === si.id)[0] || {}
);
return (
<tbody>
{myItems.map((item, key) => {
const {
priceBulk = "-",
priceRetail = "-",
quantity = "-",
minimumBulkQuantity = "-",
dateAdded,
name = "",
unit = "",
image,
} = item;
return (
<tr>
<td>
<div className="img-container">
<img src={images[image && image.split(".")[0]]} alt="..." />:{"
"}
</div>
</td>
<td className="td-name">
<a href="#">{name}</a>
<br />
{/* <small>by Rukart </small> */}
</td>
<td className="td-name">
{quantity} {unit}
</td>
<td className="td-number">
<small>?</small>
{`${priceBulk}/${unit}`}
</td>
<td className="td-number">
<small>?</small>
{`${priceRetail}/${unit}`}
</td>
<td className="td-name">
{minimumBulkQuantity} {unit}
</td>
<td key={key} className="text-right">
<Button
icon
color="info"
size="sm"
onClick={() =>
alert(
`Last modified by <to be added> at ${new Date(
dateAdded
).toLocaleString()}`
)
}
>
<i className="now-ui-icons users_single-02" />
</Button>{" "}
<Button
icon
color="success"
size="sm"
onClick={() => this.toggleModal(item)}
>
<i className="now-ui-icons ui-2_settings-90" />
</Button>{" "}
<Button
icon
color="danger"
size="sm"
onClick={(e) => this.removeItem(key)}
>
<i className="now-ui-icons ui-1_simple-remove" />
</Button>
</td>
</tr>
);
})}
<tr>
<td colSpan="4" />
<td colSpan="4" className="text-right">
<Button onClick={this.toggleAddModal} color="info" round>
Add Item <i className="now-ui-icons arrows-1_minimal-right" />
</Button>
<Modal
isModalOpen={this.state.isAddModalOpen}
toggleModal={this.toggleAddModal}
modalAction={this.addItemApi}
actionLabel="Add"
title="Add Item to Dashboard"
>
<AddItemForm addItem={this.addItem} />
</Modal>
</td>
</tr>
</tbody>
);
};
render() {
const { selectedItem, isEditModalOpen, items, options } = this.state;
return (
<div>
<PanelHeader size="sm" />
<div className="content">
{this.state.alert}
<Modal
isModalOpen={isEditModalOpen}
toggleModal={this.toggleModal}
modalAction={this.updateItem} //an action to set updat eitem state obj
actionLabel="Update"
title={selectedItem && selectedItem.name}
>
<EditItemForm
editItem={this.editItem}
item={this.state.selectedItem}
/>
</Modal>
<Row>
<Col xs={12} md={12}>
<Card>
<CardBody>
<Form>
<FormGroup>
<Label for="multiItemSelect">
Add Items to Dashboard:
</Label>
<Select
id="multiItemSelect"
className="warning"
multi={true}
closeOnSelect={false}
placeholder="Add items to My product list"
name="multipleSelect"
value={this.state.multipleSelect}
options={options}
onChange={this.handleSelect}
/>
</FormGroup>
</Form>