|
@@ -31,7 +31,7 @@ const route = [
|
|
|
path: "/",
|
|
|
protected: false,
|
|
|
component: Home,
|
|
|
- events: true
|
|
|
+ // events: true
|
|
|
},
|
|
|
{
|
|
|
id: 2,
|
|
@@ -121,116 +121,61 @@ const route = [
|
|
|
}
|
|
|
];
|
|
|
|
|
|
-// export const Router = withRouter(({ history }) => {
|
|
|
-
|
|
|
-// const [events, setEvents] = useState([]);
|
|
|
-
|
|
|
-// useEffect(() => {
|
|
|
-// fetch("https://api-marathon.herokuapp.com/api/v1/event")
|
|
|
-// .then(response => response.json())
|
|
|
-// .then(json => setEvents(json));
|
|
|
-// }, []);
|
|
|
-
|
|
|
-// console.log('events', events)
|
|
|
-
|
|
|
-// useEffect(() => {
|
|
|
-// const user = localStorage.getItem("user");
|
|
|
-// if (user) {
|
|
|
-// const userRole = JSON.parse(user).role;
|
|
|
-// if (userRole === 'admin') {
|
|
|
-// history.push("/admin");
|
|
|
-// }
|
|
|
-// if (userRole === 'user') {
|
|
|
-// history.push("/profile");
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }, [history]);
|
|
|
-
|
|
|
-// return (
|
|
|
-// <div className="container">
|
|
|
-// {console.log('events', events)}
|
|
|
-// <Switch>
|
|
|
-// {route.map(el => (
|
|
|
-// <PrivateRoute
|
|
|
-// protectedRoute={el.protected}
|
|
|
-// key={el.id}
|
|
|
-// exact={el.exact}
|
|
|
-// path={el.path}
|
|
|
-// component={el.component}
|
|
|
-// events = {el.events && events}
|
|
|
-// />
|
|
|
-// ))}
|
|
|
+const Router = withRouter(({ history, user }) => {
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ const user = localStorage.getItem("user");
|
|
|
+ if (user) {
|
|
|
+ const userRole = JSON.parse(user).role;
|
|
|
+ if (userRole === 'admin') {
|
|
|
+ history.push("/admin");
|
|
|
+ }
|
|
|
+ if (userRole === 'user') {
|
|
|
+ history.push("/profile");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, [user]);
|
|
|
+
|
|
|
+ console.log('user', user)
|
|
|
+
|
|
|
+ return (
|
|
|
+ <div className="container">
|
|
|
+ {/* {console.log('events', events)} */}
|
|
|
+ <Switch>
|
|
|
+ {route.map(el => (
|
|
|
+ <PrivateRoute
|
|
|
+ protectedRoute={el.protected}
|
|
|
+ key={el.id}
|
|
|
+ exact={el.exact}
|
|
|
+ path={el.path}
|
|
|
+ component={el.component}
|
|
|
+ // events = {el.events && events}
|
|
|
+ />
|
|
|
+ ))}
|
|
|
|
|
|
-// {
|
|
|
-// events.map(event =>
|
|
|
-// <Route exact
|
|
|
-// path={`/events/${event._id}`}
|
|
|
-// key={event._id}
|
|
|
-// render={ props => (<EventCard event={event} />) }
|
|
|
-// />
|
|
|
-// )
|
|
|
-// }
|
|
|
-// </Switch>
|
|
|
-// </div>
|
|
|
-// );
|
|
|
-// });
|
|
|
-
|
|
|
-export class Router extends React.Component {
|
|
|
- componentDidMount() {
|
|
|
- this.props.getAllEvents();
|
|
|
- }
|
|
|
-
|
|
|
- render() {
|
|
|
- const { events } = this.props;
|
|
|
- return(
|
|
|
- <div className="container">
|
|
|
- <Switch>
|
|
|
- <Route exact path="/" render={ props => (
|
|
|
- <Home events={events} />
|
|
|
- )} />
|
|
|
-
|
|
|
- <Route exact path="/events" render={ props => (
|
|
|
- <Events events={events} />
|
|
|
- )} />
|
|
|
-
|
|
|
- <Route exact path="/result" component={Result} />
|
|
|
- <Route exact path="/gallery" component={Gallery} />
|
|
|
- <Route exact path="/reviews" component={Reviews} />
|
|
|
-
|
|
|
- {
|
|
|
- events.map(event =>
|
|
|
- <Route exact
|
|
|
- path={`/events/${event._id}`}
|
|
|
- key={event._id}
|
|
|
- render={ props => (<EventCard event={event} />) }
|
|
|
- />
|
|
|
- )
|
|
|
- }
|
|
|
-
|
|
|
- <Route exact path="/login" component={Login} />
|
|
|
- <Route exact path="/registration" component={RegistrationPage} />
|
|
|
-
|
|
|
- <Route exact path="/profile" component={Profile} />
|
|
|
-
|
|
|
-
|
|
|
- <Route exact path = '/admin' component = {AdminMainPage} />
|
|
|
- <Route exact path = '/admin/add_new_event' component = {AdminAddEventPage} />
|
|
|
- <Route exact path = '/admin/photogalary' component = {AdminAddPhotogalarytPage} />
|
|
|
- <Route exact path = '/admin/my_events' component = {AdminMyEventsPage} />
|
|
|
-
|
|
|
- </Switch>
|
|
|
- </div>
|
|
|
- )
|
|
|
- }
|
|
|
-}
|
|
|
+ {/* {
|
|
|
+ events.map(event =>
|
|
|
+ <Route exact
|
|
|
+ path={`/events/${event._id}`}
|
|
|
+ key={event._id}
|
|
|
+ render={ props => (<EventCard event={event} />) }
|
|
|
+ />
|
|
|
+ )
|
|
|
+ } */}
|
|
|
+ </Switch>
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+});
|
|
|
|
|
|
const mapStateToProps = state => {
|
|
|
+ console.log('state',state)
|
|
|
return {
|
|
|
- events: state.getEvents.events
|
|
|
+ // events: state.getEvents.events,
|
|
|
+ user: state.login.user
|
|
|
};
|
|
|
};
|
|
|
|
|
|
export default connect(
|
|
|
- mapStateToProps,
|
|
|
- { getAllEvents }
|
|
|
+ mapStateToProps
|
|
|
+ // { getAllEvents }
|
|
|
)(Router);
|