-
Notifications
You must be signed in to change notification settings - Fork 51
[PROD] - WM Copilot Portal #1662
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
Changes from all commits
9c12180
e950796
e551d12
537a94b
59cb7d7
9e8f76f
27fc0b8
1f93074
887e1ff
25c01d6
07b407b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,7 +98,7 @@ const ChallengesComponent = ({ | |
<OutlineButton | ||
text='Request Copilot' | ||
type={'info'} | ||
url={`${COPILOTS_URL}/requests/new`} | ||
url={`${COPILOTS_URL}/requests/new?projectId=${activeProject.id}`} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure that |
||
target={'_blank'} | ||
/> | ||
)} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,20 +6,30 @@ import Modal from '../Modal' | |
import SelectUserAutocomplete from '../SelectUserAutocomplete' | ||
import { PROJECT_ROLES } from '../../config/constants' | ||
import PrimaryButton from '../Buttons/PrimaryButton' | ||
import { addUserToProject, inviteUserToProject } from '../../services/projects' | ||
import { addUserToProject, inviteUserToProject, updateProjectMemberRole } from '../../services/projects' | ||
|
||
import styles from './Users.module.scss' | ||
|
||
const theme = { | ||
container: styles.modalContainer | ||
} | ||
|
||
const UserAddModalContent = ({ projectId, addNewProjectMember, onMemberInvited, onClose }) => { | ||
const UserAddModalContent = ({ | ||
projectMembers, | ||
projectOption, | ||
projectId, | ||
addNewProjectMember, | ||
onMemberInvited, | ||
onClose, | ||
updateProjectMember | ||
}) => { | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Consider renaming |
||
const [existingRole, setExistingRole] = useState('') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
||
const onUpdateUserToAdd = (option) => { | ||
if (option && option.value) { | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Consider checking if |
||
const role = get(failed, '0.role') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider checking if |
||
setAddUserError(error) | ||
setIsAdding(false) | ||
setUserAddingFailed(errorCode === 'ALREADY_MEMBER') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure that |
||
setExistingRole(role) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure that |
||
} else if (rest.message) { | ||
setAddUserError(rest.message) | ||
setIsAdding(false) | ||
|
@@ -74,121 +88,152 @@ const UserAddModalContent = ({ projectId, addNewProjectMember, onMemberInvited, | |
} | ||
} | ||
|
||
const onConfirmCopilotRoleChange = async () => { | ||
const member = projectMembers.find(item => item.userId === userToAdd.userId) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider checking if |
||
const action = member.role === 'manager' ? 'complete-copilot-requests' : '' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic for determining the |
||
const response = await updateProjectMemberRole(projectId, member.id, 'copilot', action) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle potential errors from the |
||
updateProjectMember(response) | ||
onClose() | ||
} | ||
|
||
const onCancelCopilotRoleChange = () => { | ||
setUserAddingFailed(false) | ||
setAddUserError('') | ||
} | ||
|
||
return ( | ||
<Modal theme={theme} onCancel={onClose}> | ||
<div className={cn(styles.contentContainer, styles.confirm)}> | ||
<div className={styles.title}>Add User</div> | ||
<div className={styles.addUserContentContainer}> | ||
<div className={styles.row}> | ||
<div className={cn(styles.field, styles.col1, styles.addUserTitle)}> | ||
Member<span className={styles.required}>*</span> : | ||
</div> | ||
<div className={cn(styles.field, styles.col2)}> | ||
<SelectUserAutocomplete | ||
value={userToAdd ? { label: userToAdd.handle, value: userToAdd.userId.toString() } : null} | ||
onChange={onUpdateUserToAdd} | ||
/> | ||
{ | ||
isUserAddingFailed && (['observer', 'customer', 'copilot', 'manager'].includes(existingRole)) && ( | ||
<div className={cn(styles.contentContainer, styles.confirm)}> | ||
<div className={styles.textContent}>{`The copilot ${userToAdd.handle} is part of ${projectOption.label} project with ${existingRole} role.`}</div> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure that |
||
<div className={styles.buttonWrapper}> | ||
<PrimaryButton onClick={onConfirmCopilotRoleChange} text={'Confirm'} type={'info'} /> | ||
<PrimaryButton onClick={onCancelCopilotRoleChange} text={'Cancel'} type={'disabled'} /> | ||
</div> | ||
</div> | ||
{showSelectUserError && ( | ||
<div className={styles.row}> | ||
<div className={styles.errorMesssage}>Please select a member.</div> | ||
</div> | ||
)} | ||
<div className={styles.row}> | ||
<div className={cn(styles.field, styles.col1, styles.addUserTitle)}> | ||
<label htmlFor='memberToAdd'>Role :</label> | ||
</div> | ||
<div className={cn(styles.col5)}> | ||
<div className={styles.tcRadioButton}> | ||
<input | ||
name={`add-user-radio`} | ||
type='radio' | ||
id={`read-add-user`} | ||
checked={userPermissionToAdd === PROJECT_ROLES.READ} | ||
onChange={() => setUserPermissionToAdd(PROJECT_ROLES.READ)} | ||
/> | ||
<label htmlFor={`read-add-user`}> | ||
<div>Read</div> | ||
<input type='hidden' /> | ||
</label> | ||
) | ||
} | ||
{ | ||
!isUserAddingFailed && ( | ||
<div className={cn(styles.contentContainer, styles.confirm)}> | ||
<div className={styles.title}>Add User</div> | ||
<div className={styles.addUserContentContainer}> | ||
<div className={styles.row}> | ||
<div className={cn(styles.field, styles.col1, styles.addUserTitle)}> | ||
Member<span className={styles.required}>*</span> : | ||
</div> | ||
<div className={cn(styles.field, styles.col2)}> | ||
<SelectUserAutocomplete | ||
value={userToAdd ? { label: userToAdd.handle, value: userToAdd.userId.toString() } : null} | ||
onChange={onUpdateUserToAdd} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
<div className={cn(styles.col5)}> | ||
<div className={styles.tcRadioButton}> | ||
<input | ||
name={`add-user-radio`} | ||
type='radio' | ||
id={`write-add-user`} | ||
checked={userPermissionToAdd === PROJECT_ROLES.WRITE} | ||
onChange={() => setUserPermissionToAdd(PROJECT_ROLES.WRITE)} | ||
/> | ||
<label htmlFor={`write-add-user`}> | ||
<div>Write</div> | ||
<input type='hidden' /> | ||
</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 commentThe reason will be displayed to describe this comment to others. Learn more. There is a typo in the class name |
||
</div> | ||
)} | ||
<div className={styles.row}> | ||
<div className={cn(styles.field, styles.col1, styles.addUserTitle)}> | ||
<label htmlFor='memberToAdd'>Role :</label> | ||
</div> | ||
<div className={cn(styles.col5)}> | ||
<div className={styles.tcRadioButton}> | ||
<input | ||
name={`add-user-radio`} | ||
type='radio' | ||
id={`read-add-user`} | ||
checked={userPermissionToAdd === PROJECT_ROLES.READ} | ||
onChange={() => setUserPermissionToAdd(PROJECT_ROLES.READ)} | ||
/> | ||
<label htmlFor={`read-add-user`}> | ||
<div>Read</div> | ||
<input type='hidden' /> | ||
</label> | ||
</div> | ||
</div> | ||
<div className={cn(styles.col5)}> | ||
<div className={styles.tcRadioButton}> | ||
<input | ||
name={`add-user-radio`} | ||
type='radio' | ||
id={`write-add-user`} | ||
checked={userPermissionToAdd === PROJECT_ROLES.WRITE} | ||
onChange={() => setUserPermissionToAdd(PROJECT_ROLES.WRITE)} | ||
/> | ||
<label htmlFor={`write-add-user`}> | ||
<div>Write</div> | ||
<input type='hidden' /> | ||
</label> | ||
</div> | ||
</div> | ||
<div className={cn(styles.col5)}> | ||
<div className={styles.tcRadioButton}> | ||
<input | ||
name={`add-user-radio`} | ||
type='radio' | ||
id={`full-access-add-user`} | ||
checked={userPermissionToAdd === PROJECT_ROLES.MANAGER} | ||
onChange={() => setUserPermissionToAdd(PROJECT_ROLES.MANAGER)} | ||
/> | ||
<label htmlFor={`full-access-add-user`}> | ||
<div>Full Access</div> | ||
<input type='hidden' /> | ||
</label> | ||
</div> | ||
</div> | ||
<div className={cn(styles.col5)}> | ||
<div className={styles.tcRadioButton}> | ||
<input | ||
name={`add-user-radio`} | ||
type='radio' | ||
id={`copilot-add-user`} | ||
checked={userPermissionToAdd === PROJECT_ROLES.COPILOT} | ||
onChange={() => setUserPermissionToAdd(PROJECT_ROLES.COPILOT)} | ||
/> | ||
<label htmlFor={`copilot-add-user`}> | ||
<div>Copilot</div> | ||
<input type='hidden' /> | ||
</label> | ||
</div> | ||
</div> | ||
</div> | ||
{addUserError && ( | ||
<div className={styles.errorMesssage}>{addUserError}</div> | ||
)} | ||
</div> | ||
<div className={cn(styles.col5)}> | ||
<div className={styles.tcRadioButton}> | ||
<input | ||
name={`add-user-radio`} | ||
type='radio' | ||
id={`full-access-add-user`} | ||
checked={userPermissionToAdd === PROJECT_ROLES.MANAGER} | ||
onChange={() => setUserPermissionToAdd(PROJECT_ROLES.MANAGER)} | ||
<div className={styles.buttonGroup}> | ||
<div className={styles.buttonSizeA}> | ||
<PrimaryButton | ||
text={'Close'} | ||
type={'info'} | ||
onClick={onClose} | ||
/> | ||
<label htmlFor={`full-access-add-user`}> | ||
<div>Full Access</div> | ||
<input type='hidden' /> | ||
</label> | ||
</div> | ||
</div> | ||
<div className={cn(styles.col5)}> | ||
<div className={styles.tcRadioButton}> | ||
<input | ||
name={`add-user-radio`} | ||
type='radio' | ||
id={`copilot-add-user`} | ||
checked={userPermissionToAdd === PROJECT_ROLES.COPILOT} | ||
onChange={() => setUserPermissionToAdd(PROJECT_ROLES.COPILOT)} | ||
<div className={styles.buttonSizeA}> | ||
<PrimaryButton | ||
text={isAdding ? 'Adding user...' : 'Add User'} | ||
type={'info'} | ||
onClick={onAddUserConfirmClick} | ||
/> | ||
<label htmlFor={`copilot-add-user`}> | ||
<div>Copilot</div> | ||
<input type='hidden' /> | ||
</label> | ||
</div> | ||
</div> | ||
</div> | ||
{addUserError && ( | ||
<div className={styles.errorMesssage}>{addUserError}</div> | ||
)} | ||
</div> | ||
<div className={styles.buttonGroup}> | ||
<div className={styles.buttonSizeA}> | ||
<PrimaryButton | ||
text={'Close'} | ||
type={'info'} | ||
onClick={onClose} | ||
/> | ||
</div> | ||
<div className={styles.buttonSizeA}> | ||
<PrimaryButton | ||
text={isAdding ? 'Adding user...' : 'Add User'} | ||
type={'info'} | ||
onClick={onAddUserConfirmClick} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
</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 commentThe reason will be displayed to describe this comment to others. Learn more. Consider specifying a more precise PropType for |
||
projectMembers: PropTypes.array.isRequired, | ||
updateProjectMember: PropTypes.func.isRequired | ||
} | ||
|
||
export default UserAddModalContent |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,16 +46,22 @@ const ProjectInvitations = ({ match, auth, isProjectLoading, history, projectDet | |
|
||
const updateInvite = useCallback(async (status, source) => { | ||
setIsUpdating(status) | ||
await updateProjectMemberInvite(projectId, invitation.id, status, source) | ||
|
||
// await for the project details to propagate | ||
await delay(1000) | ||
await loadProjectInvites(projectId) | ||
toastr.success('Success', `Successfully ${status} the invitation.`) | ||
|
||
// await for the project details to fetch | ||
await delay(1000) | ||
history.push(status === PROJECT_MEMBER_INVITE_STATUS_ACCEPTED ? `/projects/${projectId}/challenges` : '/projects') | ||
try { | ||
await updateProjectMemberInvite(projectId, invitation.id, status, source) | ||
|
||
// await for the project details to propagate | ||
await delay(1000) | ||
await loadProjectInvites(projectId) | ||
toastr.success('Success', `Successfully ${status} the invitation.`) | ||
|
||
// await for the project details to fetch | ||
await delay(1000) | ||
history.push(status === PROJECT_MEMBER_INVITE_STATUS_ACCEPTED ? `/projects/${projectId}/challenges` : '/projects') | ||
} catch (e) { | ||
toastr.error('Error', e.response.data.message) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider checking if |
||
await delay(1000) | ||
history.push('/projects') | ||
} | ||
}, [projectId, invitation, loadProjectInvites, history]) | ||
|
||
const acceptInvite = useCallback(() => updateInvite(PROJECT_MEMBER_INVITE_STATUS_ACCEPTED, source), [updateInvite, source]) | ||
|
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 branch name 'pm-1365' should be checked for consistency with the naming conventions used in your project. Ensure that it follows the same pattern as other branch names, such as using uppercase letters or underscores if applicable.