Marina Yakovenko 5 years ago
parent
commit
6d308af8e2

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

@@ -8,7 +8,7 @@ const adminHeader = props => {
 	
 	const logout = (e) => {
         localStorage.removeItem('user');
-        document.location.reload(true);
+        props.history.push('/')
     }
 
 	return (

+ 2 - 5
src/components/adminMenu/adminMenu.js

@@ -11,8 +11,7 @@ class AdminMenu extends Component {
     }
 
     clickEventHandler = (e) => {
-        const elem = adminMenu.find(el => el.id === +e.target.id)
-        this.props.history.push(elem.path)
+        this.props.history.push(e)
     }
 
     render() {
@@ -23,10 +22,8 @@ class AdminMenu extends Component {
                     el.text !== "Log out" && el.text !== "Main Page" &&
                     <div
                         className="menu-skew"
-                        path={el.path}
                         key={el.id}
-                        id={el.id}
-                        onClick={this.clickEventHandler}
+                        onClick={this.clickEventHandler.bind(null, el.path)}
                     >
                         <h2 className="menu-text">{el.text.toUpperCase()}</h2>
                         {/* <Link to={el.path} className = "menu-text">{el.text.toUpperCase()}</Link>  */}

+ 5 - 4
src/components/sidebar/Sidebar.js

@@ -1,5 +1,5 @@
 import React from 'react';
-import { Link } from "react-router-dom";
+import { Link, withRouter } from "react-router-dom";
 import { connect } from "react-redux";
 
 import { showSidebar } from "../../actions/show-sidebar";
@@ -37,10 +37,11 @@ const siteMenu = [
 
 export class Sidebar extends React.Component {
     
-
     logoutHandler = () => {
         this.props.getLogoutUserSubmit()
+        this.props.history.push('/')
     }
+
     render() {
         console.log('ssdsd',this.props)
 	    const { showSidebar, showSidebarFlag, getLogoutUserSubmit } = this.props;
@@ -69,7 +70,7 @@ export class Sidebar extends React.Component {
 						}
                         {
                             localStorage.user && <li>
-                                <button className="logout" onClick={getLogoutUserSubmit}>
+                                <button className="logout" onClick={this.logoutHandler}>
                                     <i className="fa fa-sign-out"></i>
                                 </button>
                             </li>
@@ -96,4 +97,4 @@ const mapStateToProps = state => {
 export default connect(
     mapStateToProps,
     { showSidebar, getLogoutUserSubmit }
-)(Sidebar);
+)(withRouter(Sidebar));

+ 0 - 1
src/conteiners/adminAddEventPage/adminAddEventPage.js

@@ -8,7 +8,6 @@ import ConfirmationMessage from "../../components/confirmationMessage/confirmati
 
 class AdminAddEventPage extends Component {
     state = { 
-        // eventFormInitialValue: eventFormInitialValue.eventFormInitialValue,
         confirmationMessageFlag: false
      };
 

+ 16 - 3
src/conteiners/adminPhotogalaryPage/adminPhotogalaryPage.js

@@ -5,17 +5,26 @@ import * as actions from "../../actions/photogalaryActions";
 // import {photogalaryOnchange} from "../../actions/photogalaryActions";
 import AdminHeader from "../../components/adminHeader/adminHeader";
 import PhotogalaryForm from "../../components/adminPhotogalary/adminPhotogalaryReduxForm";
-// import {eventFormInitialValue} from "../../state/addEventInitialValue"
+import ConfirmationMessage from "../../components/confirmationMessage/confirmationMessage";
 
 class AdminAddPhotogalarytPage extends Component {
-    // state = { 
-    //  };
+    state = { 
+        confirmationMessageFlag: false
+     };
 
     componentDidMount() {
         this.props.getEvents();
         this.props.getPhotogalary()
     }
 
+    showConfirmationMessage = () => {
+        this.setState({confirmationMessageFlag: true })
+        document.location.reload(true);
+    };
+    closeConfirmationMessage = () => {
+        this.setState({confirmationMessageFlag: false })
+    };
+
     render() {
         const {
             eventTypes,
@@ -46,6 +55,10 @@ class AdminAddPhotogalarytPage extends Component {
                             // initialValues = {addPhotogalaryInitialValue}
                         />
                     </div>
+                    {this.state.confirmationMessageFlag && 
+                        <ConfirmationMessage closeMessage = {this.closeConfirmationMessage}>
+                            <div className = "text">Photogalary has beed added.</div>
+                        </ConfirmationMessage >}
                 </div>
             </>
 		);

+ 1 - 1
src/conteiners/home/Home.js

@@ -76,7 +76,7 @@ export default class Home extends React.Component {
         //console.log(events);
         return (
             <>
-                <Sidebar history={this.props.history}/>
+                <Sidebar/>
                 <div className="hero">
                     <div className="container-wrap">
                         <div className="hero-wrap">

+ 2 - 0
src/private-router.js

@@ -7,7 +7,9 @@ export const PrivateRoute = ({ component: Component, protectedRoute, ...rest })
 		render={props => {
 			if (protectedRoute) {
 				const user = localStorage.getItem("user");
+				console.log('user')
 				if (!user) {
+					console.log('user')
 					return <Redirect to="/" />;
 				}
 

+ 1 - 5
src/router.js

@@ -136,7 +136,7 @@ const Router = withRouter(({ history, user }) => {
 		}
 	}, [user]);
 
-	console.log('user', user)
+	// console.log('user', user)
 
 	return (
 		<div className="container">
@@ -149,7 +149,6 @@ const Router = withRouter(({ history, user }) => {
 						exact={el.exact}
 						path={el.path}
                         component={el.component}
-                        // events = {el.events && events}
 					/>
 				))}
 				
@@ -168,14 +167,11 @@ const Router = withRouter(({ history, user }) => {
 });
 
 const mapStateToProps = state => {
-	console.log('state',state)
     return {
-		// events: state.getEvents.events,
 		user: state.login.user
     };
 };
 
 export default connect(
     mapStateToProps
-    // { getAllEvents }
 )(Router);

+ 4 - 4
src/state/adminMenu.js

@@ -1,10 +1,10 @@
 export const adminMenu = [
-	{ path: "/admin", id: 0, text: "Main Page", logout: false },
+	// { path: "/admin", id: 0, text: "Main Page", logout: false },
 	{ path: "/admin/add_new_event", id: 1, text: "Add New Event", logout: false },
 	{ path: "/admin/my_events", id: 2, text: "My Events", logout: false },
-	{ path: "/admin/feedbacks", id: 3, text: "Feedbacks", logout: false },
-    { path: "/admin/photogalary", id: 4, text: "Add Photogalery", logout: false },
-	{ path: "/admin/results", id: 5, text: "Add Results", logout: false },
+    { path: "/admin/photogalary", id: 3, text: "Add Photogalery", logout: false },
+	{ path: "/admin/results", id: 4, text: "Add Results", logout: false },
+	{ path: "/admin/feedbacks", id: 5, text: "Feedbacks", logout: false },
 	{ path: "/", id: 6, text: "Go to WebSite", logout: false },
 	{ path: "/", id: 7, text: "Log out", logout: true }
 ];