Browse Source

admin page files

Marina Yakovenko 5 years ago
parent
commit
aa4faabaf1

+ 1 - 1
src/components/adminMenu/adminMenu.js

@@ -1,5 +1,5 @@
 import React, { Component } from "react";
-import { Link, withRouter } from "react-router-dom";
+import { withRouter } from "react-router-dom";
 import "./adminMenu.scss";
 import { adminMenu } from "../../state/adminMenu";
 

+ 8 - 18
src/components/adminPhotogalary/adminPhotogalaryReduxForm.js

@@ -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">

+ 3 - 3
src/components/eventForm/eventReduxForm.js

@@ -1,4 +1,4 @@
-import React, { Component } from "react";
+import React from "react";
 import { reduxForm, Field } from "redux-form";
 import "./eventForm.scss";
 import { customInput } from "../customFields/customInput/customInput";
@@ -13,7 +13,7 @@ const EventReduxForm = ({
 }) => {
 
     const submit = value => {
-        console.log('submit values', value)
+        // console.log('submit values', value)
         postNewEvent(value)
     };
 
@@ -56,7 +56,7 @@ const EventReduxForm = ({
         <form className="event-form__event-form__main" onSubmit={handleSubmit(submit)}>
             {console.log('eventFormInitialValue', eventFormInitialValue)}
 
-            <img className="event-form__picture" src={eventFormInitialValue.mainBannerPicture} />
+            <img className="event-form__picture" alt="Event Bunner" src={eventFormInitialValue.mainBannerPicture} />
             <Field name="mainBannerPicture" className="input-box__wide" label="Main Banner Picture" component={customInput} />
             <Field name="title" label="Event Title" className="input-box__wide" required component={customInput} />
             <Field name="eventType" label="Event Type" required component={customSelect} >

+ 28 - 19
src/conteiners/adminMainPage/adminMainPage.js

@@ -1,31 +1,40 @@
-import React, {Component} from 'react';
+import React, { Component } from 'react';
 import { connect } from "react-redux";
-// import * as actions from "../../actions/carElementActions";
+import { showSidebar } from "../../actions/show-sidebar";
 import "./adminMainPage.scss";
 import Header from '../../components/adminHeader/adminHeader';
 import AdminMenu from '../../components/adminMenu/adminMenu';
 
 class AdminMainPage extends Component {
-    render() {
-        const { 
-
-         } = this.props;
-    
-        return (
-          <div className = "admin-main-page-wrapper">
-            <Header />
-            <AdminMenu />
-          </div>
-        )
-    }
+
+  componentDidMount() {
+    this.props.showSidebar()
+  }
+
+  componentWillUnmount() {
+    this.props.showSidebar()
+  }
+  
+  render() {
+    // const {
+
+    // } = this.props;
+
+    return (
+      <div className="admin-main-page-wrapper">
+        <Header />
+        <AdminMenu />
+      </div>
+    )
+  }
 }
-    
-    
+
+
 const mapStateToProps = state => ({
 
 });
-    
+
 export default connect(
-    mapStateToProps,
-    //actions
+  mapStateToProps,
+  { showSidebar }
 )(AdminMainPage);

+ 20 - 8
src/conteiners/adminPhotogalaryPage/adminPhotogalaryPage.js

@@ -1,9 +1,10 @@
 import React, { Component } from "react";
 import { connect } from "react-redux";
-import * as actions from "../../actions/adminMainPageActions";
+// import * as actions from "../../actions/adminMainPageActions";
 import AdminHeader from "../../components/adminHeader/adminHeader";
 import PhotogalaryForm from "../../components/adminPhotogalary/adminPhotogalaryReduxForm";
-import {eventFormInitialValue} from "../../state/addEventInitialValue"
+import { showSidebar } from "../../actions/show-sidebar";
+// import {eventFormInitialValue} from "../../state/addEventInitialValue"
 
 class AdminAddPhotogalarytPage extends Component {
     // state = { 
@@ -12,13 +13,21 @@ class AdminAddPhotogalarytPage extends Component {
 
     // componentDidMount() {
 	//     this.props.getEvents();
-	// }
+    // }
+    
+    componentDidMount() {
+        this.props.showSidebar()
+      }
+    
+      componentWillUnmount() {
+        this.props.showSidebar()
+      }
 
     render() {
-        const {
-            postNewEvent,
-            eventList
-        } = this.props
+        // const {
+        //     postNewEvent,
+        //     eventList
+        // } = this.props
 
         // console.log('eventList', eventList)
 
@@ -41,4 +50,7 @@ const mapStateToProps = state => ({
 	eventList: state.adminMainPageReducer.eventList,
 });
 
-export default connect(mapStateToProps, actions)(AdminAddPhotogalarytPage);
+export default connect(
+    mapStateToProps, 
+    { showSidebar }
+)(AdminAddPhotogalarytPage);

+ 0 - 2
src/router.js

@@ -7,7 +7,6 @@ import AdminAddEventPage from './conteiners/adminAddEventPage/adminAddEventPage'
 import Home from './conteiners/home/Home';
 import Login from './conteiners/login/Login';
 
-import EventReduxForm from "./components/eventForm/eventReduxForm"
 import AdminAddPhotogalarytPage from "./conteiners/adminPhotogalaryPage/adminPhotogalaryPage"
 import Sidebar from './components/sidebar/Sidebar';
 
@@ -49,7 +48,6 @@ export class Router extends React.Component {
 			           
 			            <Route exact path = '/admin' component = {AdminMainPage} />
 			            <Route exact path = '/admin/add_new_event' component = {AdminAddEventPage} />
-			            <Route exact path = '/admin/my_events' component = {EventReduxForm} />
 			            <Route exact path = '/admin/photogalary' component = {AdminAddPhotogalarytPage} />
 			            
 			        </Switch>

+ 1 - 2
src/state/adminMenu.js

@@ -4,6 +4,5 @@ export const adminMenu = [
 	{ path: "/admin/my_events", id: 2, text: "My Events", hideWhenAuth: false },
     { path: "/admin/photogalary", id: 3, text: "Photogalery", hideWhenAuth: false },
     { path: "/admin/feedbacks", id: 4, text: "Feedbacks", hideWhenAuth: false },
-	{ path: "/main_page", id: 5, text: "Log out", hideWhenAuth: false },
-	// { path: "/auth", id: 5, text: "Auth", hideWhenAuth: true }
+	{ path: "/", id: 5, text: "Log out", hideWhenAuth: false }
 ];