Tanya Sashyna 5 rokov pred
rodič
commit
ca649fa31d

+ 10 - 0
src/actionTypes/actionTypes.js

@@ -42,10 +42,20 @@ 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";
 
+//eventUser
+export const GET_REGISTRATION_EVENT = "GET_REGISTRATION_EVENT";
+export const GET_REGISTRATION_EVENT_SUCCESS = "GET_REGISTRATION_EVENT_SUCCESS";
+export const GET_REGISTRATION_EVENT_ERROR = "GET_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 PUT_REGISTRATION_EVENT = "PUT_REGISTRATION_EVENT";
+export const PUT_REGISTRATION_EVENT_SUCCESS = "PUT_REGISTRATION_EVENT_SUCCESS";
+export const PUT_REGISTRATION_EVENT_ERROR = "PUT_REGISTRATION_EVENT_ERROR";
+//eventUser
+
 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";

+ 76 - 5
src/actions/registrationEvent.js

@@ -1,23 +1,55 @@
 import * as types from "../actionTypes/actionTypes";
+const urlRegEvent = 'https://api-marathon.herokuapp.com/api/v1/eventUsers';
 
+//get
+export const getRegEvent = payload => ({
+    type: types.GET_REGISTRATION_EVENT,
+    payload
+});
+
+export const getRegEventSuccess = payload => ({
+    type: types.GET_REGISTRATION_EVENT_SUCCESS,
+    payload
+});
+
+export const getRegEventError = payload => ({
+    type: types.GET_REGISTRATION_EVENT_ERROR,
+    payload
+});
+
+export const getAllRegEvent = () => {
+    return dispatch => {
+        let promise = fetch(urlRegEvent)
+
+        dispatch(getRegEvent())
+
+        promise.then(
+            data => data.json().then(data => dispatch(getRegEventSuccess(data))),
+            error => dispatch(getRegEventError(error))
+        )
+    }
+}
+
+//post
 export const regEvent = payload => ({
-    type: types.POST_REQUEST_CHECKIN,
+    type: types.POST_REGISTRATION_EVENT,
     payload
 });
 
 export const regEventSuccess = payload => ({
-    type: types.POST_REQUEST_SUCCESS_CHECKIN,
+    type: types.POST_REGISTRATION_EVENT_SUCCESS,
     payload
 });
 
 export const regEventError = payload => ({
-    type: types.POST_REQUEST_ERROR_CHECKIN,
+    type: types.POST_REGISTRATION_EVENT_ERROR,
     payload
 });
 
 export const regEventSubmit = payload => {
+    console.log('post');
     return dispatch => {
-        let promise = fetch("https://api-marathon.herokuapp.com/api/v1/eventUsers",
+        let promise = fetch(urlRegEvent,
             {
                 method: 'POST',
                 body: JSON.stringify(payload),
@@ -34,4 +66,43 @@ export const regEventSubmit = payload => {
             error => dispatch(regEventError(error))
         )
     }
-}
+}
+
+//put
+/*export const putRegEvent = payload => ({
+    type: types.PUT_REGISTRATION_EVENT,
+    payload
+});
+
+export const putRegEventSuccess = payload => ({
+    type: types.PUT_REGISTRATION_EVENT_SUCCESS,
+    payload
+});
+
+export const putRegEventError = payload => ({
+    type: types.PUT_REGISTRATION_EVENT_ERROR,
+    payload
+});*/
+
+//передать обьект с id юзера и обьект event
+/*export const putRegEventSubmit = payload => {
+    console.log('action',payload.value);
+    return dispatch => {
+        let promise = fetch(`${urlRegEvent}/${payload.id}`,
+            {
+                method: 'PUT',
+                body: JSON.stringify(payload.value),
+                headers: {
+                    "Content-type": "application/json"
+                }
+            }
+        )
+
+        dispatch(putRegEvent())
+
+        promise.then(
+            data => data.json().then(data => dispatch(putRegEventSuccess(data))),
+            error => dispatch(putRegEventError(error))
+        )
+    }
+}*/

+ 1 - 1
src/components/adminResults/adminResultsForm.scss

@@ -2,7 +2,7 @@
 
 .results-form {
 	width: 100%;
-	min-height: 100vh;
+	flex-grow: 1;
 	margin: auto;
 
 	background: -webkit-linear-gradient(top, #fff, $color-blue);

+ 14 - 0
src/components/reg-form-event/RegFormEvent.js

@@ -6,12 +6,26 @@ import { customInput } from "../customFields/customInput/customInput";
 import { validationForms } from "../../utils/validationForms";
 
 let RegFormEvent = props => {
+    //const { handleSubmit, regEventSubmit, putRegEventSubmit, eventId, reset, eventUsers } = props;
     const { handleSubmit, regEventSubmit, eventId, reset } = props;
     const eventTypes = ['Select distance', 'Half marathone','Marathone'];
+    //console.log(eventUsers);
 
     const submit = value => {
         value.event = eventId;
         regEventSubmit(value);
+        /*console.log('value',value);
+        const emailUser = value.email;
+
+        const userEvent = eventUsers.find(el => el.email === emailUser );*/
+        //value.id = userEvent._id;
+        /*console.log('userEvent',userEvent);
+        !userEvent && regEventSubmit(value);
+
+        userEvent && putRegEventSubmit({
+            id: userEvent._id,
+            value: value
+        })*/
         reset();
     };
 

+ 12 - 2
src/conteiners/eventCard/EventCard.js

@@ -2,6 +2,7 @@ import React from 'react';
 import { connect } from "react-redux";
 
 import { getRequestEvent } from "../../actions/getRequestEvent";
+//import { regEventSubmit, getAllRegEvent, putRegEventSubmit } from "../../actions/registrationEvent";
 import { regEventSubmit } from "../../actions/registrationEvent";
 
 import './eventCard.scss';
@@ -13,9 +14,11 @@ import RegFormEvent from '../../components/reg-form-event/RegFormEvent';
 export class EventCard extends React.Component {
     componentDidMount() {
         this.props.getRequestEvent(this.props.match.params.id);
+        //this.props.getAllRegEvent();
     }
 
     render() {
+        //const { event, regEventSubmit, getAllRegEvent, putRegEventSubmit, eventUsers } = this.props;
         const { event, regEventSubmit } = this.props;
         return (
             <>
@@ -80,7 +83,13 @@ export class EventCard extends React.Component {
                                     }
                                 </div>
                                 <div className="reg-form-event">
-                                    <RegFormEvent eventId={event._id} regEventSubmit={regEventSubmit}/>
+                                    <RegFormEvent 
+                                        eventId={event._id} 
+                                        regEventSubmit={regEventSubmit}
+                                        /*getAllRegEvent={getAllRegEvent} 
+                                        putRegEventSubmit={putRegEventSubmit}
+                                        eventUsers={eventUsers}*/
+                                    />
                                 </div>
                             </div>
                         </div>
@@ -94,7 +103,8 @@ export class EventCard extends React.Component {
 
 const mapStateToProps = state => {
     return {
-        event: state.getEventCard.event
+        event: state.getEventCard.event,
+        eventUsers: state.registrationEvent.eventUsers
     };
 };
 

+ 3 - 1
src/reducers/combineReducers.js

@@ -13,6 +13,7 @@ import allReviews from "./reviews";
 import adminResultsReduser from "./adminResultsReduser"
 import userInfo from "./getUserInfo"
 import results from "./getResults";
+import registrationEvent from "./registrationEvent";
 
 export default combineReducers({
 	form: formReducer,
@@ -27,5 +28,6 @@ export default combineReducers({
     logout,
     adminResultsReduser,
     userInfo,
-    results
+    results,
+    registrationEvent
 });

+ 1 - 0
src/reducers/getResults.js

@@ -14,6 +14,7 @@ export default (state = initialState, action) => {
 
         case types.GET_RESULT_SUCCESS: {            
             const resultsArr = action.payload.results;
+            //console.log(resultsArr);
             const marathoneResultsArr = resultsArr.filter( elem => elem.eventUser.distance === "Marathone" );
             
             const halfMarathoneResultsArr = resultsArr.filter( elem => elem.eventUser.distance === "Half marathone" );

+ 36 - 1
src/reducers/registrationEvent.js

@@ -1,11 +1,30 @@
 import * as types from "../actionTypes/actionTypes";
 
 const initialState = {
-    user: {}
+    eventUsers: []
 }
 
 export default (state = initialState, action) => {
     switch (action.type) {
+        //get
+        case types.GET_REGISTRATION_EVENT: {
+            return state;
+        }
+
+        case types.GET_REGISTRATION_EVENT_SUCCESS: {
+            //console.log('getRegEventUser', action.payload.eventusers)
+            return {
+                ...state,
+                eventUsers: action.payload.eventusers
+            };
+        }
+
+        case types.GET_REGISTRATION_EVENT_ERROR: {
+            console.log(action.payload.message);
+            return state;
+        }
+
+        //post
         case types.POST_REGISTRATION_EVENT: {
             return state;
         }
@@ -15,6 +34,22 @@ export default (state = initialState, action) => {
         }
 
         case types.POST_REGISTRATION_EVENT_ERROR: {
+            console.log(action.payload.message);
+            return state;
+        }
+
+        //put
+        case types.PUT_REGISTRATION_EVENT: {
+            return state;
+        }
+
+        case types.PUT_REGISTRATION_EVENT_SUCCESS: {
+            console.log('getRegEventUser',action.payload)
+            return state;
+        }
+
+        case types.PUT_REGISTRATION_EVENT_ERROR: {
+            console.log(action.payload);
             return state;
         }
 

+ 1 - 1
src/styles/custom.scss

@@ -15,7 +15,7 @@ html, body, #root {
 .container {
     display: flex;
     flex-direction: column;
-    height: 100%;
+    min-height: 100%;
 
     &-wrap {
         flex-grow: 1;