소스 검색

Merge branch 'dev' of http://gitlab.a-level.com.ua/Entony/FEA_12_TRIATHLON into dev

Tanya Sashyna 5 년 전
부모
커밋
59c1afbf05

+ 67 - 65
src/actionTypes/actionTypes.js

@@ -1,87 +1,89 @@
-export const POST_NEW_EVENT_REQUEST = "POST_NEW_EVENT_REQUEST";
-export const POST_NEW_EVENT_REQUEST_SUCCESS = "POST_NEW_EVENT_REQUEST_SUCCESS";
-export const POST_NEW_EVENT_REQUEST_FAIL = "POST_NEW_EVENT_REQUEST_FAIL";
+export const POST_NEW_EVENT_REQUEST = 'POST_NEW_EVENT_REQUEST';
+export const POST_NEW_EVENT_REQUEST_SUCCESS = 'POST_NEW_EVENT_REQUEST_SUCCESS';
+export const POST_NEW_EVENT_REQUEST_FAIL = 'POST_NEW_EVENT_REQUEST_FAIL';
 
-export const GET_EVENTS_REQUEST = "GET_EVENTS_REQUEST";
-export const GET_EVENTS_REQUEST_SUCCESS = "GET_EVENTS_REQUEST_SUCCESS";
-export const GET_EVENTS_REQUEST_FAIL = "GET_EVENTS_REQUEST_FAIL";
+export const GET_EVENTS_REQUEST = 'GET_EVENTS_REQUEST';
+export const GET_EVENTS_REQUEST_SUCCESS = 'GET_EVENTS_REQUEST_SUCCESS';
+export const GET_EVENTS_REQUEST_FAIL = 'GET_EVENTS_REQUEST_FAIL';
 
-export const EDIT_EVENT_REQUEST = "EDIT_EVENT_REQUEST";
-export const EDIT_EVENT_REQUEST_SUCCESS = "EDIT_EVENT_REQUEST_SUCCESS";
-export const EDIT_EVENT_REQUEST_FAIL = "EDIT_EVENT_REQUEST_FAIL";
+export const EDIT_EVENT_REQUEST = 'EDIT_EVENT_REQUEST';
+export const EDIT_EVENT_REQUEST_SUCCESS = 'EDIT_EVENT_REQUEST_SUCCESS';
+export const EDIT_EVENT_REQUEST_FAIL = 'EDIT_EVENT_REQUEST_FAIL';
 
-export const REMOVE_EVENT_REQUEST = "REMOVE_EVENT_REQUEST";
-export const REMOVE_EVENT_REQUEST_SUCCESS = "REMOVE_EVENT_REQUEST_SUCCESS";
-export const REMOVE_EVENT_REQUEST_FAIL = "REMOVE_EVENT_REQUEST_FAIL";
+export const REMOVE_EVENT_REQUEST = 'REMOVE_EVENT_REQUEST';
+export const REMOVE_EVENT_REQUEST_SUCCESS = 'REMOVE_EVENT_REQUEST_SUCCESS';
+export const REMOVE_EVENT_REQUEST_FAIL = 'REMOVE_EVENT_REQUEST_FAIL';
 
-export const SHOW_SIDEBAR = "SHOW_SIDEBAR";
+export const SHOW_SIDEBAR = 'SHOW_SIDEBAR';
 
-export const POST_REQUEST_LOGIN = "POST_REQUEST_LOGIN";
-export const POST_REQUEST_SUCCESS_LOGIN = "POST_REQUEST_SUCCESS_LOGIN";
-export const POST_REQUEST_ERROR_LOGIN = "POST_REQUEST_ERROR_LOGIN";
+export const POST_REQUEST_LOGIN = 'POST_REQUEST_LOGIN';
+export const POST_REQUEST_SUCCESS_LOGIN = 'POST_REQUEST_SUCCESS_LOGIN';
+export const POST_REQUEST_ERROR_LOGIN = 'POST_REQUEST_ERROR_LOGIN';
 
-export const POST_REQUEST_CHECKIN = "POST_REQUEST_CHECKIN";
-export const POST_REQUEST_SUCCESS_CHECKIN = "POST_REQUEST_SUCCESS_CHECKIN";
-export const POST_REQUEST_ERROR_CHECKIN = "POST_REQUEST_ERROR_CHECKIN";
+export const POST_REQUEST_CHECKIN = 'POST_REQUEST_CHECKIN';
+export const POST_REQUEST_SUCCESS_CHECKIN = 'POST_REQUEST_SUCCESS_CHECKIN';
+export const POST_REQUEST_ERROR_CHECKIN = 'POST_REQUEST_ERROR_CHECKIN';
 
-export const GET_REQUEST_EVENTS = "GET_REQUEST_EVENTS";
-export const GET_REQUEST_SUCCESS_EVENTS = "GET_REQUEST_SUCCESS_EVENTS";
-export const GET_REQUEST_ERROR_EVENTS = "GET_REQUEST_ERROR_EVENTS";
+export const GET_REQUEST_EVENTS = 'GET_REQUEST_EVENTS';
+export const GET_REQUEST_SUCCESS_EVENTS = 'GET_REQUEST_SUCCESS_EVENTS';
+export const GET_REQUEST_ERROR_EVENTS = 'GET_REQUEST_ERROR_EVENTS';
 
-export const EDIT_EVENT = "EDIT_EVENT";
+export const EDIT_EVENT = 'EDIT_EVENT';
 
-export const GET_PHOTOGALARY_REQUEST = "GET_PHOTOGALARY_REQUEST";
-export const GET_PHOTOGALARY_REQUEST_SUCCESS = "GET_PHOTOGALARY_REQUEST_SUCCESS";
-export const GET_PHOTOGALARY_REQUEST_FAIL = "GET_PHOTOGALARY_REQUEST_FAIL";
+export const GET_PHOTOGALARY_REQUEST = 'GET_PHOTOGALARY_REQUEST';
+export const GET_PHOTOGALARY_REQUEST_SUCCESS = 'GET_PHOTOGALARY_REQUEST_SUCCESS';
+export const GET_PHOTOGALARY_REQUEST_FAIL = 'GET_PHOTOGALARY_REQUEST_FAIL';
 
-export const POST_PHOTOGALARY_REQUEST = "POST_PHOTOGALARY_REQUEST";
-export const POST_PHOTOGALARY_REQUEST_SUCCESS = "POST_PHOTOGALARY_REQUEST_SUCCESS";
-export const POST_PHOTOGALARY_REQUEST_FAIL = "POST_PHOTOGALARY_REQUEST_FAIL";
+export const POST_PHOTOGALARY_REQUEST = 'POST_PHOTOGALARY_REQUEST';
+export const POST_PHOTOGALARY_REQUEST_SUCCESS = 'POST_PHOTOGALARY_REQUEST_SUCCESS';
+export const POST_PHOTOGALARY_REQUEST_FAIL = 'POST_PHOTOGALARY_REQUEST_FAIL';
 
-export const PUT_PHOTOGALARY_REQUEST = "PUT_PHOTOGALARY_REQUEST";
-export const PUT_PHOTOGALARY_REQUEST_SUCCESS = "PUT_PHOTOGALARY_REQUEST_SUCCESS";
-export const PUT_PHOTOGALARY_REQUEST_FAIL = "PUT_PHOTOGALARY_REQUEST_FAIL";
+export const PUT_PHOTOGALARY_REQUEST = 'PUT_PHOTOGALARY_REQUEST';
+export const PUT_PHOTOGALARY_REQUEST_SUCCESS = 'PUT_PHOTOGALARY_REQUEST_SUCCESS';
+export const PUT_PHOTOGALARY_REQUEST_FAIL = 'PUT_PHOTOGALARY_REQUEST_FAIL';
 
-export const POST_REGISTRATION_EVENT = "POST_REGISTRATION_EVENT";
-export const POST_REGISTRATION_EVENT_SUCCESS = "POST_REGISTRATION_EVENT_SUCCESS";
-export const POST_REGISTRATION_EVENT_ERROR = "POST_REGISTRATION_EVENT_ERROR";
+export const POST_REGISTRATION_EVENT = 'POST_REGISTRATION_EVENT';
+export const POST_REGISTRATION_EVENT_SUCCESS = 'POST_REGISTRATION_EVENT_SUCCESS';
+export const POST_REGISTRATION_EVENT_ERROR = 'POST_REGISTRATION_EVENT_ERROR';
 
-export const GET_LOGOUT_USER = "GET_LOGOUT_USER";
-export const GET_LOGOUT_USER_SUCCESS = "GET_LOGOUT_USER_SUCCESS";
-export const GET_LOGOUT_USER_ERROR = "GET_LOGOUT_USER_ERROR";
+export const GET_LOGOUT_USER = 'GET_LOGOUT_USER';
+export const GET_LOGOUT_USER_SUCCESS = 'GET_LOGOUT_USER_SUCCESS';
+export const GET_LOGOUT_USER_ERROR = 'GET_LOGOUT_USER_ERROR';
 
-export const GET_REQUEST_EVENT_CARD = "GET_REQUEST_EVENT_CARD";
-export const GET_REQUEST_SUCCESS_EVENT_CARD = "GET_REQUEST_SUCCESS_EVENT_CARD";
-export const GET_REQUEST_ERROR_EVENT_CARD = "GET_REQUEST_ERROR_EVENT_CARD";
+export const GET_REQUEST_EVENT_CARD = 'GET_REQUEST_EVENT_CARD';
+export const GET_REQUEST_SUCCESS_EVENT_CARD = 'GET_REQUEST_SUCCESS_EVENT_CARD';
+export const GET_REQUEST_ERROR_EVENT_CARD = 'GET_REQUEST_ERROR_EVENT_CARD';
 
-export const GET_REQUEST_REVIEWS = "GET_REQUEST_REVIEWS";
-export const GET_REQUEST_SUCCESS_REVIEWS = "GET_REQUEST_SUCCESS_REVIEWS";
-export const GET_REQUEST_ERROR_REVIEWS = "GET_REQUEST_ERROR_REVIEWS";
+export const GET_REQUEST_REVIEWS = 'GET_REQUEST_REVIEWS';
+export const GET_REQUEST_SUCCESS_REVIEWS = 'GET_REQUEST_SUCCESS_REVIEWS';
+export const GET_REQUEST_ERROR_REVIEWS = 'GET_REQUEST_ERROR_REVIEWS';
 
-export const POST_REQUEST_REVIEW = "POST_REQUEST_REVIEW";
-export const POST_REQUEST_SUCCESS_REVIEW = "POST_REQUEST_SUCCESS_REVIEW";
-export const POST_REQUEST_ERROR_REVIEW = "POST_REQUEST_ERROR_REVIEW";
+export const POST_REQUEST_REVIEW = 'POST_REQUEST_REVIEW';
+export const POST_REQUEST_SUCCESS_REVIEW = 'POST_REQUEST_SUCCESS_REVIEW';
+export const POST_REQUEST_ERROR_REVIEW = 'POST_REQUEST_ERROR_REVIEW';
 
-export const GET_EVENT_BY_TITLE = "GET_EVENT_BY_TITLE";
-export const GET_EVENT_BY_TITLE_SUCCESS = "GET_EVENT_BY_TITLE_SUCCESS";
-export const GET_EVENT_BY_TITLE_FAIL = "GET_EVENT_BY_TITLE_FAIL";
+export const GET_EVENT_BY_TITLE = 'GET_EVENT_BY_TITLE';
+export const GET_EVENT_BY_TITLE_SUCCESS = 'GET_EVENT_BY_TITLE_SUCCESS';
+export const GET_EVENT_BY_TITLE_FAIL = 'GET_EVENT_BY_TITLE_FAIL';
 
-export const GET_REGISTRED_USERS = "GET_REGISTRED_USERS";
-export const GET_REGISTRED_USERS_SUCCESS = "GET_REGISTRED_USERS_SUCCESS";
-export const GET_REGISTRED_USERS_FAIL = "GET_REGISTRED_USERS_FAIL";
+export const GET_REGISTRED_USERS = 'GET_REGISTRED_USERS';
+export const GET_REGISTRED_USERS_SUCCESS = 'GET_REGISTRED_USERS_SUCCESS';
+export const GET_REGISTRED_USERS_FAIL = 'GET_REGISTRED_USERS_FAIL';
 
-export const GET_USERS_INFO = "GET_USERS_INFO";
-export const GET_USERS_INFO_SUCCESS = "GET_USERS_INFO_SUCCESS";
-export const GET_USERS_INFO_ERROR = "GET_USERS_INFO_ERROR";
+export const GET_USERS_INFO = 'GET_USERS_INFO';
+export const GET_USERS_INFO_SUCCESS = 'GET_USERS_INFO_SUCCESS';
+export const GET_USERS_INFO_ERROR = 'GET_USERS_INFO_ERROR';
 
-export const POST_RESULTS_REQUEST = "POST_RESULTS_REQUEST";
-export const POST_RESULTS_REQUEST_SUCCESS = "POST_RESULTS_REQUEST_SUCCESS";
-export const POST_RESULTS_REQUEST_FAIL = "POST_RESULTS_REQUEST_FAIL";
+export const POST_RESULTS_REQUEST = 'POST_RESULTS_REQUEST';
+export const POST_RESULTS_REQUEST_SUCCESS = 'POST_RESULTS_REQUEST_SUCCESS';
+export const POST_RESULTS_REQUEST_FAIL = 'POST_RESULTS_REQUEST_FAIL';
 
-export const GET_PHOTOGALARU_EVENTS_REQUEST = "GET_PHOTOGALARU_EVENTS_REQUEST";
-export const GET_PHOTOGALARU_EVENTS_REQUEST_SUCCESS = "GET_PHOTOGALARU_EVENTS_REQUEST_SUCCESS";
-export const GET_PHOTOGALARU_EVENTS_REQUEST_FAIL = "GET_PHOTOGALARU_EVENTS_REQUEST_FAIL";
+export const GET_PHOTOGALARU_EVENTS_REQUEST = 'GET_PHOTOGALARU_EVENTS_REQUEST';
+export const GET_PHOTOGALARU_EVENTS_REQUEST_SUCCESS = 'GET_PHOTOGALARU_EVENTS_REQUEST_SUCCESS';
+export const GET_PHOTOGALARU_EVENTS_REQUEST_FAIL = 'GET_PHOTOGALARU_EVENTS_REQUEST_FAIL';
 
-export const GET_RESULT = "GET_RESULT";
-export const GET_RESULT_SUCCESS = "GET_RESULT_SUCCESS";
-export const GET_RESULT_ERROR = "GET_RESULT_ERROR";
+export const GET_RESULT = 'GET_RESULT';
+export const GET_RESULT_SUCCESS = 'GET_RESULT_SUCCESS';
+export const GET_RESULT_ERROR = 'GET_RESULT_ERROR';
+
+export const CHANGE_EDIT_FLAG = 'CHANGE_EDIT_FLAG';

+ 46 - 39
src/actions/adminMainPageActions.js

@@ -1,36 +1,43 @@
-import axios from "axios";
-import * as types from "../actionTypes/actionTypes"
+import axios from 'axios';
+import * as types from '../actionTypes/actionTypes';
 
-const eventURL = 'https://api-marathon.herokuapp.com/api/v1/event'
+const eventURL = 'https://api-marathon.herokuapp.com/api/v1/event';
 
-export const editEvent = payload => {
+export const editEvent = (payload) => {
 	return {
 		type: types.EDIT_EVENT,
 		payload
 	};
 };
 
+export const changeEditFlag = (payload) => {
+	return {
+		type: types.CHANGE_EDIT_FLAG,
+		payload
+	};
+};
+
 //POST
-const postNewEventRequest = payload => ({
+const postNewEventRequest = (payload) => ({
 	type: types.POST_NEW_EVENT_REQUEST,
 	payload
 });
-const postNewEventRequestSuccess = payload => ({
+const postNewEventRequestSuccess = (payload) => ({
 	type: types.POST_NEW_EVENT_REQUEST_SUCCESS,
 	payload
 });
-const postNewEventRequestFail = payload => ({
+const postNewEventRequestFail = (payload) => ({
 	type: types.POST_NEW_EVENT_REQUEST_FAIL,
 	payload
 });
 
-export const postNewEvent = payload => {
-	return async dispatch => {
+export const postNewEvent = (payload) => {
+	return async (dispatch) => {
 		dispatch(postNewEventRequest());
 		try {
 			const { data } = await axios.post(eventURL, payload);
 			dispatch(postNewEventRequestSuccess(data));
-			console.log("New Event Posted", payload)
+			console.log('New Event Posted', payload);
 		} catch (error) {
 			dispatch(postNewEventRequestFail(error));
 		}
@@ -38,102 +45,102 @@ export const postNewEvent = payload => {
 };
 
 //PUT
-const editEventRequest = payload => ({
+const editEventRequest = (payload) => ({
 	type: types.EDIT_EVENT_REQUEST,
 	payload
 });
-const editEventRequestSuccess = payload => ({
+const editEventRequestSuccess = (payload) => ({
 	type: types.EDIT_EVENT_REQUEST_SUCCESS,
 	payload
 });
-const editEventRequestFail = payload => ({
+const editEventRequestFail = (payload) => ({
 	type: types.EDIT_EVENT_REQUEST_FAIL,
 	payload
 });
 
 export const changeEvent = (payload) => {
-	return async dispatch => {
+	return async (dispatch) => {
 		dispatch(editEventRequest());
 		try {
 			await axios.put(`${eventURL}/${payload._id} `, payload);
-			dispatch(editEventRequestSuccess({payload, id: payload._id}));
-			console.log("Event Changed", payload)
+			dispatch(editEventRequestSuccess({ payload, id: payload._id }));
+			console.log('Event Changed', payload);
 		} catch (error) {
-			console.log('edit payload',payload)
+			console.log('edit payload', payload);
 			dispatch(editEventRequestFail(error));
 		}
 	};
 };
 
 //GET
-const getEventsRequest = payload => ({
+const getEventsRequest = (payload) => ({
 	type: types.GET_EVENTS_REQUEST,
 	payload
 });
 
-const getEventsRequestSuccess = payload => ({
+const getEventsRequestSuccess = (payload) => ({
 	type: types.GET_EVENTS_REQUEST_SUCCESS,
 	payload
 });
 
-const getEventsRequestFail = payload => ({
+const getEventsRequestFail = (payload) => ({
 	type: types.GET_EVENTS_REQUEST_FAIL,
 	payload
 });
 
-export const getEvents = (type = 'Select Event Type') => dispatch => {
+export const getEvents = (type = 'Select Event Type') => (dispatch) => {
 	dispatch(getEventsRequest());
 	return axios
-		.get( type !== 'Select Event Type' ? `${eventURL}/?eventType=${type}` : eventURL)
-		.then(res => dispatch(getEventsRequestSuccess(res)))
-		.catch(err => dispatch(getEventsRequestFail(err)));
+		.get(type !== 'Select Event Type' ? `${eventURL}/?eventType=${type}` : eventURL)
+		.then((res) => dispatch(getEventsRequestSuccess(res)))
+		.catch((err) => dispatch(getEventsRequestFail(err)));
 };
 
-//GET BY TITLE 
+//GET BY TITLE
 
-const getEventByTitleRequest = payload => ({
+const getEventByTitleRequest = (payload) => ({
 	type: types.GET_EVENT_BY_TITLE,
 	payload
 });
 
-const getEventByTitleRequestSuccess = payload => ({
+const getEventByTitleRequestSuccess = (payload) => ({
 	type: types.GET_EVENT_BY_TITLE_SUCCESS,
 	payload
 });
 
-const getEventByTitleRequestFail = payload => ({
+const getEventByTitleRequestFail = (payload) => ({
 	type: types.GET_EVENT_BY_TITLE_FAIL,
 	payload
 });
 
-export const getEventByTitle = (title) => dispatch => {
+export const getEventByTitle = (title) => (dispatch) => {
 	dispatch(getEventByTitleRequest());
 	return axios
-		.get( title && `${eventURL}/?title=${title}`)
-		.then(res => dispatch(getEventByTitleRequestSuccess(res)))
-		.catch(err => dispatch(getEventByTitleRequestFail(err)));
+		.get(title && `${eventURL}/?title=${title}`)
+		.then((res) => dispatch(getEventByTitleRequestSuccess(res)))
+		.catch((err) => dispatch(getEventByTitleRequestFail(err)));
 };
 
 // REMOVE
-const removeEventRequest = payload => ({
+const removeEventRequest = (payload) => ({
 	type: types.REMOVE_EVENT_REQUEST,
 	payload
 });
 
-const removeEventSuccess = payload => ({
+const removeEventSuccess = (payload) => ({
 	type: types.REMOVE_EVENT_REQUEST_SUCCESS,
 	payload
 });
 
-const removeEventFail = payload => ({
+const removeEventFail = (payload) => ({
 	type: types.REMOVE_EVENT_REQUEST_FAIL,
 	payload
 });
 
-export const removeEvent = _id => dispatch => {
+export const removeEvent = (_id) => (dispatch) => {
 	dispatch(removeEventRequest());
 	return axios
 		.delete(`${eventURL}/${_id}`)
-		.then(res => dispatch(removeEventSuccess({ res, _id })))
-		.catch(err => dispatch(removeEventFail(err)));
-};
+		.then((res) => dispatch(removeEventSuccess({ res, _id })))
+		.catch((err) => dispatch(removeEventFail(err)));
+};

+ 24 - 16
src/components/adminHeader/adminHeader.js

@@ -1,14 +1,17 @@
-import React from "react";
-import { Link, withRouter } from "react-router-dom";
-import "./adminHeader.scss";
-import { adminMenu } from "../../state/adminMenu";
-
-const adminHeader = props => {
+import React from 'react';
+import { Link, withRouter } from 'react-router-dom';
+import './adminHeader.scss';
+import { adminMenu } from '../../state/adminMenu';
 
+const adminHeader = (props) => {
 	const logout = (e) => {
 		localStorage.removeItem('user');
-		props.history.push('/')
-	}
+		props.history.push('/');
+	};
+
+	const clickEventHandler = (e) => {
+		props.changeEditFlag();
+	};
 
 	return (
 		<header className="header" id="header">
@@ -17,17 +20,22 @@ const adminHeader = props => {
 					<div className="header__logo">
 						<Link to="/admin">
 							Just_<span>tri</span>_it
-                        </Link>
+						</Link>
 					</div>
 				</div>
 				<nav className="header__nav">
 					<ul className="header__list">
-						{adminMenu.map(el =>
-							el.hideWhenAuth && props.user ? null : (
-								<li className="header__item" key={el.id} onClick={el.logout ? logout : null}>
-									<Link to={el.path}>{el.text}</Link>
-								</li>
-							)
+						{adminMenu.map(
+							(el) =>
+								el.hideWhenAuth && props.user ? null : (
+									<li
+										className="header__item"
+										key={el.id}
+										onClick={el.logout ? logout : clickEventHandler}
+									>
+										<Link to={el.path}>{el.text}</Link>
+									</li>
+								)
 						)}
 					</ul>
 				</nav>
@@ -36,4 +44,4 @@ const adminHeader = props => {
 	);
 };
 
-export default withRouter(adminHeader);
+export default withRouter(adminHeader);

+ 27 - 28
src/components/adminMenu/adminMenu.js

@@ -1,35 +1,34 @@
-import React, { Component } from "react";
-import { withRouter } from "react-router-dom";
-import "./adminMenu.scss";
-import { adminMenu } from "../../state/adminMenu";
+import React, { Component } from 'react';
+import { withRouter } from 'react-router-dom';
+import './adminMenu.scss';
+import { adminMenu } from '../../state/adminMenu';
 
 class AdminMenu extends Component {
-    constructor(props) {
-        super(props);
+	constructor(props) {
+		super(props);
 
-        this.state = { adminMenu };
-    }
+		this.state = { adminMenu };
+	}
 
-    clickEventHandler = (e) => {
-        this.props.history.push(e)
-    }
+	clickEventHandler = (e) => {
+		this.props.history.push(e);
+	};
 
-    render() {
-        return (
-            <div className="menu-block">
-                {adminMenu.map(el =>
-                    el.text !== "Log out" && el.text !== "Main Page" &&
-                    <div
-                        className="menu-skew"
-                        key={el.id}
-                        onClick={this.clickEventHandler.bind(null, el.path)}
-                    >
-                        <h2 className="menu-text">{el.text.toUpperCase()}</h2>
-                    </div>
-                )}
-            </div>
-        )
-    }
+	render() {
+		return (
+			<div className="menu-block">
+				{adminMenu.map(
+					(el) =>
+						el.text !== 'Log out' &&
+						el.text !== 'Main Page' && (
+							<div className="menu-skew" key={el.id} onClick={this.clickEventHandler.bind(null, el.path)}>
+								<h2 className="menu-text">{el.text.toUpperCase()}</h2>
+							</div>
+						)
+				)}
+			</div>
+		);
+	}
 }
 
-export default withRouter(AdminMenu)
+export default withRouter(AdminMenu);

+ 147 - 147
src/components/adminPhotogalary/adminPhotogalaryReduxForm.js

@@ -1,151 +1,151 @@
-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 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';
 
 class PhotogalaryReduxForm extends Component {
-
-    state = {
-        addPhotogalaryInitialValue,
-        filteredEventList: []
-    }
-
-    submit = values => {
-        const pictures = this.state.addPhotogalaryInitialValue.pictures.reduce((prev, elem) => {
-            return prev.concat(elem.value);
-        }, []);
-
-        const submitValues = {
-            ...this.state.addPhotogalaryInitialValue,
-            pictures: pictures,
-        }
-
-        this.props.submitHandler(submitValues);
-        this.props.reset()
-    };
-
-    onChangeTypeHandler = e => {
-        const { name, value } = e.target;
-
-        this.setState(prevState => {
-            return {
-                ...prevState,
-                addPhotogalaryInitialValue: {
-                    ...prevState.addPhotogalaryInitialValue,
-                    [name]: value
-                },
-                filteredEventList: [{_id: 1, title: "Select event"}].concat(
-                    this.props.eventList.filter(el => el.eventType === value)
-                )
-            };
-        });
-    };
-
-    onChangeTitleHandler = e => {
-        const { name, value } = e.target;
-
-        this.setState(prevState => {
-            return {
-                ...prevState,
-                addPhotogalaryInitialValue: {
-                    ...prevState.addPhotogalaryInitialValue,
-                    [name]: value
-                }
-            };
-        });
-    };
-
-    onChangePicturesHandler = e => {
-        const { value, id } = e.target;
-
-        this.setState(prevState => {
-            return {
-                ...prevState,
-                addPhotogalaryInitialValue: {
-                    ...prevState.addPhotogalaryInitialValue,
-                    pictures: prevState.addPhotogalaryInitialValue.pictures.map(
-                        el => (el.id === id ? { ...el, value } : el)
-                    )
-                }
-            };
-        });
-    };
-
-    addPicture = (e) => {
-        this.setState(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 { filteredEventList, addPhotogalaryInitialValue } = this.state;
-
-        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.onChangeTypeHandler}
-                    className="form-block__select -wide"
-                >
-                    {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}
-                    className="form-block__select -wide"
-                >
-                    {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>
-
-        );
-    }
+	state = {
+		addPhotogalaryInitialValue,
+		filteredEventList: []
+	};
+
+	submit = (values) => {
+		const pictures = this.state.addPhotogalaryInitialValue.pictures.reduce((prev, elem) => {
+			return prev.concat(elem.value);
+		}, []);
+
+		const submitValues = {
+			...this.state.addPhotogalaryInitialValue,
+			pictures: pictures
+		};
+
+		this.props.submitHandler(submitValues);
+		this.props.reset();
+	};
+
+	onChangeTypeHandler = (e) => {
+		const { name, value } = e.target;
+
+		this.setState((prevState) => {
+			return {
+				...prevState,
+				addPhotogalaryInitialValue: {
+					...prevState.addPhotogalaryInitialValue,
+					[name]: value
+				},
+				filteredEventList: [ { _id: 1, title: 'Select event' } ].concat(
+					this.props.eventList.filter((el) => el.eventType === value)
+				)
+			};
+		});
+	};
+
+	onChangeTitleHandler = (e) => {
+		const { name, value } = e.target;
+
+		this.setState((prevState) => {
+			return {
+				...prevState,
+				addPhotogalaryInitialValue: {
+					...prevState.addPhotogalaryInitialValue,
+					[name]: value
+				}
+			};
+		});
+	};
+
+	onChangePicturesHandler = (e) => {
+		const { value, id } = e.target;
+
+		this.setState((prevState) => {
+			return {
+				...prevState,
+				addPhotogalaryInitialValue: {
+					...prevState.addPhotogalaryInitialValue,
+					pictures: prevState.addPhotogalaryInitialValue.pictures.map(
+						(el) => (el.id === id ? { ...el, value } : el)
+					)
+				}
+			};
+		});
+	};
+
+	addPicture = (e) => {
+		this.setState((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 { filteredEventList, addPhotogalaryInitialValue } = this.state;
+
+		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.onChangeTypeHandler}
+					className="form-block__select -wide"
+				>
+					{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}
+					className="form-block__select -wide"
+				>
+					{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>
+		);
+	}
 }
 
-export default reduxForm({ form: "photogalaryForm", enableReinitialize: true })(PhotogalaryReduxForm);
+export default reduxForm({ form: 'photogalaryForm', enableReinitialize: true })(PhotogalaryReduxForm);

+ 90 - 54
src/components/eventForm/eventReduxForm.js

@@ -1,63 +1,99 @@
-import React from "react";
-import { reduxForm, Field } from "redux-form";
-import "./eventForm.scss";
-import { customInput } from "../customFields/customInput/customInput";
-import { customTextarea } from "../customFields/customTextarea/customTextarea";
-import { customSelect } from "../customFields/customSelect/customSelect";
-import { eventFormValidation } from "../../utils/eventFormValidation";
+import React from 'react';
+import { reduxForm, Field } from 'redux-form';
+import { withRouter } from 'react-router-dom';
+import './eventForm.scss';
+import { customInput } from '../customFields/customInput/customInput';
+import { customTextarea } from '../customFields/customTextarea/customTextarea';
+import { customSelect } from '../customFields/customSelect/customSelect';
+import { eventFormValidation } from '../../utils/eventFormValidation';
 
 const EventReduxForm = ({
-    handleSubmit,
-    postNewEvent,
-    showConfirmationMessage,
-    reset,
-    eventTypes,
-    initialValues,
-    editFormFlag,
-    changeEvent
+	handleSubmit,
+	postNewEvent,
+	showConfirmationMessage,
+	reset,
+	eventTypes,
+	initialValues,
+	editFormFlag,
+	changeEvent,
+	history
 }) => {
-
-    const submit = value => {
+	const submit = (value) => {
 		if (!editFormFlag) {
-            postNewEvent(value)
+			postNewEvent(value);
 		} else {
-            changeEvent(value);
+			changeEvent(value);
+			setTimeout(() => history.push('/admin/my_events'), 3000);
 		}
-        reset();
-        showConfirmationMessage();
-    };
-
-    return (
-        <form className="event-form__event-form__main" onSubmit={handleSubmit(submit)}>
+		reset();
+		showConfirmationMessage();
+	};
 
-            <img className="event-form__picture" alt="Event Bunner" src={initialValues.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} >
-                {eventTypes.map(elem => <option key={elem.id} value={elem.optionName}>{elem.optionName}</option>)}
-            </Field>
-            <Field name="eventDate" type="date" label="Event Date" required component={customInput} />
-            <Field name="country" label="Country" required component={customInput} />
-            <Field name="city" label="City" required component={customInput} />
-            <Field name="overview" label="Overview" rows="10" placeholder='Enter event overview' component={customTextarea} />
-            <Field name="contentPicture" label="Content Picture" className="input-box -wide" placeholder='Enter picture url' component={customInput} />
-            <Field name="contentVideo" label="Content Video" className="input-box -wide" placeholder='Enter video url' component={customInput} />
-            <Field name="marathoneDistancePrice" label="Marathone Distance Price" component={customInput} />
-            <Field name="halfmarathoneDistancePrice" label="Halfmarathone Distance Price" component={customInput} />
-            <Field name="ageLimit" label="Age Limit" component={customTextarea} />
-            <Field name="awardMedals" label="Award Medals" component={customTextarea} />
-            <Field name="maximumTime" label="Maximum Time" component={customTextarea} />
-            <Field name="aidStations" label="Aid Stations" component={customTextarea} />
-            <Field name="equipmentStorage" label="Equipment Storage" component={customTextarea} />
-            <Field name="parking" label="Parking" component={customTextarea} />
-            <Field name="refreshments" label="Refreshments" component={customTextarea} />
-            <Field name="map" label="Map" className="input-box -wide" placeholder='Enter picture url' component={customInput} />
+	return (
+		<form className="event-form__event-form__main" onSubmit={handleSubmit(submit)}>
+			<img className="event-form__picture" alt="Event Bunner" src={initialValues.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}>
+				{eventTypes.map((elem) => (
+					<option key={elem.id} value={elem.optionName}>
+						{elem.optionName}
+					</option>
+				))}
+			</Field>
+			<Field name="eventDate" type="date" label="Event Date" required component={customInput} />
+			<Field name="country" label="Country" required component={customInput} />
+			<Field name="city" label="City" required component={customInput} />
+			<Field
+				name="overview"
+				label="Overview"
+				rows="10"
+				placeholder="Enter event overview"
+				component={customTextarea}
+			/>
+			<Field
+				name="contentPicture"
+				label="Content Picture"
+				className="input-box -wide"
+				placeholder="Enter picture url"
+				component={customInput}
+			/>
+			<Field
+				name="contentVideo"
+				label="Content Video"
+				className="input-box -wide"
+				placeholder="Enter video url"
+				component={customInput}
+			/>
+			<Field name="marathoneDistancePrice" label="Marathone Distance Price" component={customInput} />
+			<Field name="halfmarathoneDistancePrice" label="Halfmarathone Distance Price" component={customInput} />
+			<Field name="ageLimit" label="Age Limit" component={customTextarea} />
+			<Field name="awardMedals" label="Award Medals" component={customTextarea} />
+			<Field name="maximumTime" label="Maximum Time" component={customTextarea} />
+			<Field name="aidStations" label="Aid Stations" component={customTextarea} />
+			<Field name="equipmentStorage" label="Equipment Storage" component={customTextarea} />
+			<Field name="parking" label="Parking" component={customTextarea} />
+			<Field name="refreshments" label="Refreshments" component={customTextarea} />
+			<Field
+				name="map"
+				label="Map"
+				className="input-box -wide"
+				placeholder="Enter picture url"
+				component={customInput}
+			/>
 
-            <div className="event-form__control-box">
-                <button className="event-form__submit-btn">{editFormFlag ? 'Save Changes' : 'Add Event'}</button>
-            </div>
-        </form>
-    );
-}
+			<div className="event-form__control-box">
+				<button className="event-form__submit-btn">{editFormFlag ? 'Save Changes' : 'Add Event'}</button>
+			</div>
+		</form>
+	);
+};
 
-export default reduxForm({ form: "eventForm", validate: eventFormValidation, enableReinitialize: true })(EventReduxForm);
+export default withRouter(
+	reduxForm({ form: 'eventForm', validate: eventFormValidation, enableReinitialize: true })(EventReduxForm)
+);

+ 2 - 2
src/conteiners/adminAddEventPage/adminAddEventPage.js

@@ -33,7 +33,7 @@ class AdminAddEventPage extends Component {
 
         return (
             <>
-                <AdminHeader />
+                <AdminHeader changeEditFlag={this.props.changeEditFlag}/>
                 <div className="event-form">
                     <div className="event-form__content">
                         <h2 className="event-form__form-title">{editFormFlag ? 'CHANGE EVENT' : 'ADD NEW EVENT'}</h2>
@@ -51,7 +51,7 @@ class AdminAddEventPage extends Component {
 
                 {this.state.confirmationMessageFlag &&
                     <ConfirmationMessage closeMessage={this.closeConfirmationMessage}>
-                        <div className="text">{editFormFlag ? `Event has been changed.` : `New event has beed added.`}</div>
+                        <div className="text">Event has been saved</div>
                     </ConfirmationMessage >}
             </>
         );

+ 14 - 16
src/conteiners/adminMainPage/adminMainPage.js

@@ -1,24 +1,22 @@
 import React, { Component } from 'react';
-import { connect } from "react-redux";
-import "./adminMainPage.scss";
+import { connect } from 'react-redux';
+import './adminMainPage.scss';
+import * as actions from '../../actions/adminMainPageActions';
 import Header from '../../components/adminHeader/adminHeader';
 import AdminMenu from '../../components/adminMenu/adminMenu';
 
 class AdminMainPage extends Component {
-
-  render() {
-
-    return (
-      <div className="admin-main-page-wrapper">
-        <Header />
-        <AdminMenu />
-      </div>
-    )
-  }
+	render() {
+		console.log('main', this.props);
+		return (
+			<div className="admin-main-page-wrapper">
+				<Header changeEditFlag={this.props.changeEditFlag} />
+				<AdminMenu />
+			</div>
+		);
+	}
 }
 
-const mapStateToProps = state => ({
-
-});
+const mapStateToProps = (state) => ({});
 
-export default connect(mapStateToProps)(AdminMainPage);
+export default connect(mapStateToProps, actions)(AdminMainPage);

+ 2 - 2
src/conteiners/adminMyEventsPage/adminMyEventsPage.js

@@ -33,7 +33,7 @@ class AdminAddEventPage extends Component {
 
         return (
             <>
-                <AdminHeader />
+                <AdminHeader changeEditFlag={this.props.changeEditFlag}/>
                 <div className="event-page">
                     <div className="event-page__content">
                         <h2 className="event-page__title">MY EVENTS</h2>
@@ -65,7 +65,7 @@ class AdminAddEventPage extends Component {
                             )}
                         </div>
 
-                        {editFormFlag && <Redirect to='/admin/add_new_event' />}
+                        {editFormFlag && <Redirect to='/admin/event' />}
                     </div>
                 </div>
             </>

+ 1 - 1
src/conteiners/adminPhotogalaryPage/adminPhotogalaryPage.js

@@ -32,7 +32,7 @@ class AdminAddPhotogalarytPage extends Component {
 
         return (
             <>
-                <AdminHeader />
+                <AdminHeader changeEditFlag={this.props.changeEditFlag}/>
                 <div className="photogalary-form">
                     <div className="photogalary-form__content">
                         <h2 className="photogalary-form__form-title">ADD PHOTOGALARY</h2>

+ 3 - 3
src/conteiners/adminResultsPage/adminResultsPage.js

@@ -1,6 +1,6 @@
 import React, { Component } from "react";
 import { connect } from "react-redux";
-import { getEvents, getEventByTitle } from "../../actions/adminMainPageActions";
+import { getEvents, getEventByTitle, changeEditFlag } from "../../actions/adminMainPageActions";
 import { getRegistredUsers, resultsPromiseAll } from "../../actions/adminResultsActions";
 import AdminHeader from "../../components/adminHeader/adminHeader";
 import ResultsForm from "../../components/adminResults/adminResultsForm";
@@ -55,7 +55,7 @@ class AdminResultstPage extends Component {
 
         return (
             <>
-                <AdminHeader />
+                <AdminHeader changeEditFlag={this.props.changeEditFlag}/>
                 <div className="results-form">
                     <div className="results-form__content">
                         <h2 className="results-form__form-title">RESULTS</h2>
@@ -90,5 +90,5 @@ const mapStateToProps = state => ({
 
 export default connect(
     mapStateToProps,
-    { getEvents, getEventByTitle, getRegistredUsers, resultsPromiseAll }
+    { getEvents, getEventByTitle, getRegistredUsers, resultsPromiseAll, changeEditFlag }
 )(AdminResultstPage);

+ 32 - 29
src/reducers/adminMainPageReducer.js

@@ -1,13 +1,10 @@
-import * as types from "../actionTypes/actionTypes"
-import initialState from "../state/addEventInitialValue";
-
+import * as types from '../actionTypes/actionTypes';
+import initialState from '../state/addEventInitialValue';
 
 export default (state = initialState, action) => {
-
 	switch (action.type) {
-
 		case types.EDIT_EVENT: {
-			const eventFormInitialValue = state.eventList.find(el => el._id === action.payload);
+			const eventFormInitialValue = state.eventList.find((el) => el._id === action.payload);
 			return {
 				...state,
 				eventFormInitialValue: eventFormInitialValue,
@@ -15,32 +12,39 @@ export default (state = initialState, action) => {
 			};
 		}
 
+		case types.CHANGE_EDIT_FLAG: {
+			return {
+				...state,
+				eventFormInitialValue: initialState.eventFormInitialValue,
+				editFormFlag: false
+			};
+		}
+
 		//POST
 		case types.POST_NEW_EVENT_REQUEST_SUCCESS: {
-			console.log('reducer add event success', action.payload)
+			console.log('reducer add event success', action.payload);
 			return {
 				...state,
-				addEventMessage: "New event has been added"
-			}
+				addEventMessage: 'New event has been added'
+			};
 		}
 		case types.POST_NEW_EVENT_REQUEST_FAIL: {
-			console.log('reducer add event fail', action.payload)
-			return { ...state, error: action.payload }
+			console.log('reducer add event fail', action.payload);
+			return { ...state, error: action.payload };
 		}
 
 		//PUT
 		case types.EDIT_EVENT_REQUEST_SUCCESS: {
-			console.log('reducer edit event success', action.payload)
+			console.log('reducer edit event success', action.payload);
 			return {
 				...state,
-				addEventMessage: "Event has been changed",
-				// eventFormInitialValue: eventFormInitialValue,
-				// editFormFlag: false
-			}
+				eventFormInitialValue: initialState.eventFormInitialValue,
+				editFormFlag: false
+			};
 		}
 		case types.EDIT_EVENT_REQUEST_FAIL: {
-			console.log('reducer edit event fail', action.payload)
-			return { ...state, error: action.payload }
+			console.log('reducer edit event fail', action.payload);
+			return { ...state, error: action.payload };
 		}
 
 		// GET ALL EVENTS
@@ -48,26 +52,25 @@ export default (state = initialState, action) => {
 			return state;
 		}
 		case types.GET_EVENTS_REQUEST_SUCCESS: {
-			const { data } = action.payload;			
-			const eventList = data.events.map( event => ({
-					...event,
-					eventDate: new Date(event.eventDate).toDateString().split(' ').slice(1,4)
-				})
-			)
+			const { data } = action.payload;
+			const eventList = data.events.map((event) => ({
+				...event,
+				eventDate: new Date(event.eventDate).toDateString().split(' ').slice(1, 4)
+			}));
 			return { ...state, eventList };
 		}
 		case types.GET_EVENTS_REQUEST_FAIL: {
 			return state;
 		}
 
-		// GET EVENT BY TITLE 
+		// GET EVENT BY TITLE
 		case types.GET_EVENT_BY_TITLE: {
 			return state;
 		}
 		case types.GET_EVENT_BY_TITLE_SUCCESS: {
 			const { data } = action.payload;
-			console.log('reducer data eventByTitle', data)
-			const eventByTitle = data
+			console.log('reducer data eventByTitle', data);
+			const eventByTitle = data;
 			return { ...state, eventByTitle };
 		}
 		case types.GET_EVENT_BY_TITLE_FAIL: {
@@ -82,7 +85,7 @@ export default (state = initialState, action) => {
 			const { _id } = action.payload;
 			return {
 				...state,
-				eventList: state.eventList.filter(el => el._id !== _id)
+				eventList: state.eventList.filter((el) => el._id !== _id)
 			};
 		}
 
@@ -93,4 +96,4 @@ export default (state = initialState, action) => {
 		default:
 			return state;
 	}
-}
+};

+ 37 - 36
src/router.js

@@ -1,13 +1,13 @@
-import React, { useEffect } from "react";
-import { Switch, withRouter } from "react-router-dom";
-import { connect } from "react-redux";
-import { PrivateRoute } from "./private-router";
+import React, { useEffect } from 'react';
+import { Switch, withRouter } from 'react-router-dom';
+import { connect } from 'react-redux';
+import { PrivateRoute } from './private-router';
 
 import AdminMainPage from './conteiners/adminMainPage/adminMainPage';
 import AdminAddEventPage from './conteiners/adminAddEventPage/adminAddEventPage';
 import AdminMyEventsPage from './conteiners/adminMyEventsPage/adminMyEventsPage';
-import AdminAddPhotogalarytPage from "./conteiners/adminPhotogalaryPage/adminPhotogalaryPage"
-import AdminResultsPage from "./conteiners/adminResultsPage/adminResultsPage"
+import AdminAddPhotogalarytPage from './conteiners/adminPhotogalaryPage/adminPhotogalaryPage';
+import AdminResultsPage from './conteiners/adminResultsPage/adminResultsPage';
 
 import Home from './conteiners/home/Home';
 import Result from './conteiners/result/Result';
@@ -25,63 +25,63 @@ const route = [
 	{
 		id: 1,
 		exact: true,
-		path: "/",
+		path: '/',
 		protected: false,
 		component: Home
 	},
 	{
 		id: 2,
 		exact: true,
-		path: "/events",
+		path: '/events',
 		protected: false,
 		component: Events
 	},
 	{
 		id: 3,
 		exact: true,
-		path: "/events/:id",
+		path: '/events/:id',
 		protected: false,
 		component: EventCard
 	},
 	{
 		id: 4,
 		exact: true,
-		path: "/results",
+		path: '/results',
 		protected: false,
 		component: Result
 	},
 	{
 		id: 5,
 		exact: true,
-		path: "/gallery",
+		path: '/gallery',
 		protected: false,
 		component: Gallery
 	},
 	{
 		id: 6,
 		exact: true,
-		path: "/reviews",
+		path: '/reviews',
 		protected: false,
 		component: Reviews
 	},
 	{
 		id: 7,
 		exact: true,
-		path: "/login",
+		path: '/login',
 		protected: false,
 		component: Login
 	},
 	{
 		id: 8,
 		exact: true,
-		path: "/registration",
+		path: '/registration',
 		protected: false,
 		component: RegistrationPage
 	},
 	{
 		id: 9,
 		exact: true,
-		path: "/profile",
+		path: '/profile',
 		protected: true,
 		hasAccess: 'user',
 		component: Profile
@@ -89,7 +89,7 @@ const route = [
 	{
 		id: 10,
 		exact: true,
-		path: "/admin",
+		path: '/admin',
 		protected: true,
 		hasAccess: 'admin',
 		component: AdminMainPage
@@ -97,7 +97,7 @@ const route = [
 	{
 		id: 11,
 		exact: true,
-		path: "/admin/add_new_event",
+		path: '/admin/event',
 		protected: true,
 		hasAccess: 'admin',
 		component: AdminAddEventPage
@@ -105,7 +105,7 @@ const route = [
 	{
 		id: 12,
 		exact: true,
-		path: "/admin/photogalary",
+		path: '/admin/photogalary',
 		protected: true,
 		hasAccess: 'admin',
 		component: AdminAddPhotogalarytPage
@@ -113,7 +113,7 @@ const route = [
 	{
 		id: 13,
 		exact: true,
-		path: "/admin/results",
+		path: '/admin/results',
 		protected: true,
 		hasAccess: 'admin',
 		component: AdminResultsPage
@@ -121,7 +121,7 @@ const route = [
 	{
 		id: 14,
 		exact: true,
-		path: "/admin/my_events",
+		path: '/admin/my_events',
 		protected: true,
 		hasAccess: 'admin',
 		component: AdminMyEventsPage
@@ -133,26 +133,29 @@ const route = [
 ];
 
 const Router = withRouter(({ history, user }) => {
-	useEffect(() => {
-		const userl = localStorage.user ? JSON.parse(localStorage.user).user : null;
+	useEffect(
+		() => {
+			const userl = localStorage.user ? JSON.parse(localStorage.user).user : null;
 
-		if (userl) {
-			const userRole = userl.role;
+			if (userl) {
+				const userRole = userl.role;
 
-			if (userRole === 'admin') {
-				history.push("/admin");
-			}
+				if (userRole === 'admin') {
+					history.push('/admin');
+				}
 
-			if (userRole === 'user') {
-				history.push("/profile");
+				if (userRole === 'user') {
+					history.push('/profile');
+				}
 			}
-		}
-	}, [history, user]);
+		},
+		[ history, user ]
+	);
 
 	return (
 		<div className="container">
 			<Switch>
-				{route.map(el => (
+				{route.map((el) => (
 					<PrivateRoute
 						protectedRoute={el.protected}
 						key={el.id}
@@ -166,12 +169,10 @@ const Router = withRouter(({ history, user }) => {
 	);
 });
 
-const mapStateToProps = state => {
+const mapStateToProps = (state) => {
 	return {
 		user: state.login.user
 	};
 };
 
-export default connect(
-	mapStateToProps
-)(Router);
+export default connect(mapStateToProps)(Router);

+ 7 - 7
src/state/adminMenu.js

@@ -1,8 +1,8 @@
 export const adminMenu = [
-	{ 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/photogalary", id: 3, text: "Add Photogalery", logout: false },
-	{ path: "/admin/results", id: 4, text: "Add Results", logout: false },
-	{ path: "/", id: 5, text: "Go to WebSite", logout: false },
-	{ path: "/", id: 6, text: "Log out", logout: true }
-];
+	{ path: '/admin/event', id: 1, text: 'Add New Event', logout: false },
+	{ path: '/admin/my_events', id: 2, text: 'My Events', logout: false },
+	{ path: '/admin/photogalary', id: 3, text: 'Add Photogalery', logout: false },
+	{ path: '/admin/results', id: 4, text: 'Add Results', logout: false },
+	{ path: '/', id: 5, text: 'Go to WebSite', logout: false },
+	{ path: '/', id: 6, text: 'Log out', logout: true }
+];