@@ -38,6 +38,10 @@ import { ItemType } from "pages/setting/idSource/idSourceConstants";
3838import _ from "lodash" ;
3939import { messageInstance } from "lowcoder-design/src/components/GlobalInstances" ;
4040import { 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" ;
4145
4246type IdSourceDetailProps = {
4347 location : Location & { state : ConfigItem } ;
@@ -68,13 +72,32 @@ export const IdSourceDetail = (props: IdSourceDetailProps) => {
6872 if ( ! configDetail ) {
6973 goList ( ) ;
7074 }
71- const handleSuccess = ( values : ConfigItem ) => {
75+ const handleSuccess = ( values : any ) => {
7276 setSaveLoading ( true ) ;
73- const params = {
74- ...values ,
75- ...( configDetail . ifLocal ? null : { id : configDetail . id } ) ,
77+ let params = {
78+ id : configDetail . id ,
7679 authType : configDetail . authType ,
80+ enableRegister : configDetail . enableRegister ,
7781 } ;
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+ }
78101 IdSourceApi . saveConfig ( params )
79102 . then ( ( resp ) => {
80103 if ( validateResponse ( resp ) ) {
@@ -157,14 +180,16 @@ export const IdSourceDetail = (props: IdSourceDetailProps) => {
157180 >
158181 { Object . entries ( authConfig [ configDetail . authType ] . form ) . map ( ( [ key , value ] ) => {
159182 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" ) ;
161185 required = valueObject ? valueObject . isRequire ?? required : required ;
162186 const hasLock = valueObject && valueObject ?. hasLock ;
163187 const tip = valueObject && valueObject . tip ;
164188 const label = valueObject ? valueObject . label : value as string ;
165189 const isList = valueObject && valueObject . isList ;
166190 const isPassword = valueObject && valueObject . isPassword ;
167191 const isIcon = valueObject && valueObject . isIcon ;
192+ const isSwitch = valueObject && valueObject . isSwitch ;
168193 return (
169194 < div key = { key } >
170195 < Form . Item
@@ -208,30 +233,32 @@ export const IdSourceDetail = (props: IdSourceDetailProps) => {
208233 }
209234 autoComplete = { "one-time-code" }
210235 />
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 ? (
223239 < IconPicker
224240 onChange = { ( value ) => form . setFieldValue ( "sourceIcon" , value ) }
225241 label = { 'Source Icon' }
226242 value = { form . getFieldValue ( 'sourceIcon' ) }
227243 />
228- ) : (
244+ ) : isList ? (
229245 < CustomSelect
230246 options = { ( value as ItemType ) . options }
231247 placeholder = { trans ( "idSource.formSelectPlaceholder" , {
232248 label,
233249 } ) }
234250 />
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+ />
235262 ) }
236263 </ Form . Item >
237264 { hasLock && lock && (
@@ -246,6 +273,34 @@ export const IdSourceDetail = (props: IdSourceDetailProps) => {
246273 <CheckboxStyled>{trans("idSource.enableRegister")}</CheckboxStyled>
247274 </Form.Item> */ }
248275
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+
249304 < Form . Item >
250305 < SaveButton loading = { saveLoading } disabled = { saveDisable } htmlType = "submit" >
251306 { configDetail . enable ? trans ( "idSource.save" ) : trans ( "idSource.saveBtn" ) }
0 commit comments