|
@@ -4,29 +4,66 @@ 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";
|
|
|
|
|
|
class PhotogalaryReduxForm extends Component {
|
|
|
|
|
|
state = {
|
|
|
- addPhotogalaryInitialValue
|
|
|
+ addPhotogalaryInitialValue,
|
|
|
+ filteredEventList: [{ _id: 0, title: 'Choose Event' }]
|
|
|
}
|
|
|
|
|
|
+ submit = values => {
|
|
|
+ // console.log('submit props', this.props)
|
|
|
+ // console.log('submit state', this.state)
|
|
|
+ const pictures = this.state.addPhotogalaryInitialValue.pictures.reduce((prev, elem) => {
|
|
|
+ return prev.concat(elem.value);
|
|
|
+ }, []);
|
|
|
|
|
|
- submit = e => {
|
|
|
- // this.props.submitHandler(addPhotogalaryInitialValue);
|
|
|
+ const eventId = this.props.eventList.find(
|
|
|
+ event => event.title === this.state.addPhotogalaryInitialValue.eventTitle
|
|
|
+ )._id
|
|
|
+
|
|
|
+ const submitValues = {
|
|
|
+ ...this.state.addPhotogalaryInitialValue,
|
|
|
+ pictures: pictures,
|
|
|
+ // _id: eventId
|
|
|
+ }
|
|
|
+ // console.log('submit eventId', eventId)
|
|
|
+ console.log('submit values', submitValues)
|
|
|
+ // console.log('pictures', pictures)
|
|
|
+
|
|
|
+ this.props.submitHandler(submitValues);
|
|
|
+ this.props.reset()
|
|
|
+ };
|
|
|
+
|
|
|
+ onChangeTypeHandler = e => {
|
|
|
+ const { name, value } = e.target;
|
|
|
+ console.log('eventInput', value)
|
|
|
+ this.setState(prevState => {
|
|
|
+ console.log('prevStateInput', prevState)
|
|
|
+ return {
|
|
|
+ ...prevState,
|
|
|
+ addPhotogalaryInitialValue: {
|
|
|
+ ...prevState.addPhotogalaryInitialValue,
|
|
|
+ [name]: value
|
|
|
+ },
|
|
|
+ filteredEventList: prevState.filteredEventList.concat(
|
|
|
+ this.props.eventList.filter(el => el.eventType === value)
|
|
|
+ )
|
|
|
+ };
|
|
|
+ });
|
|
|
};
|
|
|
|
|
|
- onChangeHandler = e => {
|
|
|
+ onChangeTitleHandler = e => {
|
|
|
const { name, value } = e.target;
|
|
|
- // console.log('eventInput',e)
|
|
|
+ console.log('eventInput', value)
|
|
|
this.setState(prevState => {
|
|
|
- // console.log('prevStateInput', prevState)
|
|
|
+ console.log('prevStateInput', prevState)
|
|
|
return {
|
|
|
...prevState,
|
|
|
addPhotogalaryInitialValue: {
|
|
|
...prevState.addPhotogalaryInitialValue,
|
|
|
- [ name ]: value
|
|
|
+ [name]: value
|
|
|
}
|
|
|
};
|
|
|
});
|
|
@@ -34,9 +71,9 @@ class PhotogalaryReduxForm extends Component {
|
|
|
|
|
|
onChangePicturesHandler = e => {
|
|
|
const { value, id } = e.target;
|
|
|
- // console.log('eventPicture',e)
|
|
|
+ console.log('eventPicture', e)
|
|
|
this.setState(prevState => {
|
|
|
- // console.log('prevStatePicture', prevState)
|
|
|
+ console.log('prevStatePicture', prevState)
|
|
|
return {
|
|
|
...prevState,
|
|
|
addPhotogalaryInitialValue: {
|
|
@@ -48,68 +85,76 @@ class PhotogalaryReduxForm extends Component {
|
|
|
};
|
|
|
|
|
|
addPicture = (e) => {
|
|
|
- this.setState(prevState => ({
|
|
|
- ...prevState,
|
|
|
- addPhotogalaryInitialValue: {
|
|
|
- ...prevState.addPhotogalaryInitialValue,
|
|
|
- pictures: prevState.addPhotogalaryInitialValue.pictures.concat({
|
|
|
- id: Math.random()
|
|
|
- .toString()
|
|
|
- .substr(2, 100),
|
|
|
- name: `picture ${Math.random()
|
|
|
- .toString()
|
|
|
- .substr(2, 100)}`,
|
|
|
- value: ""
|
|
|
- })
|
|
|
+ this.setState(prevState => {
|
|
|
+ console.log('prevStatePicture-add', prevState)
|
|
|
+ return {
|
|
|
+ ...prevState,
|
|
|
+ addPhotogalaryInitialValue: {
|
|
|
+ ...prevState.addPhotogalaryInitialValue,
|
|
|
+ pictures: prevState.addPhotogalaryInitialValue.pictures.concat({
|
|
|
+ id: Math.random()
|
|
|
+ .toString()
|
|
|
+ .substr(2, 100),
|
|
|
+ name: `picture_${Math.random()
|
|
|
+ .toString()
|
|
|
+ .substr(2, 100)}`,
|
|
|
+ value: ""
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
- }));
|
|
|
+ });
|
|
|
};
|
|
|
|
|
|
render() {
|
|
|
- const { addPhotogalaryInitialValue } = this.state;
|
|
|
- console.log(this.state)
|
|
|
+ const { filteredEventList, addPhotogalaryInitialValue } = this.state;
|
|
|
+ // console.log(this.state)
|
|
|
|
|
|
- const { handleSubmit, eventTypes } = this.props;
|
|
|
+ const {
|
|
|
+ handleSubmit,
|
|
|
+ eventTypes,
|
|
|
+ } = this.props;
|
|
|
|
|
|
return (
|
|
|
<form className="event-form__event-form__main" onSubmit={handleSubmit(this.submit)}>
|
|
|
|
|
|
- <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="eventTytle"
|
|
|
- label="Event Title"
|
|
|
- required
|
|
|
- component={customInput}
|
|
|
- onChange = {this.onChangeHandler}
|
|
|
- />
|
|
|
-
|
|
|
- {addPhotogalaryInitialValue.pictures.map((el, i) => (
|
|
|
- <Field
|
|
|
- key={`${el.id}/${i}`}
|
|
|
- name={el.name}
|
|
|
- id={el.id}
|
|
|
- label="Picture"
|
|
|
- onChange = {this.onChangePicturesHandler}
|
|
|
- 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">
|
|
|
- <button className="event-form__submit-btn" >Add Event</button>
|
|
|
- </div>
|
|
|
- </form>
|
|
|
-
|
|
|
+ <Field
|
|
|
+ name="eventType"
|
|
|
+ label="Event Type"
|
|
|
+ required
|
|
|
+ component={customSelect}
|
|
|
+ onChange={this.onChangeTypeHandler}
|
|
|
+ >
|
|
|
+ {eventTypes.map(elem => <option key={elem.id} value={elem.optionName}>{elem.optionName}</option>)}
|
|
|
+ </Field>
|
|
|
+
|
|
|
+ <Field
|
|
|
+ name="eventTitle"
|
|
|
+ label="Event Title"
|
|
|
+ required
|
|
|
+ component={customSelect}
|
|
|
+ onChange={this.onChangeTitleHandler}
|
|
|
+ >
|
|
|
+ {filteredEventList.map(elem => <option key={elem._id} value={elem.title}>{elem.title}</option>)}
|
|
|
+ </Field>
|
|
|
+
|
|
|
+ {addPhotogalaryInitialValue.pictures.map((el, i) => (
|
|
|
+ <Field
|
|
|
+ key={`${el.id}/${i}`}
|
|
|
+ name={el.name}
|
|
|
+ id={el.id}
|
|
|
+ label="Picture"
|
|
|
+ onChange={this.onChangePicturesHandler}
|
|
|
+ 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">
|
|
|
+ <button className="event-form__submit-btn" >Add Photogalary</button>
|
|
|
+ </div>
|
|
|
+ </form>
|
|
|
+
|
|
|
);
|
|
|
}
|
|
|
}
|