-
Notifications
You must be signed in to change notification settings - Fork 1
#174797472 User role settings #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
c7ea982
to
be966f7
Compare
31e7aa1
to
820b9fb
Compare
820b9fb
to
113bc83
Compare
3f1764b
to
88ce8ec
Compare
84a51e6
to
bcdc1ec
Compare
There was a problem hiding this 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
bcdc1ec
to
aa8b30f
Compare
aa8b30f
to
e6e41d8
Compare
e6e41d8
to
1d44266
Compare
e387450
to
57cf821
Compare
src/views/Roles/Roles.js
Outdated
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)); | ||
}; | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed 👍
57cf821
to
b1ab9cb
Compare
There was a problem hiding this 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]
b1ab9cb
to
700b236
Compare
What does this PR do?
enable user role settings
Description of Task to be completed?
How should this be manually tested?
https://github.com/atlp-rwanda/script-heroes-frontend.git
cd script-heroes-frontend
ft-user-role-settings-#174797472
yarn install
yarn run dev
http://localhost:8080/roles
What are the relevant pivotal tracker stories?
https://www.pivotaltracker.com/story/show/174797472
Screenshots (if appropriate)