|
@@ -1,12 +1,10 @@
|
|
|
import React, { Component } from "react";
|
|
|
import { reduxForm, Field } from "redux-form";
|
|
|
-
|
|
|
import "./adminPhotogalary.scss";
|
|
|
import { addPhotogalaryInitialValue } from "../../state/photogalaryFormData";
|
|
|
import { customInput } from "../customFields/customInput/customInput";
|
|
|
import { customSelect } from "../customFields/customSelect/customSelect";
|
|
|
import { eventTypes } from "../../state/addEventInitialValue";
|
|
|
-import { eventFormValidation } from "../../utils/eventFormValidation";
|
|
|
|
|
|
class PhotogalaryReduxForm extends Component {
|
|
|
|
|
@@ -14,30 +12,22 @@ class PhotogalaryReduxForm extends Component {
|
|
|
addPhotogalaryInitialValue
|
|
|
}
|
|
|
|
|
|
- submit = e => {
|
|
|
- e.preventDefault();
|
|
|
-
|
|
|
- const values = Object.keys(this.state.addPhotogalaryInitialValue).reduce((prev, elem) => {
|
|
|
- return { ...prev, [elem]: this.state.addPhotogalaryInitialValue[elem].value };
|
|
|
- }, {});
|
|
|
|
|
|
- this.props.submitHandler(values);
|
|
|
+ submit = e => {
|
|
|
+ // this.props.submitHandler(addPhotogalaryInitialValue);
|
|
|
};
|
|
|
|
|
|
onChangeHandler = e => {
|
|
|
const { name, value, id } = e.target;
|
|
|
|
|
|
this.setState(prevState => {
|
|
|
- const values = Object.keys(prevState.addPhotogalaryInitialValue).reduce((prev, elem) => {
|
|
|
- if (elem === name) return prev.concat(value);
|
|
|
- return prev.concat(prevState.addPhotogalaryInitialValue[elem].value);
|
|
|
- }, []);
|
|
|
|
|
|
return {
|
|
|
...prevState,
|
|
|
addPhotogalaryInitialValue: {
|
|
|
...prevState.addPhotogalaryInitialValue,
|
|
|
- pictures: prevState.addPhotogalaryInitialValue.pictures.map(el => (el.id === +id ? { ...el, value } : el))
|
|
|
+ [name]: value,
|
|
|
+ pictures: prevState.addPhotogalaryInitialValue.pictures.map(el => (el.id === id ? { ...el, value } : el))
|
|
|
}
|
|
|
};
|
|
|
});
|
|
@@ -49,7 +39,7 @@ class PhotogalaryReduxForm extends Component {
|
|
|
addPhotogalaryInitialValue: {
|
|
|
...prevState.addPhotogalaryInitialValue,
|
|
|
pictures: prevState.addPhotogalaryInitialValue.pictures.concat({
|
|
|
- id: +Math.random()
|
|
|
+ id: Math.random()
|
|
|
.toString()
|
|
|
.substr(2, 100),
|
|
|
value: ""
|
|
@@ -67,13 +57,13 @@ class PhotogalaryReduxForm extends Component {
|
|
|
return (
|
|
|
<form className="event-form__event-form__main" onSubmit={handleSubmit(this.submit)}>
|
|
|
|
|
|
- <Field name="eventType" label="Event Type" required component={customSelect} >
|
|
|
+ <Field name="eventType" label="Event Type" required component={customSelect} onChange = {this.onChangeHandler} >
|
|
|
{eventTypes.map(elem => <option key={elem.id} value={elem.optionName}>{elem.optionName}</option>)}
|
|
|
</Field>
|
|
|
- <Field name="title" label="Event Title" required component={customInput} />
|
|
|
+ <Field name="eventTytle" label="Event Title" required component={customInput} onChange = {this.onChangeHandler} />
|
|
|
|
|
|
{addPhotogalaryInitialValue.pictures.map((el, i) => (
|
|
|
- <Field key={`${el.id}/${i}`} name="pictures" label="Picture" className="input-box__wide" placeholder='Enter picture url' component={customInput} />
|
|
|
+ <Field key={`${el.id}/${i}`} name="pictures" label="Picture" onChange = {this.onChangeHandler} className="input-box__wide" placeholder='Enter picture url' component={customInput} />
|
|
|
))}
|
|
|
<button type="button" className="photogalary-form__picture-btn" onClick={this.addPicture} >Add Picture</button>
|
|
|
<div className="event-form__control-box">
|