1- import { useState } from "react" ;
1+ import { useEffect , useMemo , useState } from "react" ;
22import { messageInstance , CustomSelect , CloseEyeIcon } from "lowcoder-design" ;
33import {
44 CustomModalStyled ,
@@ -10,12 +10,13 @@ import {
1010 SpanStyled ,
1111 PasswordLabel
1212} from "./styledComponents" ;
13- import { Form , Input , Select } from "antd" ;
13+ import { Form , Input , Select , Tooltip } from "antd" ;
1414import IdSourceApi , { ConfigItem } from "api/idSourceApi" ;
1515import { validateResponse } from "api/apiUtils" ;
16- import { authConfig , AuthType } from "./idSourceConstants" ;
16+ import { authConfig , AuthType , clientIdandSecretConfig , ItemType } from "./idSourceConstants" ;
1717import { ServerAuthTypeInfo } from "constants/authConstants" ;
1818import { GeneralLoginIcon } from "assets/icons" ;
19+ import _ from "lodash" ;
1920
2021type CreateModalProp = {
2122 modalVisible : boolean ;
@@ -42,7 +43,11 @@ function CreateModal(props: CreateModalProp) {
4243 }
4344 function saveAuthProvider ( values : ConfigItem ) {
4445 setSaveLoading ( true ) ;
45- IdSourceApi . saveConfig ( values )
46+ const config = {
47+ ...values ,
48+ enableRegister : true ,
49+ }
50+ IdSourceApi . saveConfig ( config )
4651 . then ( ( resp ) => {
4752 if ( validateResponse ( resp ) ) {
4853 messageInstance . success ( trans ( "idSource.saveSuccess" ) ) ;
@@ -69,6 +74,13 @@ function CreateModal(props: CreateModalProp) {
6974 value : config . sourceValue ,
7075 } ) ) ;
7176
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+
7284 return (
7385 < CustomModalStyled
7486 width = "500px"
@@ -115,7 +127,56 @@ function CreateModal(props: CreateModalProp) {
115127 ) ) }
116128 </ CustomSelect >
117129 </ 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
119180 name="clientId"
120181 label="Client ID"
121182 rules={[{ required: true }]}
@@ -147,10 +208,7 @@ function CreateModal(props: CreateModalProp) {
147208 placeholder={trans("idSource.encryptedServer")}
148209 autoComplete="off"
149210 />
150- </ Form . Item >
151- < Form . Item className = "register" name = "enableRegister" valuePropName = "checked" >
152- < CheckboxStyled > { trans ( "idSource.enableRegister" ) } </ CheckboxStyled >
153- </ Form . Item >
211+ </Form.Item> */ }
154212 </ FormStyled >
155213 </ CustomModalStyled >
156214 ) ;
0 commit comments