@@ -12,6 +12,9 @@ import { HelpText } from "components/HelpText";
12
12
import copyToClipboard from "copy-to-clipboard" ;
13
13
import { trans } from "i18n" ;
14
14
import { messageInstance } from "lowcoder-design/src/components/GlobalInstances" ;
15
+ import Divider from "antd/es/divider" ;
16
+ import Flex from "antd/es/flex" ;
17
+ import Select from "antd/es/select" ;
15
18
16
19
const InviteButton = styled ( TacoButton ) `
17
20
width: 76px;
@@ -23,14 +26,36 @@ const StyledLoading = styled(WhiteLoading)`
23
26
height: 170px;
24
27
` ;
25
28
26
- function InviteContent ( props : { inviteInfo : InviteInfo } ) {
27
- const { inviteInfo } = props ;
29
+ function InviteContent ( props : { inviteInfo : InviteInfo , onClose ?: ( ) => void } ) {
30
+ const { inviteInfo, onClose } = props ;
28
31
const inviteLink = genInviteLink ( inviteInfo ?. inviteCode ) ;
29
32
const inviteText = trans ( "memberSettings.inviteText" , {
30
33
userName : inviteInfo . createUserName ,
31
34
organization : inviteInfo . invitedOrganizationName ,
32
35
inviteLink,
33
36
} ) ;
37
+ const [ emails , setEmails ] = useState < string [ ] > ( [ ] ) ;
38
+
39
+ const isValidEmail = ( email : string ) => / ^ [ ^ \s @ ] + @ [ ^ \s @ ] + \. [ ^ \s @ ] + $ / . test ( email ) ;
40
+
41
+ const sendInvitations = async ( ) => {
42
+ const filteredEmails = emails . filter ( isValidEmail ) ;
43
+ if ( ! filteredEmails . length ) {
44
+ return messageInstance . error ( trans ( "memberSettings.noValidEmails" ) ) ;
45
+ }
46
+ try {
47
+ const resp = await InviteApi . sendInvitations ( { emails : filteredEmails , orgId : inviteInfo . invitedOrganizationId } )
48
+ if ( validateResponse ( resp ) && resp . data . success ) {
49
+ messageInstance . success ( trans ( 'membersSettings.inviteByEmailSuccess' ) ) ;
50
+ onClose ?.( ) ;
51
+ return ;
52
+ }
53
+ throw new Error ( trans ( 'membersSettings.inviteByEmailError' ) ) ;
54
+ } catch ( e : any ) {
55
+ messageInstance . error ( e . message ) ;
56
+ }
57
+ }
58
+
34
59
return (
35
60
< >
36
61
< HelpText style = { { marginBottom : 16 } } > { trans ( "memberSettings.inviteUserHelp" ) } </ HelpText >
@@ -48,6 +73,34 @@ function InviteContent(props: { inviteInfo: InviteInfo }) {
48
73
{ trans ( "memberSettings.inviteCopyLink" ) }
49
74
</ InviteButton >
50
75
</ div >
76
+ < Divider style = { { marginTop : '60px' } } />
77
+ < HelpText style = { { marginBottom : 16 } } > { trans ( "memberSettings.inviteByEmailHelp" ) } </ HelpText >
78
+ < CommonTextLabel > { trans ( "memberSettings.inviteByEmailLabel" ) } </ CommonTextLabel >
79
+ < Select
80
+ mode = "tags"
81
+ allowClear
82
+ open = { false }
83
+ style = { { width : '100%' , marginTop : '8px' , marginBottom : '8px' } }
84
+ placeholder = "Enter emails"
85
+ defaultValue = { [ ] }
86
+ onChange = { ( value ) => {
87
+ setEmails ( value ) ;
88
+ } }
89
+ options = { [ ] }
90
+ showSearch = { false }
91
+ suffixIcon = { '' }
92
+ />
93
+ < Flex justify = "end" >
94
+ < TacoButton
95
+ buttonType = "primary"
96
+ onClick = { ( ) => {
97
+ sendInvitations ( ) ;
98
+ } }
99
+ disabled = { ! Boolean ( emails ?. length ) }
100
+ >
101
+ { trans ( "memberSettings.inviteByEmailButton" ) }
102
+ </ TacoButton >
103
+ </ Flex >
51
104
</ >
52
105
) ;
53
106
}
@@ -101,7 +154,7 @@ function InviteDialog(props: {
101
154
showCancelButton = { false }
102
155
width = "440px"
103
156
>
104
- { ! inviteInfo ? < StyledLoading size = { 20 } /> : < InviteContent inviteInfo = { inviteInfo } /> }
157
+ { ! inviteInfo ? < StyledLoading size = { 20 } /> : < InviteContent inviteInfo = { inviteInfo } onClose = { ( ) => setInviteDialogVisible ( false ) } /> }
105
158
</ CustomModal >
106
159
</ >
107
160
) ;
0 commit comments