Moved properties in dedicated tab

This commit is contained in:
dbroqua 2018-10-06 20:49:58 +02:00
parent a7aa0cb01a
commit 44366d1e7e
4 changed files with 79 additions and 41 deletions

View File

@ -2,7 +2,6 @@
text-align: center; text-align: center;
} }
@media screen and (min-width: 640px) { @media screen and (min-width: 640px) {
input.form-control { input.form-control {
margin: 0 16px; margin: 0 16px;
@ -38,3 +37,15 @@
padding: 16px; padding: 16px;
margin-top: 32px; margin-top: 32px;
} }
.form-group,
label {
text-align: left;
}
.properties--card {
background: #e9ecef;
padding: 6px;
border-radius: 6px;
box-shadow: 4px 4px 16px #999;
}

View File

@ -25,6 +25,7 @@ import API from './Api';
import VegetableMain from './Vegetable/Main' import VegetableMain from './Vegetable/Main'
import VegetableCarousel from './Vegetable/Carousel' import VegetableCarousel from './Vegetable/Carousel'
import VegetableMap from './Vegetable/Map' import VegetableMap from './Vegetable/Map'
import VegetablesProperties from './Vegetable/Properties'
import './Vegetable.css'; import './Vegetable.css';
import 'react-notifications/lib/notifications.css'; import 'react-notifications/lib/notifications.css';
@ -47,6 +48,7 @@ class Vegetable extends Component {
availableProperties: [] availableProperties: []
}; };
this.handleChange = this.handleChange.bind(this);
this.getVegetable = this.getVegetable.bind(this); this.getVegetable = this.getVegetable.bind(this);
this.updateVegetable = this.updateVegetable.bind(this); this.updateVegetable = this.updateVegetable.bind(this);
this.changeMainPicture = this.changeMainPicture.bind(this); this.changeMainPicture = this.changeMainPicture.bind(this);
@ -58,6 +60,19 @@ class Vegetable extends Component {
this.getVegetable(props.match.params.categoryId, props.match.params.vegetableId); this.getVegetable(props.match.params.categoryId, props.match.params.vegetableId);
} }
handleChange(event) {
const target = event.target;
const value = target.type === 'checkbox' ? target.checked : target.value;
const name = target.name;
this.setState(prevState => ({
Vegetable: {
...prevState.Vegetable,
[name]: value,
},
}));
}
toggle(tab) { toggle(tab) {
if (this.state.activeTab !== tab) { if (this.state.activeTab !== tab) {
this.setState({ this.setState({
@ -245,13 +260,21 @@ class Vegetable extends Component {
className={classnames({ active: this.state.activeTab === '2' })} className={classnames({ active: this.state.activeTab === '2' })}
onClick={() => { this.toggle('2'); }} onClick={() => { this.toggle('2'); }}
> >
Carte Propriétés
</NavLink> </NavLink>
</NavItem> </NavItem>
<NavItem> <NavItem>
<NavLink <NavLink
className={classnames({ active: this.state.activeTab === '3' })} className={classnames({ active: this.state.activeTab === '3' })}
onClick={() => { this.toggle('3'); }} onClick={() => { this.toggle('3'); }}
>
Carte
</NavLink>
</NavItem>
<NavItem>
<NavLink
className={classnames({ active: this.state.activeTab === '4' })}
onClick={() => { this.toggle('4'); }}
> >
Galerie Galerie
</NavLink> </NavLink>
@ -268,12 +291,19 @@ class Vegetable extends Component {
/> />
</TabPane> </TabPane>
<TabPane tabId="2"> <TabPane tabId="2">
<VegetablesProperties
selectedProperties={this.state.Vegetable.Properties}
availableProperties={this.state.availableProperties}
setProperties={this.handleChange}
/>
</TabPane>
<TabPane tabId="3">
<VegetableMap <VegetableMap
Vegetable={this.state.Vegetable} Vegetable={this.state.Vegetable}
updateValue={this.updateValueFromChild} updateValue={this.updateValueFromChild}
/> />
</TabPane> </TabPane>
<TabPane tabId="3"> <TabPane tabId="4">
<VegetableCarousel <VegetableCarousel
addPicture={this.addPicture} addPicture={this.addPicture}
imagesPreviewUrls={this.state.imagesPreviewUrls} imagesPreviewUrls={this.state.imagesPreviewUrls}

View File

@ -134,12 +134,6 @@ class VegetableMain extends Component {
/> />
</Col> </Col>
</FormGroup> </FormGroup>
<VegetablesProperties
selectedProperties={this.state.Vegetable.Properties}
availableProperties={this.state.availableProperties}
setProperties={this.handleChange}
/>
</Col> </Col>
<Col xs={12} sm={8}> <Col xs={12} sm={8}>
<div className="imgPreview"> <div className="imgPreview">

View File

@ -2,13 +2,14 @@ import React, {
Component, Component,
} from 'react'; } from 'react';
import { import {
Row,
Col,
Button, Button,
FormGroup, FormGroup,
Label, Label,
Input, Input,
InputGroup, InputGroup,
InputGroupAddon, InputGroupAddon
Col
} from 'reactstrap'; } from 'reactstrap';
import { import {
FaPlus, FaPlus,
@ -103,7 +104,7 @@ class VegetablesProperties extends Component {
break; break;
} }
} }
return !isSet; return !isSet;
} }
@ -120,45 +121,47 @@ class VegetablesProperties extends Component {
render() { render() {
return ( return (
<div> <Row>
{this.state.selectedProperties.map( (item , key) => ( {this.state.selectedProperties.map( (item , key) => (
<FormGroup row key={key}> <Col xs={12} lg={6} xl={4} key={key}>
<Label for="name" sm={4}>{item.label ? item.label : (item.Property ? item.Property.name : '')}</Label> <FormGroup className="properties--card">
<Col sm={8}> <Label for="name">{item.label ? item.label : (item.Property ? item.Property.name : '')}</Label>
<Input <Input
type="text" type="textarea"
value={item.value} value={item.value}
id={item.propertyId} id={item.propertyId}
placeholder={item.label} placeholder={item.label}
onChange={this.handleArrayChange} onChange={this.handleArrayChange}
onBlur={this.updateParent} onBlur={this.updateParent}
/> />
</FormGroup>
</Col>
))}
<Col xs={12}>
<hr />
<FormGroup row>
<Label for="newProperty" sm={4}>Propriétés</Label>
<Col sm={8}>
<InputGroup>
<Input value={this.state.selectedPropety} type="select" name="selectedPropety" id="newProperty" onChange={this.handleChange}>
<option />
{this.state.availableProperties.map( (item, key) => {
if ( this.notSet( item.id ) ) {
return (<option key={key} value={item.id}>{item.name}</option>)
}
return (null)
})}
</Input>
<InputGroupAddon addonType="append">
<Button color="primary" onClick={this.addProperty}>
<FaPlus />
</Button>
</InputGroupAddon>
</InputGroup>
</Col> </Col>
</FormGroup> </FormGroup>
))} </Col>
<hr /> </Row>
<FormGroup row>
<Label for="newProperty" sm={4}>Propriétés</Label>
<Col sm={8}>
<InputGroup>
<Input value={this.state.selectedPropety} type="select" name="selectedPropety" id="newProperty" onChange={this.handleChange}>
{this.state.availableProperties.map( (item, key) => {
if ( this.notSet( item.id ) ) {
return (<option key={key} value={item.id}>{item.name}</option>)
}
return (null)
})}
</Input>
<InputGroupAddon addonType="append">
<Button color="primary" onClick={this.addProperty}>
<FaPlus />
</Button>
</InputGroupAddon>
</InputGroup>
</Col>
</FormGroup>
</div>
) )
} }