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

fix(roles): roles page bugs #85

Merged
merged 3 commits into from
Aug 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/routes/Roles/components/RoleForm/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ function RoleForm() {

const editRate = useCallback(
(index, changes) => {
// a num field is `null` but user trying to increase/decrease it
// start with 0
for (const key in changes) {
if (isNaN(changes[key])) {
changes[key] = 0;
}
}
// apply changes
dispatch(
setModalRole({
...roleState,
Expand Down
10 changes: 9 additions & 1 deletion src/routes/Roles/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import { useDispatch, useSelector } from "react-redux";
import debounce from "lodash/debounce";
import omit from "lodash/omit";
import withAuthentication from "hoc/withAuthentication";
import { setFilter, setIsModalOpen, setModalRole } from "store/actions/roles";
import {
setFilter,
setIsModalOpen,
setModalError,
setModalRole,
} from "store/actions/roles";
import { createRole, deleteRole, updateRole } from "store/thunks/roles";
import {
getRolesIsModalOpen,
Expand Down Expand Up @@ -48,6 +53,7 @@ const Roles = () => {

const onCreateClick = useCallback(() => {
setModalOperationType("CREATE");
dispatch(setModalError(null));
// role template with initial values
dispatch(
setModalRole({
Expand All @@ -65,6 +71,7 @@ const Roles = () => {
const onEditClick = useCallback(
(role) => {
setModalOperationType("EDIT");
dispatch(setModalError(null));
dispatch(setModalRole(role));
dispatch(setIsModalOpen(true));
},
Expand All @@ -74,6 +81,7 @@ const Roles = () => {
const onDeleteClick = useCallback(
(role) => {
setModalOperationType("DELETE");
dispatch(setModalError(null));
dispatch(setModalRole(role));
dispatch(setIsModalOpen(true));
},
Expand Down
2 changes: 1 addition & 1 deletion src/store/thunks/roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const createRole = (body) => async (dispatch) => {
const role = extractResponseData(response);
dispatch(actions.createRole(role));
dispatch(actions.setIsModalOpen(false));
makeToast("Successfully craeted the role.", "success");
makeToast("Successfully created the role.", "success");
} catch (error) {
dispatch(
actions.setModalError(`Failed to create the role.\n${error.toString()}`)
Expand Down