|
@@ -1,14 +1,17 @@
|
|
|
import * as types from '../actionsTypes/actionsTypes'
|
|
|
|
|
|
+import {adminChangeUserForm} from "../utils/formFields"
|
|
|
+
|
|
|
const defaultState = {
|
|
|
- user:null,
|
|
|
- findUserInput:'',
|
|
|
+ user: null,
|
|
|
+ findUserInput: '',
|
|
|
+ changeUserForm: adminChangeUserForm,
|
|
|
isFetching: false,
|
|
|
- error:null
|
|
|
+ error: null
|
|
|
};
|
|
|
|
|
|
export const userReducer = (state = defaultState, action) => {
|
|
|
- switch(action.type){
|
|
|
+ switch (action.type) {
|
|
|
|
|
|
case types.FIND_USER_REQUEST : {
|
|
|
return {
|
|
@@ -18,9 +21,23 @@ export const userReducer = (state = defaultState, action) => {
|
|
|
}
|
|
|
|
|
|
case types.FIND_USER_REQUEST_SUCCESS : {
|
|
|
+ const data = state.findUserInput.includes('@') ? action.payload.users[0] : action.payload.user;
|
|
|
+ state.changeUserForm.map(el => console.log(Object.keys(data).find(item => item === el.name)));
|
|
|
return {
|
|
|
...state,
|
|
|
- user:state.findUserInput.includes('@') ? action.payload.users[0] : action.payload.user,
|
|
|
+ user: data,
|
|
|
+ changeUserForm: state.changeUserForm.map(el => Object.keys(data).find(item => item === el.name) ? el.type === 'radio' ?
|
|
|
+ {
|
|
|
+ ...el,
|
|
|
+ checked: data[`${el.name}`] === el.value
|
|
|
+ } :
|
|
|
+ {
|
|
|
+ ...el,
|
|
|
+ value: data[`${el.name}`]
|
|
|
+ } :
|
|
|
+ el
|
|
|
+ ),
|
|
|
+ error: action.payload.message,
|
|
|
isFetching: false
|
|
|
};
|
|
|
}
|
|
@@ -28,7 +45,7 @@ export const userReducer = (state = defaultState, action) => {
|
|
|
case types.FIND_USER_REQUEST_FAIL : {
|
|
|
return {
|
|
|
...state,
|
|
|
- error:action.payload,
|
|
|
+ error: action.payload,
|
|
|
isFetching: false
|
|
|
}
|
|
|
}
|
|
@@ -36,12 +53,30 @@ export const userReducer = (state = defaultState, action) => {
|
|
|
case types.CHANGE_INPUT_VALUE_FIND_USER : {
|
|
|
return {
|
|
|
...state,
|
|
|
- findUserInput:action.payload
|
|
|
+ findUserInput: action.payload
|
|
|
};
|
|
|
}
|
|
|
|
|
|
+ case types.CHANGE_INPUT_VALUE_USER_FORM : {
|
|
|
+ console.log(action.payload.target);
|
|
|
+ const data = action.payload.target;
|
|
|
+ return {
|
|
|
+ ...state,
|
|
|
+ changeUserForm: state.changeUserForm.map(el => el.name === data.name ? el.type === 'radio' ?
|
|
|
+ {
|
|
|
+ ...el,
|
|
|
+ checked: !el.checked
|
|
|
+ } :
|
|
|
+ {
|
|
|
+ ...el,
|
|
|
+ value: data.value
|
|
|
+ } :
|
|
|
+ el
|
|
|
+ ),
|
|
|
+ };
|
|
|
+ }
|
|
|
|
|
|
- case types.DELETE_USER_REQUEST : {
|
|
|
+ case types.DELETE_USER_REQUEST : {
|
|
|
return {
|
|
|
...state,
|
|
|
isFetching: true
|
|
@@ -51,7 +86,7 @@ export const userReducer = (state = defaultState, action) => {
|
|
|
case types.DELETE_USER_REQUEST_SUCCESS : {
|
|
|
return {
|
|
|
...state,
|
|
|
- services:action.payload,
|
|
|
+ services: action.payload,
|
|
|
isFetching: false
|
|
|
};
|
|
|
}
|
|
@@ -59,12 +94,11 @@ export const userReducer = (state = defaultState, action) => {
|
|
|
case types.DELETE_USER_REQUEST_FAIL : {
|
|
|
return {
|
|
|
...state,
|
|
|
- error:action.payload,
|
|
|
+ error: action.payload,
|
|
|
isFetching: false
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
|
|
|
default:
|
|
|
return state
|