1
- import { useState } from "react" ;
1
+ import { useEffect , useMemo , useState } from "react" ;
2
2
import { messageInstance , CustomSelect , CloseEyeIcon } from "lowcoder-design" ;
3
3
import {
4
4
CustomModalStyled ,
@@ -10,12 +10,13 @@ import {
10
10
SpanStyled ,
11
11
PasswordLabel
12
12
} from "./styledComponents" ;
13
- import { Form , Input , Select } from "antd" ;
13
+ import { Form , Input , Select , Tooltip } from "antd" ;
14
14
import IdSourceApi , { ConfigItem } from "api/idSourceApi" ;
15
15
import { validateResponse } from "api/apiUtils" ;
16
- import { authConfig , AuthType } from "./idSourceConstants" ;
16
+ import { authConfig , AuthType , clientIdandSecretConfig , ItemType } from "./idSourceConstants" ;
17
17
import { ServerAuthTypeInfo } from "constants/authConstants" ;
18
18
import { GeneralLoginIcon } from "assets/icons" ;
19
+ import _ from "lodash" ;
19
20
20
21
type CreateModalProp = {
21
22
modalVisible : boolean ;
@@ -42,7 +43,11 @@ function CreateModal(props: CreateModalProp) {
42
43
}
43
44
function saveAuthProvider ( values : ConfigItem ) {
44
45
setSaveLoading ( true ) ;
45
- IdSourceApi . saveConfig ( values )
46
+ const config = {
47
+ ...values ,
48
+ enableRegister : true ,
49
+ }
50
+ IdSourceApi . saveConfig ( config )
46
51
. then ( ( resp ) => {
47
52
if ( validateResponse ( resp ) ) {
48
53
messageInstance . success ( trans ( "idSource.saveSuccess" ) ) ;
@@ -69,6 +74,13 @@ function CreateModal(props: CreateModalProp) {
69
74
value : config . sourceValue ,
70
75
} ) ) ;
71
76
77
+ const selectedAuthType = Form . useWatch ( 'authType' , form ) ; ;
78
+
79
+ const authConfigForm = useMemo ( ( ) => {
80
+ if ( ! authConfig [ selectedAuthType ] ) return clientIdandSecretConfig ;
81
+ return authConfig [ selectedAuthType ] . form ;
82
+ } , [ selectedAuthType ] )
83
+
72
84
return (
73
85
< CustomModalStyled
74
86
width = "500px"
@@ -115,7 +127,56 @@ function CreateModal(props: CreateModalProp) {
115
127
) ) }
116
128
</ CustomSelect >
117
129
</ Form . Item >
118
- < Form . Item
130
+ { Object . entries ( authConfigForm ) . map ( ( [ key , value ] ) => {
131
+ const valueObject = _ . isObject ( value ) ? ( value as ItemType ) : false ;
132
+ const required = true ;
133
+ const label = valueObject ? valueObject . label : value ;
134
+ const tip = valueObject && valueObject . tip ;
135
+ const isPassword = valueObject && valueObject . isPassword ;
136
+ return (
137
+ < div key = { key } >
138
+ < Form . Item
139
+ key = { key }
140
+ name = { key }
141
+ rules = { [
142
+ {
143
+ required,
144
+ message : trans ( "idSource.formPlaceholder" , {
145
+ label,
146
+ } ) ,
147
+ } ,
148
+ ] }
149
+ label = {
150
+ isPassword ? (
151
+ < PasswordLabel >
152
+ < span > { label } :</ span >
153
+ < CloseEyeIcon />
154
+ </ PasswordLabel >
155
+ ) : (
156
+ < Tooltip title = { tip } >
157
+ < span className = { tip ? "has-tip" : "" } > { label } </ span > :
158
+ </ Tooltip >
159
+ )
160
+ }
161
+ >
162
+ { isPassword ? (
163
+ < Input
164
+ type = { "password" }
165
+ placeholder = { trans ( "idSource.encryptedServer" ) }
166
+ autoComplete = { "one-time-code" }
167
+ />
168
+ ) : (
169
+ < Input
170
+ placeholder = { trans ( "idSource.formPlaceholder" , {
171
+ label,
172
+ } ) }
173
+ />
174
+ ) }
175
+ </ Form . Item >
176
+ </ div >
177
+ ) ;
178
+ } ) }
179
+ { /* <Form.Item
119
180
name="clientId"
120
181
label="Client ID"
121
182
rules={[{ required: true }]}
@@ -147,10 +208,7 @@ function CreateModal(props: CreateModalProp) {
147
208
placeholder={trans("idSource.encryptedServer")}
148
209
autoComplete="off"
149
210
/>
150
- </ Form . Item >
151
- < Form . Item className = "register" name = "enableRegister" valuePropName = "checked" >
152
- < CheckboxStyled > { trans ( "idSource.enableRegister" ) } </ CheckboxStyled >
153
- </ Form . Item >
211
+ </Form.Item> */ }
154
212
</ FormStyled >
155
213
</ CustomModalStyled >
156
214
) ;
0 commit comments