Skip to content

feat(PM-972): copilot invitation with email #1638

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

Merged
merged 1 commit into from
Apr 14, 2025
Merged

feat(PM-972): copilot invitation with email #1638

merged 1 commit into from
Apr 14, 2025

Conversation

hentrymartin
Copy link
Collaborator

What's in this PR?

  • Copilot invitation with email flow

@@ -221,6 +221,7 @@ class Users extends Component {
<UserAddModalContent
projectId={this.state.projectOption.value}
addNewProjectMember={this.props.addNewProjectMember}
onMemberInvited={this.props.addNewProjectInvite}

Choose a reason for hiding this comment

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

Consider renaming the onMemberInvited prop to something more descriptive, such as onInviteMember or handleMemberInvitation, to clearly convey its purpose and maintain consistency with other handler props.

@@ -55,7 +55,10 @@ const InviteUserModalContent = ({ projectId, onClose, onMemberInvited, projectMe

try {
// api restriction: ONLY "customer" role can be invited via email
const { success: invitations = [], failed } = await inviteUserToProject(projectId, emailToInvite, PROJECT_ROLES.CUSTOMER)
const { success: invitations = [], failed } = await inviteUserToProject(projectId, {

Choose a reason for hiding this comment

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

Consider updating the function inviteUserToProject to accept an object as its second parameter, as this change modifies the function call to pass an object instead of separate arguments. Ensure that the function definition and any other calls to it are updated accordingly.


import styles from './Users.module.scss'

const theme = {
container: styles.modalContainer
}

const UserAddModalContent = ({ projectId, addNewProjectMember, onClose }) => {
const UserAddModalContent = ({ projectId, addNewProjectMember, onMemberInvited, onClose }) => {

Choose a reason for hiding this comment

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

The onMemberInvited prop has been added to the UserAddModalContent component. Ensure that this prop is being used appropriately within the component to handle the copilot invitation flow. If not already implemented, consider adding logic to trigger this callback when a member is successfully invited.

role: userPermissionToAdd
})
if (failed) {
const error = get(failed, '0.message', 'Unable to invite user')

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 an array before attempting to access its elements with get(failed, '0.message', 'Unable to invite user'). This will prevent potential runtime errors if failed is not an array.

setAddUserError(error)
setIsAdding(false)
} else {
onMemberInvited(invitations[0] || {})

Choose a reason for hiding this comment

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

Ensure that invitations is an array and has elements before accessing invitations[0]. This will prevent potential runtime errors if invitations is not an array or is empty.

@@ -59,6 +59,7 @@ export const FILE_PICKER_PROGRESS_INTERVAL = 100
export const FILE_PICKER_UPLOAD_RETRY = 2
export const FILE_PICKER_UPLOAD_TIMEOUT = 30 * 60 * 1000 // 30 minutes
export const SPECIFICATION_ATTACHMENTS_FOLDER = 'SPECIFICATION_ATTACHMENTS'
export const MEMBERS_API_URL = process.env.MEMBERS_API_URL

Choose a reason for hiding this comment

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

Ensure that process.env.MEMBERS_API_URL is defined and has a valid value before using it. Consider adding validation logic to handle cases where the environment variable might be undefined or incorrectly set.

Copy link
Contributor

Choose a reason for hiding this comment

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

@hentrymartin can we reuse MEMBERS_API_URL as set via https://github.com/topcoder-platform/work-manager/pull/1638/files#diff-eb618fb9d5e5863df30212207469a147b32305b06fc3606b6a1aaf1fe4f136c4R24?
I want to avoid need to set MEMBERS_API_URL as it can be compiled.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@kkartunov afaik, we don't have to set the MEMBERS_API_URL, we are loading the env variables into process.env(

'process.env': _.mapValues(constants, (value) => JSON.stringify(value))
) from the production.js/development.js file based on the environment. so in a nutshell we don't have to set environment variable anywhere.

const projectMembers = _.get(project, 'members')
const invitedMembers = _.get(project, 'invites')
const invitedUserIds = _.filter(_.map(invitedMembers, 'userId'))

Choose a reason for hiding this comment

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

Consider checking if invitedUserIds is not empty before calling fetchInviteMembers to avoid unnecessary API calls.

invitedMembers
invitedMembers: invitedMembers.map(m => ({
...m,
email: m.email || invitedUsers[m.userId].email

Choose a reason for hiding this comment

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

Ensure that invitedUsers[m.userId] is defined before accessing email to prevent potential runtime errors.

@@ -68,6 +69,19 @@ export async function fetchProjectById (id) {
return _.get(response, 'data')
}

/**
* This fetches the user corresponding to the given userIds
* @param {*} userIds

Choose a reason for hiding this comment

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

Consider specifying the type of userIds in the JSDoc comment. For example, if userIds is expected to be an array of strings, you could write @param {Array<string>} userIds.

* @param {*} userIds
*/
export async function fetchInviteMembers (userIds) {
const url = `${MEMBERS_API_URL}?${userIds.map(id => `userIds[]=${id}`).join('&')}`

Choose a reason for hiding this comment

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

Ensure that MEMBERS_API_URL is defined and correctly imported or declared in this file. If it's not, this could lead to runtime errors.

*/
export async function fetchInviteMembers (userIds) {
const url = `${MEMBERS_API_URL}?${userIds.map(id => `userIds[]=${id}`).join('&')}`
const { data = [] } = await axiosInstance.get(url)

Choose a reason for hiding this comment

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

Consider adding error handling for the API request. This will help manage scenarios where the request fails or returns an unexpected response.

emails: [email],
role: role
})
export async function inviteUserToProject (projectId, params) {

Choose a reason for hiding this comment

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

The function inviteUserToProject now takes a params object instead of separate email and role parameters. Ensure that the params object is validated to contain the necessary properties (emails and role) before passing it to createProjectMemberInvite. This will prevent potential runtime errors if the params object is malformed.

@@ -59,6 +59,7 @@ export const FILE_PICKER_PROGRESS_INTERVAL = 100
export const FILE_PICKER_UPLOAD_RETRY = 2
export const FILE_PICKER_UPLOAD_TIMEOUT = 30 * 60 * 1000 // 30 minutes
export const SPECIFICATION_ATTACHMENTS_FOLDER = 'SPECIFICATION_ATTACHMENTS'
export const MEMBERS_API_URL = process.env.MEMBERS_API_URL
Copy link
Contributor

Choose a reason for hiding this comment

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

@hentrymartin can we reuse MEMBERS_API_URL as set via https://github.com/topcoder-platform/work-manager/pull/1638/files#diff-eb618fb9d5e5863df30212207469a147b32305b06fc3606b6a1aaf1fe4f136c4R24?
I want to avoid need to set MEMBERS_API_URL as it can be compiled.

@hentrymartin hentrymartin merged commit bbe6312 into develop Apr 14, 2025
3 checks passed
@hentrymartin hentrymartin deleted the pm-972 branch April 14, 2025 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants