Skip to content

Commit 22b85f8

Browse files
committed
fix(admin-ui): fix actions as per standards
1 parent 66fe216 commit 22b85f8

File tree

6 files changed

+71
-47
lines changed

6 files changed

+71
-47
lines changed

admin-ui/plugins/user-management/components/UserManagement/UserAddPage.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import UserForm from './UserForm'
55
import GluuAlert from '../../../../app/routes/Apps/Gluu/GluuAlert'
66
import { useTranslation } from 'react-i18next'
77
import { useFormik } from 'formik'
8-
import { createUser, redirectToListPage } from '../../redux/actions/UserActions'
8+
import { createUser } from '../../redux/actions/UserActions'
99
import { useDispatch, useSelector } from 'react-redux'
1010
import moment from 'moment'
1111
function UserAddPage() {

admin-ui/plugins/user-management/components/UserManagement/UserList.js

-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { Badge } from 'reactstrap'
77
import {
88
getUsers,
99
setSelectedUserData,
10-
redirectToListPage,
1110
deleteUser,
1211
} from '../../redux/actions/UserActions'
1312

@@ -66,12 +65,6 @@ function UserList(props) {
6665
return history.push(`/user/usermanagement/edit:` + row.tableData.uuid)
6766
}
6867

69-
useEffect(() => {
70-
if (redirectToUserListPage) {
71-
dispatch(redirectToListPage(false))
72-
}
73-
}, [redirectToUserListPage])
74-
7568
function handleUserDelete(row) {
7669
dispatch(deleteUser(row.inum))
7770
}

admin-ui/plugins/user-management/redux/actions/UserActions.js

+27-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import {
22
GET_USERS,
33
GET_USERS_RESPONSE,
4-
USERS_LOADING,
54
CREATE_NEW_USER,
5+
CREATE_NEW_USER_RESPONSE,
66
SELECTED_USER_DATA,
77
UPDATE_USER,
8-
REDIRECT_TO_USERS_LIST,
8+
UPDATE_USER_RESPONSE,
99
DELETE_USER,
10+
DELETE_USER_RESPONSE,
1011
CHANGE_USERS_PASSWORD,
12+
CHANGE_USERS_PASSWORD_RESPONSE,
1113
} from './types'
1214

1315
export const getUsers = (action) => ({
@@ -22,10 +24,6 @@ export const setSelectedUserData = (action) => ({
2224

2325
export const getUserResponse = (action) => ({
2426
type: GET_USERS_RESPONSE,
25-
payload: { action },
26-
})
27-
export const usersLoading = (action) => ({
28-
type: USERS_LOADING,
2927
payload: action,
3028
})
3129

@@ -36,9 +34,9 @@ export const createUser = (action) => {
3634
}
3735
}
3836

39-
export const redirectToListPage = (action) => {
37+
export const createUserResponse = (action) => {
4038
return {
41-
type: REDIRECT_TO_USERS_LIST,
39+
type: CREATE_NEW_USER_RESPONSE,
4240
payload: action,
4341
}
4442
}
@@ -49,16 +47,37 @@ export const updateUser = (action) => {
4947
payload: action,
5048
}
5149
}
50+
51+
export const updateUserResponse = (action) => {
52+
return {
53+
type: UPDATE_USER_RESPONSE,
54+
payload: action,
55+
}
56+
}
5257
export const changeUserPassword = (action) => {
5358
return {
5459
type: CHANGE_USERS_PASSWORD,
5560
payload: action,
5661
}
5762
}
5863

64+
export const changeUserPasswordResponse = (action) => {
65+
return {
66+
type: CHANGE_USERS_PASSWORD_RESPONSE,
67+
payload: action,
68+
}
69+
}
70+
5971
export const deleteUser = (inum) => {
6072
return {
6173
type: DELETE_USER,
6274
payload: inum,
6375
}
6476
}
77+
78+
export const deleteUserResponse = (action) => {
79+
return {
80+
type: DELETE_USER_RESPONSE,
81+
payload: action,
82+
}
83+
}

admin-ui/plugins/user-management/redux/actions/types.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ export const RESET = 'RESET'
44

55
export const GET_USERS = 'GET_USERS'
66
export const GET_USERS_RESPONSE = 'GET_USERS_RESPONSE'
7-
export const USERS_LOADING = 'USERS_LOADING'
87
export const CREATE_NEW_USER = 'CREATE_NEW_USER'
8+
export const CREATE_NEW_USER_RESPONSE = 'CREATE_NEW_USER_RESPONSE'
99
export const UPDATE_USER = 'UPDATE_USER'
10+
export const UPDATE_USER_RESPONSE = 'UPDATE_USER_RESPONSE'
1011
export const SELECTED_USER_DATA = 'SELECTED_USER_DATA'
11-
export const REDIRECT_TO_USERS_LIST = 'REDIRECT_TO_USERS_LIST'
1212
export const DELETE_USER = 'DELETE_USER'
13+
export const DELETE_USER_RESPONSE = 'DELETE_USER_RESPONSE'
1314
export const CHANGE_USERS_PASSWORD = 'CHANGE_USERS_PASSWORD'
15+
export const CHANGE_USERS_PASSWORD_RESPONSE = 'CHANGE_USERS_PASSWORD_RESPONSE'

admin-ui/plugins/user-management/redux/reducers/UserReducer.js

+24-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import {
22
GET_USERS_RESPONSE,
3-
USERS_LOADING,
43
GET_USERS,
54
SELECTED_USER_DATA,
6-
REDIRECT_TO_USERS_LIST,
75
CREATE_NEW_USER,
6+
CREATE_NEW_USER_RESPONSE,
87
UPDATE_USER,
98
DELETE_USER,
109
CHANGE_USERS_PASSWORD,
10+
CHANGE_USERS_PASSWORD_RESPONSE,
11+
UPDATE_USER_RESPONSE,
12+
DELETE_USER_RESPONSE,
1113
} from '../actions/types'
1214
import reducerRegistry from '../../../../app/redux/reducers/ReducerRegistry'
1315

@@ -25,36 +27,49 @@ export default function userReducer(state = INIT_STATE, action) {
2527
return {
2628
...state,
2729
loading: true,
30+
redirectToUserListPage: false,
2831
}
2932
case CREATE_NEW_USER:
3033
return {
3134
...state,
3235
loading: true,
3336
}
37+
case CREATE_NEW_USER_RESPONSE:
38+
return {
39+
...state,
40+
loading: false,
41+
redirectToUserListPage: action.payload ? true : false,
42+
}
3443
case CHANGE_USERS_PASSWORD:
3544
return {
3645
...state,
3746
loading: true,
3847
}
39-
case UPDATE_USER:
48+
case CHANGE_USERS_PASSWORD_RESPONSE:
4049
return {
4150
...state,
4251
loading: true,
4352
}
44-
case DELETE_USER:
53+
case UPDATE_USER:
4554
return {
4655
...state,
4756
loading: true,
4857
}
49-
case REDIRECT_TO_USERS_LIST:
58+
case UPDATE_USER_RESPONSE:
5059
return {
5160
...state,
52-
redirectToUserListPage: action.payload,
61+
loading: false,
62+
redirectToUserListPage: action.payload ? true : false,
5363
}
54-
case USERS_LOADING:
64+
case DELETE_USER:
5565
return {
5666
...state,
57-
loading: action.payload,
67+
loading: true,
68+
}
69+
case DELETE_USER_RESPONSE:
70+
return {
71+
...state,
72+
loading: true,
5873
}
5974
case SELECTED_USER_DATA:
6075
return {
@@ -65,7 +80,7 @@ export default function userReducer(state = INIT_STATE, action) {
6580
return {
6681
...state,
6782
loading: false,
68-
items: action.payload?.action,
83+
items: action.payload ? action.payload : [],
6984
}
7085
default:
7186
return handleDefault()

admin-ui/plugins/user-management/redux/sagas/UserSaga.js

+15-20
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ const JansConfigApi = require('jans_config_api')
2727
import { initAudit } from '../../../../app/redux/sagas/SagaUtils'
2828
import {
2929
getUserResponse,
30-
usersLoading,
31-
redirectToListPage,
30+
updateUserResponse,
31+
deleteUserResponse,
32+
changeUserPasswordResponse,
33+
createUserResponse,
3234
getUsers,
3335
} from '../actions/UserActions'
3436
import { postUserAction } from '../../../../app/redux/api/backend-api'
@@ -47,12 +49,9 @@ export function* createUserSaga({ payload }) {
4749
addAdditionalData(audit, FETCH, API_USERS, payload)
4850
const userApi = yield* newFunction()
4951
const data = yield call(userApi.createUsers, payload)
50-
if (data) {
51-
yield put(redirectToListPage(true))
52-
}
53-
yield put(usersLoading(false))
52+
yield put(createUserResponse(data))
5453
} catch (e) {
55-
yield put(usersLoading(false))
54+
yield put(createUserResponse(null))
5655
if (isFourZeroOneError(e)) {
5756
const jwt = yield select((state) => state.authReducer.userinfo_jwt)
5857
yield put(getAPIAccessToken(jwt))
@@ -65,12 +64,9 @@ export function* updateUserSaga({ payload }) {
6564
addAdditionalData(audit, FETCH, API_USERS, payload)
6665
const userApi = yield* newFunction()
6766
const data = yield call(userApi.updateUsers, payload)
68-
if (data) {
69-
yield put(redirectToListPage(true))
70-
}
71-
yield put(usersLoading(false))
67+
yield put(updateUserResponse(data))
7268
} catch (e) {
73-
yield put(usersLoading(false))
69+
yield put(updateUserResponse(null))
7470
if (isFourZeroOneError(e)) {
7571
const jwt = yield select((state) => state.authReducer.userinfo_jwt)
7672
yield put(getAPIAccessToken(jwt))
@@ -83,10 +79,10 @@ export function* changeUserPasswordSaga({ payload }) {
8379
try {
8480
addAdditionalData(audit, FETCH, API_USERS, payload)
8581
const userApi = yield* newFunction()
86-
yield call(userApi.changeUserPassword, payload)
87-
yield put(usersLoading(false))
82+
const data = yield call(userApi.changeUserPassword, payload)
83+
yield put(changeUserPasswordResponse(data))
8884
} catch (e) {
89-
yield put(usersLoading(false))
85+
yield put(changeUserPasswordResponse(null))
9086
if (isFourZeroOneError(e)) {
9187
const jwt = yield select((state) => state.authReducer.userinfo_jwt)
9288
yield put(getAPIAccessToken(jwt))
@@ -101,10 +97,9 @@ export function* getUsersSaga({ payload }) {
10197
const userApi = yield* newFunction()
10298
const data = yield call(userApi.getUsers)
10399
yield put(getUserResponse(data))
104-
yield put(usersLoading(false))
105100
yield call(postUserAction, audit)
106101
} catch (e) {
107-
yield put(usersLoading(false))
102+
yield put(getUserResponse(null))
108103
if (isFourZeroOneError(e)) {
109104
const jwt = yield select((state) => state.authReducer.userinfo_jwt)
110105
yield put(getAPIAccessToken(jwt))
@@ -117,11 +112,11 @@ export function* deleteUserSaga({ payload }) {
117112
try {
118113
addAdditionalData(audit, FETCH, API_USERS, payload)
119114
const userApi = yield* newFunction()
120-
yield call(userApi.deleteUser, payload)
115+
const data = yield call(userApi.deleteUser, payload)
121116
yield put(getUsers({}))
122-
yield put(usersLoading(false))
117+
yield put(deleteUserResponse(data))
123118
} catch (e) {
124-
yield put(usersLoading(false))
119+
yield put(deleteUserResponse(null))
125120
if (isFourZeroOneError(e)) {
126121
const jwt = yield select((state) => state.authReducer.userinfo_jwt)
127122
yield put(getAPIAccessToken(jwt))

0 commit comments

Comments
 (0)