|
@@ -1,6 +1,6 @@
|
|
|
import React, { Component } from 'react';
|
|
|
import { Field, reduxForm } from 'redux-form';
|
|
|
-
|
|
|
+import { Link, Redirect } from "react-router-dom";
|
|
|
import FormData from 'form-data'
|
|
|
|
|
|
|
|
@@ -46,10 +46,8 @@ class FormRedactorStaff extends Component {
|
|
|
|
|
|
}
|
|
|
send = () =>{
|
|
|
- const { inputData, inputData1, inputData2, inputData3, match, photo, EditStaffAction, InfoStaff, getUser } = this.props
|
|
|
-
|
|
|
+ const { inputData, inputData1, inputData2, inputData3, match, photo, EditStaffAction, InfoStaff, getUser } = this.props
|
|
|
let values = {}
|
|
|
-
|
|
|
if(!this.state.trig){
|
|
|
values.img = "http://rs.img.com.ua/crop?v2=1&w=600&h=0&url=%2F%2Fbm.img.com.ua%2Fberlin%2Fstorage%2Forig%2Fd224d3bd9bfe8bcb6b561da523d87364.jpg";
|
|
|
values.state = 0
|
|
@@ -58,32 +56,43 @@ class FormRedactorStaff extends Component {
|
|
|
values.img = `http://127.0.0.1:2000/static/${photo.map(el => el.data.fileName)}`;
|
|
|
values.state = 1
|
|
|
}
|
|
|
- values.staff = "Машина"
|
|
|
- values.title = inputData
|
|
|
- values.description = inputData1
|
|
|
- values.price = inputData2
|
|
|
- values.categoryId = inputData3
|
|
|
+ values.title = inputData
|
|
|
+ values.description = inputData1
|
|
|
+ values.price = inputData2
|
|
|
+ values.categoryId = inputData3
|
|
|
+ values.staff = "Машина"
|
|
|
values.userId = getUser.id
|
|
|
values.id = InfoStaff[0].id
|
|
|
- //EditStaffAction(values)
|
|
|
- console.log(values)
|
|
|
+ if(values.title === ""){
|
|
|
+ InfoStaff.map(el => values.title = el.title)
|
|
|
+ }
|
|
|
+ if(values.description === ""){
|
|
|
+ InfoStaff.map(el => values.description = el.description)
|
|
|
+ }
|
|
|
+ if(values.price === null){
|
|
|
+ InfoStaff.map(el => values.price = el.price)
|
|
|
+ }
|
|
|
+ if(values.categoryId === null){
|
|
|
+ InfoStaff.map(el => values.categoryId = el.categoryId)
|
|
|
+ }
|
|
|
+ EditStaffAction(values)
|
|
|
+
|
|
|
+ //console.log(values)
|
|
|
}
|
|
|
render(){
|
|
|
|
|
|
|
|
|
const { handleSubmit, pristine, reset, submitting, InfoStaff, photo, allCategory } = this.props
|
|
|
- console.log("InfoStaff", InfoStaff)
|
|
|
+
|
|
|
const category = allCategory.data.filter(el => el.parentId !== 0)
|
|
|
let data;
|
|
|
- if(this.props.InfoStaff[0].id === this.props.match.params.id){
|
|
|
- data = []
|
|
|
- }
|
|
|
- else{
|
|
|
+
|
|
|
+
|
|
|
data = InfoStaff.map(el => <form className="form">
|
|
|
<input type="text" name="title" defaultValue ={el.title} className="input" onChange={this.changeHandler}/>
|
|
|
<textarea type="text" name="description" defaultValue ={el.description} className="input" onChange={this.changeHandler1}/>
|
|
|
<input type="number" name="price" defaultValue ={el.price} className="input" onChange={this.changeHandler2}/>
|
|
|
- <select type="number" name="categoryId" className="input" onChange={this.changeHandler3}>
|
|
|
+ <select type="number" name="categoryId" className="input" defaultValue ={el.categoryId} onChange={this.changeHandler3}>
|
|
|
|
|
|
<option >Выберите рубрику</option>
|
|
|
{category.map(el => <option value={el.id}> {el.title}</option>)}
|
|
@@ -112,10 +121,10 @@ class FormRedactorStaff extends Component {
|
|
|
|
|
|
|
|
|
<div className="buttonConteiner">
|
|
|
- <button type="button" className="button" onClick={this.send}>
|
|
|
+ <button type="button" className="button" onClick={this.send}>
|
|
|
Submit
|
|
|
</button>
|
|
|
- <button type="button" disabled={pristine || submitting} onClick={reset} className="button" >
|
|
|
+ <button type="button" disabled={pristine || submitting} onClick={reset} className="button" >
|
|
|
Clear Values
|
|
|
</button>
|
|
|
|
|
@@ -124,7 +133,7 @@ class FormRedactorStaff extends Component {
|
|
|
|
|
|
</form>
|
|
|
)
|
|
|
- }
|
|
|
+
|
|
|
return (
|
|
|
|
|
|
<div className="formdiv">
|
|
@@ -137,4 +146,8 @@ class FormRedactorStaff extends Component {
|
|
|
|
|
|
export default reduxForm({
|
|
|
form: 'RedactorForm'
|
|
|
-})(FormRedactorStaff)
|
|
|
+})(FormRedactorStaff)
|
|
|
+
|
|
|
+// {!this.state.trig ? <button type="button" className="button" onClick={this.send}>
|
|
|
+// Submit
|
|
|
+// </button>: <Redirect to='/' /> }
|