17
17
*/
18
18
19
19
import { useRequiredScopes } from "@wso2is/access-control" ;
20
+ import Box from "@oxygen-ui/react/Box" ;
21
+ import InputAdornment from "@oxygen-ui/react/InputAdornment" ;
20
22
import { AppConstants } from "@wso2is/admin.core.v1/constants/app-constants" ;
21
23
import { history } from "@wso2is/admin.core.v1/helpers/history" ;
22
24
import { FeatureConfigInterface } from "@wso2is/admin.core.v1/models/config" ;
@@ -32,6 +34,7 @@ import {
32
34
DangerZoneGroup ,
33
35
DocumentationLink ,
34
36
EmphasizedSegment ,
37
+ Heading ,
35
38
PageLayout ,
36
39
PrimaryButton ,
37
40
SecondaryButton ,
@@ -49,9 +52,13 @@ import React, {
49
52
import { Trans , useTranslation } from "react-i18next" ;
50
53
import { useDispatch , useSelector } from "react-redux" ;
51
54
import { Dispatch } from "redux" ;
52
- import { Divider , Grid , Placeholder , Ref } from "semantic-ui-react" ;
55
+ import { Divider , DropdownProps , Grid , Placeholder , Ref , Icon } from "semantic-ui-react" ;
53
56
import { deleteEmailProviderConfigurations , updateEmailProviderConfigurations , useEmailProviderConfig } from "../api" ;
54
- import { EmailProviderConstants } from "../constants" ;
57
+ import {
58
+ AuthenticationTypeDropdownOption ,
59
+ AuthenticationType ,
60
+ EmailProviderConstants
61
+ } from "../constants" ;
55
62
import {
56
63
EmailProviderConfigAPIResponseInterface ,
57
64
EmailProviderConfigFormErrorValidationsInterface ,
@@ -101,6 +108,10 @@ const EmailProvidersPage: FunctionComponent<EmailProvidersPageInterface> = (
101
108
error : emailProviderConfigFetchRequestError
102
109
} = useEmailProviderConfig ( ) ;
103
110
111
+ const [ endpointAuthType , setEndpointAuthType ] = useState < AuthenticationType > ( null ) ;
112
+ const [ showPrimarySecret , setShowPrimarySecret ] = useState < boolean > ( false ) ;
113
+ const [ showSecondarySecret , setShowSecondarySecret ] = useState < boolean > ( false ) ;
114
+
104
115
useEffect ( ( ) => {
105
116
if ( originalEmailProviderConfig instanceof IdentityAppsApiException || emailProviderConfigFetchRequestError ) {
106
117
handleRetrieveError ( ) ;
@@ -138,6 +149,148 @@ const EmailProvidersPage: FunctionComponent<EmailProvidersPageInterface> = (
138
149
}
139
150
} , [ originalEmailProviderConfig ] ) ;
140
151
152
+
153
+ const renderInputAdornmentOfSecret = ( showSecret : boolean , onClick : ( ) => void ) : ReactElement => (
154
+ < InputAdornment position = "end" >
155
+ < Icon
156
+ link = { true }
157
+ className = "list-icon reset-field-to-default-adornment"
158
+ size = "small"
159
+ color = "grey"
160
+ name = { ! showSecret ? "eye" : "eye slash" }
161
+ data-componentid = { `${ componentId } -endpoint-authentication-property-secret-view-button` }
162
+ onClick = { onClick }
163
+ />
164
+ </ InputAdornment >
165
+ ) ;
166
+
167
+ /**
168
+ * This method renders property fields of each endpoint authentication type.
169
+ *
170
+ * @returns property fields of the selected authentication type.
171
+ */
172
+ const renderEndpointAuthPropertyFields = ( ) : ReactElement => {
173
+ switch ( endpointAuthType ) {
174
+ case AuthenticationType . BASIC :
175
+ return (
176
+ < >
177
+ < Field . Input
178
+ ariaLabel = "username"
179
+ className = "addon-field-wrapper"
180
+ name = "usernameAuthProperty"
181
+ label = { t (
182
+ "customAuthenticator:fields.createWizard.configurationsStep." +
183
+ "authenticationTypeDropdown.authProperties.username.label"
184
+ ) }
185
+ placeholder = { t (
186
+ "customAuthenticator:fields.createWizard.configurationsStep." +
187
+ "authenticationTypeDropdown.authProperties.username.placeholder"
188
+ ) }
189
+ inputType = "password"
190
+ type = { showPrimarySecret ? "text" : "password" }
191
+ InputProps = { {
192
+ endAdornment : renderInputAdornmentOfSecret ( showPrimarySecret , ( ) =>
193
+ setShowPrimarySecret ( ! showPrimarySecret )
194
+ )
195
+ } }
196
+ required = { true }
197
+ maxLength = { 100 }
198
+ minLength = { 0 }
199
+ data-componentid = { `${ componentId } -endpoint-authentication-property-username` }
200
+ width = { 15 }
201
+ />
202
+ < Field . Input
203
+ ariaLabel = "password"
204
+ className = "addon-field-wrapper"
205
+ label = { t (
206
+ "customAuthenticator:fields.createWizard.configurationsStep." +
207
+ "authenticationTypeDropdown.authProperties.password.label"
208
+ ) }
209
+ placeholder = { t (
210
+ "customAuthenticator:fields.createWizard.configurationsStep." +
211
+ "authenticationTypeDropdown.authProperties.password.placeholder"
212
+ ) }
213
+ name = "passwordAuthProperty"
214
+ inputType = "password"
215
+ type = { showSecondarySecret ? "text" : "password" }
216
+ InputProps = { {
217
+ endAdornment : renderInputAdornmentOfSecret ( showSecondarySecret , ( ) =>
218
+ setShowSecondarySecret ( ! showSecondarySecret )
219
+ )
220
+ } }
221
+ required = { true }
222
+ maxLength = { 100 }
223
+ minLength = { 0 }
224
+ data-componentid = { `${ componentId } -endpoint-authentication-property-password` }
225
+ width = { 15 }
226
+ />
227
+ </ >
228
+ ) ;
229
+ case AuthenticationType . CLIENT_CREDENTIAL :
230
+ return (
231
+ < >
232
+ < Field . Input
233
+ ariaLabel = "clientID"
234
+ className = "addon-field-wrapper"
235
+ name = "clientIDAuthProperty"
236
+ inputType = "text"
237
+ type = { "text" }
238
+ label = { t (
239
+ "customAuthenticator:fields.createWizard.configurationsStep." +
240
+ "authenticationTypeDropdown.authProperties.header.label"
241
+ ) }
242
+ placeholder = { t (
243
+ "customAuthenticator:fields.createWizard.configurationsStep." +
244
+ "authenticationTypeDropdown.authProperties.header.placeholder"
245
+ ) }
246
+ required = { true }
247
+ maxLength = { 100 }
248
+ minLength = { 0 }
249
+ data-componentid = { `${ componentId } -endpoint-authentication-property-header` }
250
+ width = { 15 }
251
+ />
252
+ < Field . Input
253
+ ariaLabel = "value"
254
+ className = "addon-field-wrapper"
255
+ name = "valueAuthProperty"
256
+ inputType = "password"
257
+ type = { showSecondarySecret ? "text" : "password" }
258
+ InputProps = { {
259
+ endAdornment : renderInputAdornmentOfSecret ( showSecondarySecret , ( ) =>
260
+ setShowSecondarySecret ( ! showSecondarySecret )
261
+ )
262
+ } }
263
+ label = { t (
264
+ "customAuthenticator:fields.createWizard.configurationsStep." +
265
+ "authenticationTypeDropdown.authProperties.value.label"
266
+ ) }
267
+ placeholder = { t (
268
+ "customAuthenticator:fields.createWizard.configurationsStep." +
269
+ "authenticationTypeDropdown.authProperties.value.placeholder"
270
+ ) }
271
+ required = { true }
272
+ maxLength = { 100 }
273
+ minLength = { 0 }
274
+ data-componentid = { `${ componentId } -endpoint-authentication-property-value` }
275
+ width = { 15 }
276
+ />
277
+ </ >
278
+ ) ;
279
+ default :
280
+ break ;
281
+ }
282
+ } ;
283
+
284
+ /**
285
+ * This method handles authentication type dropdown changes.
286
+ *
287
+ * @param event - event associated with the dropdown change.
288
+ * @param data - data changed by the event
289
+ */
290
+ const handleDropdownChange = ( event : React . MouseEvent < HTMLAnchorElement > , data : DropdownProps ) => {
291
+ setEndpointAuthType ( data . value as AuthenticationType ) ;
292
+ } ;
293
+
141
294
/**
142
295
* Displays the error banner when unable to fetch email provider configuration.
143
296
*/
@@ -635,7 +788,7 @@ const EmailProvidersPage: FunctionComponent<EmailProvidersPageInterface> = (
635
788
/>
636
789
</ Grid . Column >
637
790
</ Grid . Row >
638
- < Grid . Row columns = { 2 } key = { 3 } >
791
+ { /* <Grid.Row columns={ 2 } key={ 3 }>
639
792
<Grid.Column key="userName">
640
793
<Field.Input
641
794
ariaLabel="Username Field"
@@ -687,7 +840,7 @@ const EmailProvidersPage: FunctionComponent<EmailProvidersPageInterface> = (
687
840
autoComplete="new-password"
688
841
/>
689
842
</Grid.Column>
690
- </ Grid . Row >
843
+ </Grid.Row> */ }
691
844
< Grid . Row columns = { 2 } key = { 3 } >
692
845
< Grid . Column key = "displayName" >
693
846
< Field . Input
@@ -716,6 +869,39 @@ const EmailProvidersPage: FunctionComponent<EmailProvidersPageInterface> = (
716
869
</ Grid . Column >
717
870
</ Grid . Row >
718
871
</ Grid >
872
+
873
+ < Divider className = "divider-container" />
874
+ < Heading className = "heading-container" as = "h5" >
875
+ { t ( "emailProviders:fields.authenticationTypeDropdown.title" ) }
876
+ </ Heading >
877
+ < Box className = "box-container" >
878
+ < Field . Dropdown
879
+ ariaLabel = "authenticationType"
880
+ name = "authenticationType"
881
+ label = { t (
882
+ "emailProviders:fields.authenticationTypeDropdown.label"
883
+ ) }
884
+ placeholder = { t (
885
+ "emailProviders:fields.authenticationTypeDropdown.placeholder"
886
+ ) }
887
+ hint = { t (
888
+ "emailProviders:fields.authenticationTypeDropdown.hint"
889
+ ) }
890
+ required = { true }
891
+ value = { endpointAuthType }
892
+ options = { [
893
+ ...EmailProviderConstants . AUTH_TYPES . map ( ( option : AuthenticationTypeDropdownOption ) => ( {
894
+ text : t ( option . text ) ,
895
+ value : option . value . toString ( )
896
+ } ) )
897
+ ] }
898
+ onChange = { handleDropdownChange }
899
+ enableReinitialize = { true }
900
+ data-componentid = { `${ componentId } -create-wizard-endpoint-authentication-dropdown` }
901
+ width = { 15 }
902
+ />
903
+ < div className = "box-field" > { renderEndpointAuthPropertyFields ( ) } </ div >
904
+ </ Box >
719
905
</ Form >
720
906
{
721
907
hasEmailProviderUpdatePermissions && (
0 commit comments