Browse Source

changeUser - deleteUser and changeUser now working properly

Boris K 5 years ago
parent
commit
e741a48938
3 changed files with 17 additions and 9 deletions
  1. 8 4
      src/actions/user.js
  2. 7 3
      src/components/Admin/Admin.js
  3. 2 2
      src/components/Admin/ChangeUser.js

+ 8 - 4
src/actions/user.js

@@ -86,11 +86,15 @@ const putUserRequestFail = payload => ({
 
 export const putUser = (payload) => dispatch => {
     dispatch(putUserRequest());
-    return fetch(`${URL}${payload}`, {
-        method: "DELETE",
-        credentials: "include"
+    return fetch(`${URL}${payload.path}`, {
+        method: "PUT",
+        credentials: "include",
+        headers: {
+            "Content-Type": "application/json"
+        },
+        body: JSON.stringify(payload.data)
     })
         .then(res => res.json())
         .then(res => dispatch(putUserRequestSuccess(res)))
         .catch(err => dispatch(putUserRequestFail(err)));
-};
+};

+ 7 - 3
src/components/Admin/Admin.js

@@ -22,7 +22,8 @@ import {
     changeFindUserInput,
     findUser,
     deleteUser,
-    changeInputValueUserForm
+    changeInputValueUserForm,
+    putUser
 } from "../../actions/user"
 
 import Shedule from './Shedule'
@@ -64,7 +65,8 @@ export class Admin extends React.Component {
             deleteUser,
             userError,
             changeUserForm,
-            changeInputValueUserForm
+            changeInputValueUserForm,
+            putUser
         } = this.props;
 
         return (
@@ -115,6 +117,7 @@ export class Admin extends React.Component {
                             error={userError}
                             changeUserForm={changeUserForm}
                             changeInputValueUserForm={changeInputValueUserForm}
+                            putUser={putUser}
                         />} />
                     </Switch>
                 </div>
@@ -158,7 +161,8 @@ const mapDispatchToProps = {
     changeFindUserInput,
     findUser,
     deleteUser,
-    changeInputValueUserForm
+    changeInputValueUserForm,
+    putUser
 };
 
 export default connect (mapStateToProps,mapDispatchToProps)(Admin)

+ 2 - 2
src/components/Admin/ChangeUser.js

@@ -30,7 +30,7 @@ export default class ChangeUser extends React.Component {
         this.props.changeUserForm.map(el => {
             obj[el.name] = el.type === 'radio' ? el.checked ? el.value : !el.value : el.value
         });
-        console.log(obj) //заменить на putUsers
+        this.props.putUser({data:obj,path:this.props.user._id})
     };
 
     changeConfirm = (action, text) => {
@@ -38,7 +38,7 @@ export default class ChangeUser extends React.Component {
     };
 
     deleteUser = (e) => {
-        console.log(this.props.user._id); // заменить на deleteUser
+        this.props.deleteUser(this.props.user._id);
         this.changeConfirm()
     };