Explorar el Código

deleteUser, saga

Svetlana hace 5 años
padre
commit
a1765cd5e1

+ 16 - 0
src/actions/adminActions/index.js

@@ -0,0 +1,16 @@
+import * as types from '../../constants';
+
+export const userGetRequest = payload => ({
+    type: types.USERS_GET_REQUEST,
+    payload
+})
+
+export const userGetRequestSucces = payload => ({
+    type: types.USERS_GET_REQUEST_SUCCESS,
+    payload
+})
+
+export const userGetRequestFailure = error => ({
+    type: types.USERS_GET_REQUEST_FAILURE,
+    error
+})

+ 1 - 1
src/components/common/protectedRoute/config.js

@@ -28,7 +28,7 @@ export default [
     },
     {
         path: routes.HOME,
-        access: 'user-only',
+        access: 'public',
         component: homePage
     },
     {

+ 1 - 1
src/components/common/protectedRoute/index.js

@@ -22,7 +22,7 @@ export default ({ component: Component, user, access, ...rest  }) => (
             }        
 
             if (access === 'admin-only') {
-                if (user.isAdmin) {
+                if (user.is_admin) {
                     return <Component {...props} />
                 } 
 

+ 3 - 3
src/components/public-components/header/index.js

@@ -23,7 +23,7 @@ export default class header extends Component {
 
     render() {
         const { togglerClosed } = this.state;
-        const { user } = this.props;
+        const { user:{data} } = this.props;
         const toggleStatus = togglerClosed ? "toggle-status--closed" : "toggle-status--opened"
 
         return (
@@ -60,7 +60,7 @@ export default class header extends Component {
                                 </Link>
                             </li>
                             {
-                                user && user.isAdmin && (
+                                data && data.is_admin && (
                                     <React.Fragment>
                                         <li>
                                             <Link className="header__nav nav__list-item--admin-only" to={routes.CREATE_TEST}>
@@ -85,7 +85,7 @@ export default class header extends Component {
 
                     <div className="header__links">
                         {
-                            !user.data
+                            !data
                                 ? (
                                     <React.Fragment>
                                         <Link className="header__links--sign-in link--btn link--btn25" to={routes.SIGN_IN}>Sign in</Link>

+ 29 - 0
src/components/user-components/admin-components/createDeleteUser/index.js

@@ -0,0 +1,29 @@
+import React from 'react';
+import { connect } from 'react-redux';
+import { Field, reduxForm } from 'redux-form';
+
+import formInput from '../../..//common/formInput';
+ submit=()=>{
+     
+ }
+
+class createDeleteUser extends React.Component {
+
+    render() {
+        const {  handleSubmit  } = this.props;
+        return (
+            <form  className="page">
+                <Field name="login"  type="email" placeholder="Enter new login" component={formInput} />
+                <button >Search</button>
+            </form >
+        )
+    }
+}
+
+
+const mapDispatchToProps = dispatch => bindActionCreators({ userGetRequest }, dispatch);
+
+
+export default connect(mapDispatchToProps)(reduxForm({
+    form: "createDeleteUser",   
+})(createDeleteUser))

+ 3 - 3
src/constants/index.js

@@ -1,9 +1,9 @@
-export const SIGN_IN_URL = 'https://quiz.maxcrc.de/api/v1/user?';
+export const SIGN_IN_URL = 'http://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 = 'https://quiz.maxcrc.de/api/v1/user';
+export const SIGN_UP_URL = 'http://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_SUCCESS_FAILURE = 'USERS_GET_REQUEST_FAILURE';
 
 export const TOKEN_AUTH = 'TOKEN_AUTH';
 
-export const USERS_CHANGE_URL = 'https://quiz.maxcrc.de/api/v1/user/';
+export const USERS_CHANGE_URL = 'http://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';

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

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

+ 5 - 3
src/saga/userFields/changePassword/index.js

@@ -7,10 +7,12 @@ export default function* ({payload:{id , password}}) {
     try {
         console.log("payload inside the saga", password);
         const payloads = yield call(() =>
-            axios.put(`${USERS_CHANGE_URL}${id}`, {password:password,
-            },{headers: { "Access-Control-Allow-Origin": "*", } }
+            fetch(`${USERS_CHANGE_URL}${id}`, {
+            method:"PUT",
+            body:JSON.stringify({password})
+            }
             )
-                .then(({ data }) => data)
+                .then(({ data }) => data.json)
         );
         yield put(actions.passwordChangeRequestSucces(payloads));
     }

+ 18 - 0
src/saga/userFields/createDeleteUser/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))
+    }
+}