@@ -38,6 +38,10 @@ import { ItemType } from "pages/setting/idSource/idSourceConstants";
38
38
import _ from "lodash" ;
39
39
import { messageInstance } from "lowcoder-design/src/components/GlobalInstances" ;
40
40
import { IconPicker } from "@lowcoder-ee/comps/controls/iconControl" ;
41
+ import Switch from "antd/es/switch" ;
42
+ import Title from "antd/es/typography/Title" ;
43
+ import { sourceMappingKeys } from "../OAuthForms/GenericOAuthForm" ;
44
+ import Flex from "antd/es/flex" ;
41
45
42
46
type IdSourceDetailProps = {
43
47
location : Location & { state : ConfigItem } ;
@@ -68,13 +72,32 @@ export const IdSourceDetail = (props: IdSourceDetailProps) => {
68
72
if ( ! configDetail ) {
69
73
goList ( ) ;
70
74
}
71
- const handleSuccess = ( values : ConfigItem ) => {
75
+ const handleSuccess = ( values : any ) => {
72
76
setSaveLoading ( true ) ;
73
- const params = {
74
- ...values ,
75
- ...( configDetail . ifLocal ? null : { id : configDetail . id } ) ,
77
+ let params = {
78
+ id : configDetail . id ,
76
79
authType : configDetail . authType ,
80
+ enableRegister : configDetail . enableRegister ,
77
81
} ;
82
+
83
+ if ( configDetail . authType === AuthType . Generic ) {
84
+ const { uid, email, avatar, username, ...newValues } = values ;
85
+ params = {
86
+ ...newValues ,
87
+ sourceMappings : {
88
+ uid,
89
+ email,
90
+ avatar,
91
+ username,
92
+ } ,
93
+ ...params ,
94
+ }
95
+ } else {
96
+ params = {
97
+ ...values ,
98
+ ...params ,
99
+ }
100
+ }
78
101
IdSourceApi . saveConfig ( params )
79
102
. then ( ( resp ) => {
80
103
if ( validateResponse ( resp ) ) {
@@ -157,14 +180,16 @@ export const IdSourceDetail = (props: IdSourceDetailProps) => {
157
180
>
158
181
{ Object . entries ( authConfig [ configDetail . authType ] . form ) . map ( ( [ key , value ] ) => {
159
182
const valueObject = _ . isObject ( value ) ? ( value as ItemType ) : false ;
160
- let required = configDetail . ifLocal || ( key !== "clientSecret" && key !== "publicKey" ) ;
183
+ // let required = configDetail.ifLocal || (key !== "clientSecret" && key !== "publicKey");
184
+ let required = ( key === "clientId" || key === "clientSecret" || key === "scope" ) ;
161
185
required = valueObject ? valueObject . isRequire ?? required : required ;
162
186
const hasLock = valueObject && valueObject ?. hasLock ;
163
187
const tip = valueObject && valueObject . tip ;
164
188
const label = valueObject ? valueObject . label : value as string ;
165
189
const isList = valueObject && valueObject . isList ;
166
190
const isPassword = valueObject && valueObject . isPassword ;
167
191
const isIcon = valueObject && valueObject . isIcon ;
192
+ const isSwitch = valueObject && valueObject . isSwitch ;
168
193
return (
169
194
< div key = { key } >
170
195
< Form . Item
@@ -208,30 +233,32 @@ export const IdSourceDetail = (props: IdSourceDetailProps) => {
208
233
}
209
234
autoComplete = { "one-time-code" }
210
235
/>
211
- ) : ! isPassword && ! isList && ! isIcon ? (
212
- < Input
213
- placeholder = { trans ( "idSource.formPlaceholder" , {
214
- label,
215
- } ) }
216
- disabled = { hasLock && lock }
217
- prefix = {
218
- hasLock &&
219
- ( lock ? < LockIcon onClick = { ( ) => handleLockClick ( ) } /> : < UnLockIcon /> )
220
- }
221
- />
222
- ) : ! isPassword && ! isList && isIcon ? (
236
+ ) : isSwitch ? (
237
+ < Switch />
238
+ ) : isIcon ? (
223
239
< IconPicker
224
240
onChange = { ( value ) => form . setFieldValue ( "sourceIcon" , value ) }
225
241
label = { 'Source Icon' }
226
242
value = { form . getFieldValue ( 'sourceIcon' ) }
227
243
/>
228
- ) : (
244
+ ) : isList ? (
229
245
< CustomSelect
230
246
options = { ( value as ItemType ) . options }
231
247
placeholder = { trans ( "idSource.formSelectPlaceholder" , {
232
248
label,
233
249
} ) }
234
250
/>
251
+ ) : (
252
+ < Input
253
+ placeholder = { trans ( "idSource.formPlaceholder" , {
254
+ label,
255
+ } ) }
256
+ disabled = { hasLock && lock }
257
+ prefix = {
258
+ hasLock &&
259
+ ( lock ? < LockIcon onClick = { ( ) => handleLockClick ( ) } /> : < UnLockIcon /> )
260
+ }
261
+ />
235
262
) }
236
263
</ Form . Item >
237
264
{ hasLock && lock && (
@@ -246,6 +273,34 @@ export const IdSourceDetail = (props: IdSourceDetailProps) => {
246
273
<CheckboxStyled>{trans("idSource.enableRegister")}</CheckboxStyled>
247
274
</Form.Item> */ }
248
275
276
+ { configDetail . authType === AuthType . Generic && (
277
+ < >
278
+ < Title level = { 5 } > Source Mappings</ Title >
279
+ { sourceMappingKeys . map ( sourceKey => (
280
+ < Flex gap = "10px" align = "start" key = { sourceKey } >
281
+ < Input
282
+ readOnly
283
+ disabled
284
+ value = { sourceKey }
285
+ style = { { flex : 1 } }
286
+ />
287
+ < span > → </ span >
288
+ < Form . Item
289
+ name = { sourceKey }
290
+ rules = { [ { required : true } ] }
291
+ style = { { flex : 1 } }
292
+ >
293
+ < Input
294
+ placeholder = { trans ( "idSource.formPlaceholder" , {
295
+ label : sourceKey ,
296
+ } ) }
297
+ />
298
+ </ Form . Item >
299
+ </ Flex >
300
+ ) ) }
301
+ </ >
302
+ ) }
303
+
249
304
< Form . Item >
250
305
< SaveButton loading = { saveLoading } disabled = { saveDisable } htmlType = "submit" >
251
306
{ configDetail . enable ? trans ( "idSource.save" ) : trans ( "idSource.saveBtn" ) }
0 commit comments