Skip to content

Conversation

elvisiraguha
Copy link
Member

@elvisiraguha elvisiraguha commented Nov 16, 2020

What does this PR do?

enable user role settings

Description of Task to be completed?

  • create page for assigning roles to users
  • create page for assigning permissions to roles
  • create page for creating new roles

How should this be manually tested?

  • Clone the repo git clone https://github.com/atlp-rwanda/script-heroes-frontend.git
  • Switch your working directory cd script-heroes-frontend
  • Checkout the branch git checkout ft-user-role-settings-#174797472
  • Install all dependencies yarn install
  • Start the dev server yarn run dev
  • Visit roles page in the browser http://localhost:8080/roles

What are the relevant pivotal tracker stories?

https://www.pivotaltracker.com/story/show/174797472

Screenshots (if appropriate)

Screen Shot 2020-11-30 at 13 47 20

@elvisiraguha elvisiraguha changed the title feat(frontend): user role settings #174797472 User role settings Nov 17, 2020
@elvisiraguha elvisiraguha force-pushed the ft-user-role-settings-#174797472 branch 6 times, most recently from c7ea982 to be966f7 Compare November 18, 2020 11:15
@elvisiraguha elvisiraguha force-pushed the ft-user-role-settings-#174797472 branch 3 times, most recently from 31e7aa1 to 820b9fb Compare November 19, 2020 12:00
@elvisiraguha elvisiraguha force-pushed the ft-user-role-settings-#174797472 branch from 820b9fb to 113bc83 Compare November 19, 2020 14:06
@elvisiraguha elvisiraguha added the WIP work in progress label Nov 23, 2020
@elvisiraguha elvisiraguha force-pushed the ft-user-role-settings-#174797472 branch from 3f1764b to 88ce8ec Compare November 30, 2020 07:39
@elvisiraguha elvisiraguha force-pushed the ft-user-role-settings-#174797472 branch 2 times, most recently from 84a51e6 to bcdc1ec Compare December 1, 2020 19:23
Copy link
Collaborator

@dushimeemma dushimeemma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good Job but try to move url into dotenv

@elvisiraguha elvisiraguha force-pushed the ft-user-role-settings-#174797472 branch from bcdc1ec to aa8b30f Compare December 7, 2020 09:11
@elvisiraguha elvisiraguha requested a review from b0nbon1 December 7, 2020 09:46
@elvisiraguha elvisiraguha force-pushed the ft-user-role-settings-#174797472 branch from aa8b30f to e6e41d8 Compare December 7, 2020 12:38
@elvisiraguha elvisiraguha force-pushed the ft-user-role-settings-#174797472 branch from e6e41d8 to 1d44266 Compare December 7, 2020 13:03
@elvisiraguha elvisiraguha force-pushed the ft-user-role-settings-#174797472 branch 8 times, most recently from e387450 to 57cf821 Compare December 9, 2020 09:05
Comment on lines 33 to 176
const [name, setName] = useState("");
const [description, setDescription] = useState("");
const [modalName, setModalName] = useState("");
const [modalDescription, setModalDescription] = useState("");
const [email, setEmail] = useState("");
const [userRole, setUserRole] = useState("");
const [modal, setModal] = useState(false);
const [whichModal, setWhichModal] = useState("");
const [roleInModal, setRoleInModal] = useState({});
const [validName, setValidName] = useState("");
const [validDescription, setValidDescription] = useState("");
const [disabled, setDisabled] = useState(true);
const [visible, setVisible] = useState(true);

const creating = useSelector((state) => state.statuses.creating);
const assigning = useSelector((state) => state.statuses.assigning);
const updating = useSelector((state) => state.statuses.updating);
const deleting = useSelector((state) => state.statuses.deleting);
const users = useSelector((state) => state.users.users);
const roles = useSelector((state) => state.roles.roles);
const alert = useSelector((state) => state.alerts);

const toggle = () => setModal(!modal);
const dispatch = useDispatch();

useEffect(() => {
document.title = "User Role Settings | Barefoot Nomad";
dispatch(getUsers());
dispatch(getRoles());
}, []);

useEffect(() => {
setEmail(users[0]?.email);
}, [users]);

useEffect(() => {
setUserRole(roles[0]?.name);
}, [roles]);

useEffect(() => {
if (!updating && modal) {
toggle();
}
}, [updating]);

useEffect(() => {
if (!deleting && modal) {
toggle();
}
}, [deleting]);

useEffect(() => {
if (!creating) {
setName("");
setDescription("");
}
}, [creating]);

useEffect(() => {
if (description.length >= 10 && name.length >= 3) {
setDisabled(false);
} else {
setDisabled(true);
}
}, [name, description]);

useEffect(() => {
if (name.length >= 3) {
setValidName("is-valid");
} else {
setValidName("is-invalid");
}
}, [name]);

useEffect(() => {
if (description.length >= 10) {
setValidDescription("is-valid");
} else {
setValidDescription("is-invalid");
}
}, [description]);

useEffect(() => {
setVisible(true);
}, [alert]);

const handleCreate = (e) => {
e.preventDefault();

dispatch(createRole({ name, description }));
};

const handleAssign = (e) => {
e.preventDefault();
dispatch(assignRole({ email, userRole }));
};

const findRoleName = (id) => {
const userRole = roles.filter((role) => role.id === id)[0];

return userRole ? userRole.name : "";
};

const openEditModal = (role) => {
setRoleInModal(role);
setModalName(role.name);
setModalDescription(role.description);
setWhichModal("edit");
toggle();
};

const openDeleteModal = (role) => {
setRoleInModal(role);
setWhichModal("delete");
toggle();
};

const isValid = ({ target }) => {
if (target.value.length < 3) {
target.classList.add("is-invalid");
target.classList.remove("is-valid");
} else {
target.classList.remove("is-invalid");
target.classList.add("is-valid");
}
};

const handleEdit = () => {
if (modalName.length < 3 || modalDescription.length < 3) {
return;
} else {
dispatch(
updateRole(roleInModal.id, {
name: modalName,
description: modalDescription,
})
);
}
};

const handleDelete = () => {
dispatch(deleteRole(roleInModal));
};

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file so large please break it down, I could suggest you separate the logic from the views/components

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed 👍

@elvisiraguha elvisiraguha force-pushed the ft-user-role-settings-#174797472 branch from 57cf821 to b1ab9cb Compare December 9, 2020 13:46
Copy link
Collaborator

@b0nbon1 b0nbon1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rebase the new changes and it'll be ready to be merged

- create page for assigning roles to users
- create page for assinging permissions to roles
- create page for creating new roles

[Finishes #174797472]
@elvisiraguha elvisiraguha force-pushed the ft-user-role-settings-#174797472 branch from b1ab9cb to 700b236 Compare December 10, 2020 11:09
@b0nbon1 b0nbon1 merged commit fee3287 into develop Dec 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants