Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit d99814d

Browse files
authored
Merge pull request #85 from cagdas001/dev
fix(roles): roles page bugs
2 parents 9da29ef + 870b4d5 commit d99814d

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

src/routes/Roles/components/RoleForm/index.jsx

+8
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ function RoleForm() {
8989

9090
const editRate = useCallback(
9191
(index, changes) => {
92+
// a num field is `null` but user trying to increase/decrease it
93+
// start with 0
94+
for (const key in changes) {
95+
if (isNaN(changes[key])) {
96+
changes[key] = 0;
97+
}
98+
}
99+
// apply changes
92100
dispatch(
93101
setModalRole({
94102
...roleState,

src/routes/Roles/index.jsx

+9-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ import { useDispatch, useSelector } from "react-redux";
33
import debounce from "lodash/debounce";
44
import omit from "lodash/omit";
55
import withAuthentication from "hoc/withAuthentication";
6-
import { setFilter, setIsModalOpen, setModalRole } from "store/actions/roles";
6+
import {
7+
setFilter,
8+
setIsModalOpen,
9+
setModalError,
10+
setModalRole,
11+
} from "store/actions/roles";
712
import { createRole, deleteRole, updateRole } from "store/thunks/roles";
813
import {
914
getRolesIsModalOpen,
@@ -48,6 +53,7 @@ const Roles = () => {
4853

4954
const onCreateClick = useCallback(() => {
5055
setModalOperationType("CREATE");
56+
dispatch(setModalError(null));
5157
// role template with initial values
5258
dispatch(
5359
setModalRole({
@@ -65,6 +71,7 @@ const Roles = () => {
6571
const onEditClick = useCallback(
6672
(role) => {
6773
setModalOperationType("EDIT");
74+
dispatch(setModalError(null));
6875
dispatch(setModalRole(role));
6976
dispatch(setIsModalOpen(true));
7077
},
@@ -74,6 +81,7 @@ const Roles = () => {
7481
const onDeleteClick = useCallback(
7582
(role) => {
7683
setModalOperationType("DELETE");
84+
dispatch(setModalError(null));
7785
dispatch(setModalRole(role));
7886
dispatch(setIsModalOpen(true));
7987
},

src/store/thunks/roles.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const createRole = (body) => async (dispatch) => {
3939
const role = extractResponseData(response);
4040
dispatch(actions.createRole(role));
4141
dispatch(actions.setIsModalOpen(false));
42-
makeToast("Successfully craeted the role.", "success");
42+
makeToast("Successfully created the role.", "success");
4343
} catch (error) {
4444
dispatch(
4545
actions.setModalError(`Failed to create the role.\n${error.toString()}`)

0 commit comments

Comments
 (0)