Skip to content

Commit d9b857b

Browse files
committed
fix(site): username validation in forms
1 parent 53a55b5 commit d9b857b

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

site/src/components/CreateUserForm/CreateUserForm.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { FormikContextType, FormikErrors, useFormik } from "formik"
44
import React from "react"
55
import * as Yup from "yup"
66
import * as TypesGen from "../../api/typesGenerated"
7-
import { getFormHelpers, onChangeTrimmed } from "../../util/formUtils"
7+
import { getFormHelpers, nameValidator, onChangeTrimmed } from "../../util/formUtils"
88
import { FormFooter } from "../FormFooter/FormFooter"
99
import { FullPageForm } from "../FullPageForm/FullPageForm"
1010

@@ -15,7 +15,6 @@ export const Language = {
1515
emailInvalid: "Please enter a valid email address.",
1616
emailRequired: "Please enter an email address.",
1717
passwordRequired: "Please enter a password.",
18-
usernameRequired: "Please enter a username.",
1918
createUser: "Create",
2019
cancel: "Cancel",
2120
}
@@ -32,7 +31,7 @@ export interface CreateUserFormProps {
3231
const validationSchema = Yup.object({
3332
email: Yup.string().trim().email(Language.emailInvalid).required(Language.emailRequired),
3433
password: Yup.string().required(Language.passwordRequired),
35-
username: Yup.string().required(Language.usernameRequired),
34+
username: nameValidator(Language.usernameLabel),
3635
})
3736

3837
export const CreateUserForm: React.FC<CreateUserFormProps> = ({

site/src/components/SettingsAccountForm/SettingsAccountForm.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import TextField from "@material-ui/core/TextField"
33
import { FormikContextType, FormikErrors, useFormik } from "formik"
44
import React from "react"
55
import * as Yup from "yup"
6-
import { getFormHelpers, onChangeTrimmed } from "../../util/formUtils"
6+
import { getFormHelpers, nameValidator, onChangeTrimmed } from "../../util/formUtils"
77
import { LoadingButton } from "../LoadingButton/LoadingButton"
88
import { Stack } from "../Stack/Stack"
99

@@ -22,7 +22,7 @@ export const Language = {
2222

2323
const validationSchema = Yup.object({
2424
email: Yup.string().trim().email(Language.emailInvalid).required(Language.emailRequired),
25-
username: Yup.string().trim(),
25+
username: nameValidator(Language.usernameLabel),
2626
})
2727

2828
export type AccountFormErrors = FormikErrors<AccountFormValues>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy