From 1e10632f7e01c1400e677ac062b367dd4929cf9e Mon Sep 17 00:00:00 2001 From: Tiago Paiva Date: Wed, 5 Mar 2025 12:29:21 -0300 Subject: [PATCH] fix: Adds permission groups to invite (#5173) --- frontend/common/stores/organisation-store.js | 1 + frontend/web/components/GroupSelect.tsx | 4 +- frontend/web/components/modals/InviteUsers.js | 210 ------------ .../web/components/modals/InviteUsers.tsx | 306 ++++++++++++++++++ 4 files changed, 309 insertions(+), 212 deletions(-) delete mode 100644 frontend/web/components/modals/InviteUsers.js create mode 100644 frontend/web/components/modals/InviteUsers.tsx diff --git a/frontend/common/stores/organisation-store.js b/frontend/common/stores/organisation-store.js index 0d2262e65a9e..3d3761521d86 100644 --- a/frontend/common/stores/organisation-store.js +++ b/frontend/common/stores/organisation-store.js @@ -263,6 +263,7 @@ const controller = { API.trackEvent(Constants.events.INVITE) return { email: invite.emailAddress, + permission_groups: invite.groups, role: invite.role.value, } }), diff --git a/frontend/web/components/GroupSelect.tsx b/frontend/web/components/GroupSelect.tsx index ec04ef7e1446..13611b2f9f5d 100644 --- a/frontend/web/components/GroupSelect.tsx +++ b/frontend/web/components/GroupSelect.tsx @@ -11,7 +11,7 @@ export type GroupSelectType = { value: number[] | undefined isOpen: boolean size: string - onAdd: (id: number, isUser: boolean) => void + onAdd: (id: number, isUser: boolean, name?: string) => void onRemove: (id: number, isUser: boolean) => void onToggle: () => void } @@ -58,7 +58,7 @@ const GroupSelect: FC = ({ if (isRemove && onRemove) { onRemove(v.id, false) } else if (!isRemove && onAdd) { - onAdd(v.id, false) + onAdd(v.id, false, v.name) } }} className='assignees-list-item clickable' diff --git a/frontend/web/components/modals/InviteUsers.js b/frontend/web/components/modals/InviteUsers.js deleted file mode 100644 index 19b7aa258d9a..000000000000 --- a/frontend/web/components/modals/InviteUsers.js +++ /dev/null @@ -1,210 +0,0 @@ -import React, { Component } from 'react' -import Button from 'components/base/forms/Button' -import ConfigProvider from 'common/providers/ConfigProvider' -import Constants from 'common/constants' -import Icon from 'components/Icon' -import { add } from 'ionicons/icons' -import { IonIcon } from '@ionic/react' -import { getPlanBasedOption } from 'components/PlanBasedAccess' - -const InviteUsers = class extends Component { - static displayName = 'InviteUsers' - - constructor(props, context) { - super(props, context) - this.state = { - invites: [{}], - name: props.name, - tab: 0, - } - } - - close(invites) { - AppActions.inviteUsers(invites) - closeModal() - } - - componentDidMount = () => { - this.focusTimeout = setTimeout(() => { - this.input.focus() - this.focusTimeout = null - }, 500) - } - - componentWillUnmount() { - if (this.focusTimeout) { - clearTimeout(this.focusTimeout) - } - } - - isValid = () => - _.every( - this.state.invites, - (invite) => Utils.isValidEmail(invite.emailAddress) && invite.role, - ) - - onChange = (index, key, value) => { - const invites = this.state.invites - invites[index][key] = value - this.setState({ invites }) - } - - deleteInvite = (index) => { - const invites = this.state.invites - invites.splice(index, 1) - this.setState({ invites }) - } - - changeTab = (tab) => { - this.setState({ - invites: [{}], - tab, - }) - } - - render() { - const { invites } = this.state - - return ( - - {({ error, isSaving }) => ( -
-
{ - e.preventDefault() - AppActions.inviteUsers(invites) - }} - > -
- - - - - - - - - {_.map(invites, (invite, index) => ( - - - (this.input = e)} - inputProps={{ - className: 'full-width', - name: 'inviteEmail', - }} - onChange={(e) => - this.onChange( - index, - 'emailAddress', - Utils.safeParseEventValue(e), - ) - } - value={invite.emailAddress} - isValid={this.isValid} - type='text' - placeholder='E-mail address' - /> - - - + onChange(invite.temporaryId, 'role', role) + } + className='pl-2 react-select' + options={_.map(Constants.roles, (label, value) => + value === 'ADMIN' + ? { + label, + value, + } + : getPlanBasedOption( + { + label, + value, + }, + 'RBAC', + ), + )} + /> + + +