@@ -13,7 +13,6 @@ 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
16
import MenuItem from "@mui/material/MenuItem"
18
17
19
18
export const Language = {
@@ -41,13 +40,18 @@ const validationSchema = Yup.object({
41
40
. trim ( )
42
41
. email ( Language . emailInvalid )
43
42
. required ( Language . emailRequired ) ,
44
- password : Yup . string ( ) . required ( Language . passwordRequired ) ,
43
+ password : Yup . string ( ) . when ( "login_type" , {
44
+ is : "password" ,
45
+ then : ( schema ) => schema . required ( Language . passwordRequired ) ,
46
+ otherwise : ( schema ) => schema ,
47
+ } ) ,
45
48
username : nameValidator ( Language . usernameLabel ) ,
46
49
} )
47
50
48
51
const authMethodSelect = (
49
52
title : string ,
50
53
value : string ,
54
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars -- future will use this
51
55
description : string ,
52
56
) => {
53
57
return (
@@ -138,25 +142,37 @@ export const CreateUserForm: FC<
138
142
label = { Language . emailLabel }
139
143
/>
140
144
< TextField
141
- { ...getFieldHelpers ( "password" ) }
145
+ { ...getFieldHelpers (
146
+ "password" ,
147
+ form . values . login_type === "password"
148
+ ? ""
149
+ : "No password required for this login type" ,
150
+ ) }
142
151
autoComplete = "current-password"
143
152
fullWidth
144
153
id = "password"
154
+ disabled = { form . values . login_type !== "password" }
145
155
label = { Language . passwordLabel }
146
156
type = "password"
147
157
/>
148
- < Select
149
- // {...getFieldHelpers("userLoginType", "ss")}
150
- labelId = "user-login-type"
158
+ < TextField
159
+ { ...getFieldHelpers (
160
+ "login_type" ,
161
+ "Authentication method for this user" ,
162
+ ) }
163
+ select
151
164
id = "login_type"
152
165
value = { form . values . login_type }
153
166
label = "Login Type"
154
167
onChange = { async ( e ) => {
168
+ if ( e . target . value !== "password" ) {
169
+ await form . setFieldValue ( "password" , "" )
170
+ }
155
171
await form . setFieldValue ( "login_type" , e . target . value )
156
172
} }
157
173
>
158
174
{ methods }
159
- </ Select >
175
+ </ TextField >
160
176
</ Stack >
161
177
< FormFooter onCancel = { onCancel } isLoading = { isLoading } />
162
178
</ form >
0 commit comments