@@ -13,6 +13,8 @@ import { FullPageForm } from "../FullPageForm/FullPageForm"
13
13
import { Stack } from "../Stack/Stack"
14
14
import { ErrorAlert } from "components/Alert/ErrorAlert"
15
15
import { hasApiFieldErrors , isApiError } from "api/errors"
16
+ import Select from "@mui/material/Select"
17
+ import MenuItem from "@mui/material/MenuItem"
16
18
17
19
export const Language = {
18
20
emailLabel : "Email" ,
@@ -31,6 +33,7 @@ export interface CreateUserFormProps {
31
33
error ?: unknown
32
34
isLoading : boolean
33
35
myOrgId : string
36
+ authMethods ?: TypesGen . AuthMethods
34
37
}
35
38
36
39
const validationSchema = Yup . object ( {
@@ -42,9 +45,13 @@ const validationSchema = Yup.object({
42
45
username : nameValidator ( Language . usernameLabel ) ,
43
46
} )
44
47
48
+ const authMethodSelect = ( title : string , value : string ) => {
49
+ return < MenuItem value = { value } > { title } </ MenuItem >
50
+ }
51
+
45
52
export const CreateUserForm : FC <
46
53
React . PropsWithChildren < CreateUserFormProps >
47
- > = ( { onSubmit, onCancel, error, isLoading, myOrgId } ) => {
54
+ > = ( { onSubmit, onCancel, error, isLoading, myOrgId, authMethods } ) => {
48
55
const form : FormikContextType < TypesGen . CreateUserRequest > =
49
56
useFormik < TypesGen . CreateUserRequest > ( {
50
57
initialValues : {
@@ -53,7 +60,7 @@ export const CreateUserForm: FC<
53
60
username : "" ,
54
61
organization_id : myOrgId ,
55
62
disable_login : false ,
56
- login_type : "" ,
63
+ login_type : "password " ,
57
64
} ,
58
65
validationSchema,
59
66
onSubmit,
@@ -63,6 +70,18 @@ export const CreateUserForm: FC<
63
70
error ,
64
71
)
65
72
73
+ const methods = [ ]
74
+ if ( authMethods ?. password . enabled ) {
75
+ methods . push ( authMethodSelect ( "Password" , "password" ) )
76
+ }
77
+ if ( authMethods ?. oidc . enabled ) {
78
+ methods . push ( authMethodSelect ( "OIDC" , "oidc" ) )
79
+ }
80
+ if ( authMethods ?. github . enabled ) {
81
+ methods . push ( authMethodSelect ( "Github" , "github" ) )
82
+ }
83
+ methods . push ( authMethodSelect ( "None" , "none" ) )
84
+
66
85
return (
67
86
< FullPageForm title = "Create user" >
68
87
{ isApiError ( error ) && ! hasApiFieldErrors ( error ) && (
@@ -93,6 +112,16 @@ export const CreateUserForm: FC<
93
112
label = { Language . passwordLabel }
94
113
type = "password"
95
114
/>
115
+ < Select
116
+ // {...getFieldHelpers("userLoginType", "ss")}
117
+ labelId = "user-login-type"
118
+ id = "login_type"
119
+ value = { form . values . login_type }
120
+ label = "Login Type"
121
+ onChange = { form . handleChange }
122
+ >
123
+ { methods }
124
+ </ Select >
96
125
</ Stack >
97
126
< FormFooter onCancel = { onCancel } isLoading = { isLoading } />
98
127
</ form >
0 commit comments