Svetlana hace 5 años
padre
commit
cb0ed4bf02

+ 16 - 0
src/actions/userFields/deleteUser.js

@@ -0,0 +1,16 @@
+import * as types from '../../constants';
+
+export const deleteUserRequest = payload => ({
+    type: types.DELETE_USER_REQUEST,
+    payload
+})
+
+export const deleteUserRequestSucces = payload => ({
+    type: types.DELETE_USER_REQUEST_SUCCESS,
+    payload
+})
+
+export const deleteUserRequestFailure = error => ({
+    type: types.DELETE_USER_REQUEST_FAILURE,
+    error
+})

+ 2 - 2
src/components/user-components/admin-components/createDeleteUser/deleteUser/index.js

@@ -11,10 +11,10 @@ import {deleteUserRequest} from '../../../../../actions/adminActions/deleteUser'
 
 class DeleteUser extends React.Component {
     onClick =() =>{
-        const { deleteUserRequest, data:{login}} = this.props;
+        const { deleteUserRequest, data:{login, id}} = this.props;
         console.log(login)
         deleteUserRequest({
-            login
+            login, id
         })
     }
 

+ 1 - 1
src/components/user-components/profilePage/index.js

@@ -51,7 +51,7 @@ class profilePage extends React.Component {
     render() {
         const { user:{data},users, userChangeRequest,passwordChangeRequest } = this.props;
 
-        console.log('User', users);
+        // console.log('User', users);
         // console.log('Props', this.props);
         // console.log('State', this.state);
 

+ 4 - 4
src/constants/index.js

@@ -1,9 +1,9 @@
-export const SIGN_IN_URL = 'http://quiz.maxcrc.de/api/v1/user?';
+export const SIGN_IN_URL = 'https://quiz.maxcrc.de/api/v1/user?';
 export const SIGN_IN_REQUEST = 'SIGN_IN_REQUEST';
 export const SIGN_IN_REQUEST_SUCCESS = 'SIGN_IN_REQUEST_SUCCESS';
 export const SIGN_IN_REQUEST_FAILURE = 'SIGN_IN_REQUEST_FAILURE';
 
-export const SIGN_UP_URL = 'http://quiz.maxcrc.de/api/v1/user';
+export const SIGN_UP_URL = 'https://quiz.maxcrc.de/api/v1/user';
 export const SIGN_UP_REQUEST = 'SIGN_UP_REQUEST';
 export const SIGN_UP_REQUEST_SUCCESS = 'SIGN_UP_REQUEST_SUCCESS';
 export const SIGN_UP_REQUEST_FAILURE = 'SIGN_UP_REQUEST_FAILURE';
@@ -19,7 +19,7 @@ export const USERS_GET_REQUEST_FAILURE = 'USERS_GET_REQUEST_FAILURE';
 
 export const TOKEN_AUTH = 'TOKEN_AUTH';
 
-export const USERS_CHANGE_URL = 'http://quiz.maxcrc.de/api/v1/user/';
+export const USERS_CHANGE_URL = 'https://quiz.maxcrc.de/api/v1/user/';
 export const USERS_CHANGE_REQUEST = 'USERS_CHANGE_REQUEST';
 export const USERS_CHANGE_REQUEST_SUCCESS = 'USERS_CHANGE_REQUEST_SUCCESS';
 export const USERS_CHANGE_REQUEST_FAILURE = 'USERS_CHANGE_REQUEST_FAILURE';
@@ -34,7 +34,7 @@ export const GET_CARDS = 'GET_CARD';
 export const GET_CARDS_SUCCESS = 'GET_CARDS_SUCCESS';
 export const GET_CARDS_FAILURE = 'GET_CARDS_FAILURE';
 
-export const USER_GET ='http://quiz.maxcrc.de/api/v1/user?'
+export const USER_GET ='https://quiz.maxcrc.de/api/v1/user?'
 export const USER_GET_REQUEST = 'USER_GET_REQUEST';
 export const USER_GET_REQUEST_SUCCESS = 'USER_GET_REQUEST_SUCCESS';
 export const USER_GET_REQUEST_FAILURE = 'USER_GET_REQUEST_FAILURE';

+ 25 - 0
src/reducers/deleteUsers/index.js

@@ -0,0 +1,25 @@
+import * as types from './../../constants';
+import initialState from './../initialState';
+
+export default function deleteUser(state = initialState.getUser, { type, payload }) {
+    switch (type) {
+        case types.DELETE_USER_REQUEST: {
+            return state
+        }
+        case types.DELETE_USER_REQUEST_SUCCESS: {
+            return {
+                ...state,
+               payload
+            }
+        }
+        case types.DELETE_USER_REQUEST_FAILURE: {
+            return {
+               payload
+            }
+        }
+        default: {
+            return state
+        }
+    }
+
+}

+ 2 - 2
src/saga/userFields/changeEmail/index.js

@@ -5,9 +5,9 @@ import { USERS_CHANGE_URL } from '../../../constants/index'
 
 export default function* ({payload:{id, login}}) {
     try {
-        console.log("payload inside the saga", id);
+        console.log("payload inside the saga", id, login);
         const payloads = yield call(() =>
-            axios.put(`${USERS_CHANGE_URL}${id}`, {body:{login}})
+            axios.put(`${USERS_CHANGE_URL}${id}`, {login})
                 .then(({ data }) => data)
         );
         yield put(actions.userChangeRequestSucces(payloads));

+ 4 - 8
src/saga/userFields/changePassword/index.js

@@ -3,16 +3,12 @@ import * as actions from './../../../actions/userFields/changePassword'
 import axios from 'axios';
 import { USERS_CHANGE_URL } from '../../../constants/index'
 
-export default function* ({payload:{id , password}}) {
+export default function* ({ payload: { id, password } }) {
     try {
-        console.log("payload inside the saga", password);
+        console.log("payload inside the saga",id, password);
         const payloads = yield call(() =>
-            fetch(`${USERS_CHANGE_URL}${id}`, {
-            method:"PUT",
-            body:JSON.stringify({password})
-            }
-            )
-                .then(({ data }) => data.json)
+            axios.put(`${USERS_CHANGE_URL}${id}`, {password})
+                .then(({ data }) => data)
         );
         yield put(actions.passwordChangeRequestSucces(payloads));
     }

+ 18 - 0
src/saga/userFields/createGetUser/index.js

@@ -0,0 +1,18 @@
+import { put, call } from "redux-saga/effects";
+import * as actions from '../../../actions/adminActions/index'
+import axios from 'axios';
+import { SIGN_UP_URL } from '../../../constants/index'
+
+export default function* (payload) {
+    try {
+        console.log("payload inside the saga", payload);
+        const payloads = yield call(() =>
+            axios.get(`${SIGN_UP_URL}`)
+                .then(({ data }) => data)
+        );
+        yield put(actions.userGetRequestSucces(payloads));
+    }
+    catch ({ message }) {
+        yield put(actions.userGetRequestFailure(message))
+    }
+}

+ 4 - 4
src/saga/userFields/deleteUser/index.js

@@ -1,13 +1,13 @@
 import { put, call } from "redux-saga/effects";
 import * as actions from './../../../actions/adminActions/deleteUser'
 import axios from 'axios';
-import { USER_GET } from '../../../constants/index'
+import { USERS_CHANGE_URL } from '../../../constants/index'
 
-export default function* ({payload:{login}}) {
+export default function* ({payload:{login,id}}) {
     try {
-        console.log("payload inside the saga", login);
+        console.log("payload inside the saga", login, id);
         const payloads = yield call(() =>
-            axios.delete(`${USER_GET}login=${login}`)
+            axios.delete(`${USERS_CHANGE_URL}${id}`)
                 .then((data) => data)
         );
         yield put(actions.deleteUserRequestSucces(payloads));