|
@@ -1,39 +1,55 @@
|
|
|
import React, { Component } from "react";
|
|
|
|
|
|
export default class LoadForm extends Component {
|
|
|
+ changeHandler = e => {
|
|
|
+ const { changeInputValue } = this.props;
|
|
|
+ const { value, id, checked } = e.target;
|
|
|
+ changeInputValue({ value, id, checked });
|
|
|
+ };
|
|
|
+
|
|
|
render() {
|
|
|
+ const { addToList, loads, changeInputValue, addLoads } = this.props;
|
|
|
return (
|
|
|
<div className="form">
|
|
|
<div className="form__input-box">
|
|
|
<label className="form__input-lable" htmlFor="origin">
|
|
|
Город отправитель
|
|
|
- <input className="form__input" id="origin" type="text" />
|
|
|
+ <input onChange={e => this.changeHandler(e)} className="form__input" id="origin" type="text" />
|
|
|
</label>
|
|
|
</div>
|
|
|
<div className="form__input-box">
|
|
|
<label className="form__input-lable" htmlFor="destination">
|
|
|
Город получатель
|
|
|
- <input className="form__input" id="destination" type="text" />
|
|
|
+ <input
|
|
|
+ onChange={e => this.changeHandler(e)}
|
|
|
+ className="form__input"
|
|
|
+ id="destination"
|
|
|
+ type="text"
|
|
|
+ />
|
|
|
</label>
|
|
|
</div>
|
|
|
<div className="form__input-box">
|
|
|
<label className="form__input-lable" htmlFor="name">
|
|
|
Введите имя водителя
|
|
|
- <input className="form__input" id="name" type="text" />
|
|
|
+ <input onChange={e => this.changeHandler(e)} className="form__input" id="name" type="text" />
|
|
|
</label>
|
|
|
</div>
|
|
|
|
|
|
<div className="form__input-box">
|
|
|
<label className="form__input-lable" htmlFor="night">
|
|
|
Ночная перевозка ?
|
|
|
- <input className="form__input" id="night" type="checkbox" />
|
|
|
+ <input onChange={e => this.changeHandler(e)} className="form__input" id="night" type="checkbox" />
|
|
|
</label>
|
|
|
</div>
|
|
|
|
|
|
<div className="form__input-box">
|
|
|
<label className="form__input-lable" htmlFor="bodyType">
|
|
|
Тип кузова
|
|
|
- <select className="form__input" name="bodyType" id="bodyType">
|
|
|
+ <select
|
|
|
+ onChange={e => this.changeHandler(e)}
|
|
|
+ className="form__input"
|
|
|
+ name="bodyType"
|
|
|
+ id="bodyType">
|
|
|
<option value="type1">Тип 1</option>
|
|
|
<option value="type2">Тип 2</option>
|
|
|
<option value="type3">Тип 3</option>
|
|
@@ -45,19 +61,32 @@ export default class LoadForm extends Component {
|
|
|
<div className="form__input-box">
|
|
|
<label className="form__input-lable" htmlFor="weight">
|
|
|
Вес
|
|
|
- <input className="form__input" id="weight" type="number" />
|
|
|
+ <input onChange={e => this.changeHandler(e)} className="form__input" id="weight" type="number" />
|
|
|
</label>
|
|
|
</div>
|
|
|
|
|
|
- <div className="form__input-box">
|
|
|
- <label className="form__input-lable" htmlFor="load">
|
|
|
- Груз
|
|
|
- <input className="form__input" id="load" type="text" />
|
|
|
- </label>
|
|
|
- </div>
|
|
|
+ <button type="button" onClick={addLoads}>
|
|
|
+ Добавить груз
|
|
|
+ </button>
|
|
|
+
|
|
|
+ {loads.map(el => (
|
|
|
+ <div key={el.id} className="form__input-box">
|
|
|
+ <label className="form__input-lable" htmlFor="name">
|
|
|
+ Груз
|
|
|
+ <input
|
|
|
+ onChange={e => changeInputValue({ id: el.id, value: e.target.value, loads: true })}
|
|
|
+ className="form__input"
|
|
|
+ id="name"
|
|
|
+ type="text"
|
|
|
+ />
|
|
|
+ </label>
|
|
|
+ </div>
|
|
|
+ ))}
|
|
|
|
|
|
<div className="form__button-box">
|
|
|
- <button className="form__submit-button">Создать Доставку</button>
|
|
|
+ <button className="form__submit-button" onClick={addToList}>
|
|
|
+ Создать Доставку
|
|
|
+ </button>
|
|
|
<button className="form__submit-button form__submit-button--reset">Очистить форму</button>
|
|
|
</div>
|
|
|
</div>
|