-
Notifications
You must be signed in to change notification settings - Fork 51
feat(PM-1506): Overwrite role if the copilot is already a member of the project with "read"/"write" access #1658
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
@@ -225,6 +225,9 @@ class Users extends Component { | |||
addNewProjectMember={this.props.addNewProjectMember} | |||
onMemberInvited={this.props.addNewProjectInvite} | |||
onClose={this.resetAddUserState} | |||
projectOption={this.state.projectOption} |
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.
Consider checking if projectOption
is correctly initialized and used within the component. Ensure that it aligns with the intended functionality described in the pull request.
@@ -225,6 +225,9 @@ class Users extends Component { | |||
addNewProjectMember={this.props.addNewProjectMember} | |||
onMemberInvited={this.props.addNewProjectInvite} | |||
onClose={this.resetAddUserState} | |||
projectOption={this.state.projectOption} | |||
projectMembers={projectMembers} |
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.
Verify that projectMembers
is correctly populated and used within the component. Ensure it reflects the current state of project members accurately.
@@ -225,6 +225,9 @@ class Users extends Component { | |||
addNewProjectMember={this.props.addNewProjectMember} | |||
onMemberInvited={this.props.addNewProjectInvite} | |||
onClose={this.resetAddUserState} | |||
projectOption={this.state.projectOption} | |||
projectMembers={projectMembers} | |||
updateProjectMember={updateProjectMember} |
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.
Ensure that updateProjectMember
is properly defined and handles the logic for updating project members as intended. Consider edge cases where the update might fail or need additional validation.
const UserAddModalContent = ({ projectId, addNewProjectMember, onMemberInvited, onClose }) => { | ||
const UserAddModalContent = ({ | ||
projectMembers, | ||
projectOption, |
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.
The projectOption
parameter is added but not used in the function. Consider removing it if it's unnecessary.
const [userToAdd, setUserToAdd] = useState(null) | ||
const [userPermissionToAdd, setUserPermissionToAdd] = useState(PROJECT_ROLES.READ) | ||
const [showSelectUserError, setShowSelectUserError] = useState(false) | ||
const [addUserError, setAddUserError] = useState(null) | ||
const [isAdding, setIsAdding] = useState(false) | ||
const [isUserAddingFailed, setUserAddingFailed] = useState(false) |
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.
The variable isUserAddingFailed
is introduced but not used in the code. Ensure it is utilized or remove it if not needed.
const [userToAdd, setUserToAdd] = useState(null) | ||
const [userPermissionToAdd, setUserPermissionToAdd] = useState(PROJECT_ROLES.READ) | ||
const [showSelectUserError, setShowSelectUserError] = useState(false) | ||
const [addUserError, setAddUserError] = useState(null) | ||
const [isAdding, setIsAdding] = useState(false) | ||
const [isUserAddingFailed, setUserAddingFailed] = useState(false) | ||
const [existingRole, setExistingRole] = useState('') |
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.
The variable existingRole
is introduced but not used in the code. Ensure it is utilized or remove it if not needed.
@@ -52,8 +62,12 @@ const UserAddModalContent = ({ projectId, addNewProjectMember, onMemberInvited, | |||
}) | |||
if (failed) { | |||
const error = get(failed, '0.message', 'User cannot be invited') | |||
const errorCode = get(failed, '0.error') |
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.
Consider checking if failed
is not null or undefined before attempting to access its properties to avoid potential runtime errors.
@@ -52,8 +62,12 @@ const UserAddModalContent = ({ projectId, addNewProjectMember, onMemberInvited, | |||
}) | |||
if (failed) { | |||
const error = get(failed, '0.message', 'User cannot be invited') | |||
const errorCode = get(failed, '0.error') | |||
const role = get(failed, '0.role') |
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.
Consider checking if failed
is not null or undefined before attempting to access its properties to avoid potential runtime errors.
setAddUserError(error) | ||
setIsAdding(false) | ||
setUserAddingFailed(errorCode === 'ALREADY_MEMBER') |
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.
Consider using a constant or enum for the error code 'ALREADY_MEMBER' to avoid magic strings and improve maintainability.
@@ -74,121 +88,152 @@ const UserAddModalContent = ({ projectId, addNewProjectMember, onMemberInvited, | |||
} | |||
} | |||
|
|||
const onConfirmCopilotRoleChange = async () => { | |||
const member = projectMembers.find(item => item.userId === userToAdd.userId) | |||
const action = member.role === 'manager' ? 'complete-copilot-requests' : '' |
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.
Consider checking if member
is undefined
before accessing its properties. This will prevent potential runtime errors if projectMembers.find
does not find a matching member.
const onConfirmCopilotRoleChange = async () => { | ||
const member = projectMembers.find(item => item.userId === userToAdd.userId) | ||
const action = member.role === 'manager' ? 'complete-copilot-requests' : '' | ||
const response = await updateProjectMemberRole(projectId, member.id, 'copilot', action) |
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.
The action
variable is set to an empty string if the member's role is not 'manager'. Consider handling other roles explicitly or documenting why an empty string is appropriate for roles other than 'manager'.
onChange={onUpdateUserToAdd} | ||
/> | ||
{ | ||
isUserAddingFailed && (['observer', 'customer', 'copilot', 'manager'].includes(existingRole)) && ( |
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.
The condition (['observer', 'customer', 'copilot', 'manager'].includes(existingRole))
is repeated multiple times. Consider defining a constant array for these roles to improve readability and maintainability.
</label> | ||
{showSelectUserError && ( | ||
<div className={styles.row}> | ||
<div className={styles.errorMesssage}>Please select a member.</div> |
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.
There is a typo in the class name styles.errorMesssage
. It should be styles.errorMessage
.
</Modal> | ||
) | ||
} | ||
UserAddModalContent.propTypes = { | ||
projectId: PropTypes.number.isRequired, | ||
addNewProjectMember: PropTypes.func.isRequired, | ||
onMemberInvited: PropTypes.func.isRequired, | ||
onClose: PropTypes.func.isRequired | ||
onClose: PropTypes.func.isRequired, | ||
projectOption: PropTypes.any.isRequired, |
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.
Consider using a more specific PropType instead of PropTypes.any
for projectOption
to ensure type safety and clarity. If the type is not clear, consider defining it or using a more descriptive PropType.
@@ -103,9 +103,10 @@ export async function fetchProjectPhases (id) { | |||
* @param newRole the new role | |||
* @returns {Promise<*>} | |||
*/ | |||
export async function updateProjectMemberRole (projectId, memberRecordId, newRole) { | |||
export async function updateProjectMemberRole (projectId, memberRecordId, newRole, action) { |
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.
The function updateProjectMemberRole
now includes an additional parameter action
. Ensure that all calls to this function throughout the codebase are updated to pass this new parameter, or provide a default value to maintain backward compatibility.
What's in this PR?
Ticket link - https://topcoder.atlassian.net/browse/PM-1506