Skip to content

Commit c04285c

Browse files
committed
FE
1 parent 5dca493 commit c04285c

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

site/src/components/CreateUserForm/CreateUserForm.tsx

+23-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { FullPageForm } from "../FullPageForm/FullPageForm"
1313
import { Stack } from "../Stack/Stack"
1414
import { ErrorAlert } from "components/Alert/ErrorAlert"
1515
import { hasApiFieldErrors, isApiError } from "api/errors"
16-
import Select from "@mui/material/Select"
1716
import MenuItem from "@mui/material/MenuItem"
1817

1918
export const Language = {
@@ -41,13 +40,18 @@ const validationSchema = Yup.object({
4140
.trim()
4241
.email(Language.emailInvalid)
4342
.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+
}),
4548
username: nameValidator(Language.usernameLabel),
4649
})
4750

4851
const authMethodSelect = (
4952
title: string,
5053
value: string,
54+
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- future will use this
5155
description: string,
5256
) => {
5357
return (
@@ -138,25 +142,37 @@ export const CreateUserForm: FC<
138142
label={Language.emailLabel}
139143
/>
140144
<TextField
141-
{...getFieldHelpers("password")}
145+
{...getFieldHelpers(
146+
"password",
147+
form.values.login_type === "password"
148+
? ""
149+
: "No password required for this login type",
150+
)}
142151
autoComplete="current-password"
143152
fullWidth
144153
id="password"
154+
disabled={form.values.login_type !== "password"}
145155
label={Language.passwordLabel}
146156
type="password"
147157
/>
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
151164
id="login_type"
152165
value={form.values.login_type}
153166
label="Login Type"
154167
onChange={async (e) => {
168+
if (e.target.value !== "password") {
169+
await form.setFieldValue("password", "")
170+
}
155171
await form.setFieldValue("login_type", e.target.value)
156172
}}
157173
>
158174
{methods}
159-
</Select>
175+
</TextField>
160176
</Stack>
161177
<FormFooter onCancel={onCancel} isLoading={isLoading} />
162178
</form>

0 commit comments

Comments
 (0)