Skip to content

Commit 7f32600

Browse files
committed
Fix forms
1 parent bbf2152 commit 7f32600

File tree

3 files changed

+7
-14
lines changed

3 files changed

+7
-14
lines changed

site/src/components/Form/index.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FormikContextType, FormikErrors, getIn } from "formik"
1+
import { FormikContextType, getIn } from "formik"
22
import { ChangeEvent, ChangeEventHandler, FocusEventHandler } from "react"
33

44
export * from "./FormCloseButton"
@@ -17,17 +17,10 @@ interface FormHelpers {
1717
helperText?: string
1818
}
1919

20-
export const getFormHelpers = <T>(
21-
form: FormikContextType<T>,
22-
name: string,
23-
additionalErrors: FormikErrors<T> = {},
24-
): FormHelpers => {
20+
export const getFormHelpers = <T>(form: FormikContextType<T>, name: string, error?: string): FormHelpers => {
2521
// getIn is a util function from Formik that gets at any depth of nesting, and is necessary for the types to work
2622
const touched = getIn(form.touched, name)
27-
const errors = {
28-
...getIn(form.errors, name),
29-
...additionalErrors,
30-
}
23+
const errors = error ?? getIn(form.errors, name)
3124
return {
3225
...form.getFieldProps(name),
3326
id: name,

site/src/components/Preferences/AccountForm.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,23 @@ export const AccountForm: React.FC<AccountFormProps> = ({
5555
<form onSubmit={form.handleSubmit}>
5656
<Stack>
5757
<TextField
58-
{...getFormHelpers<AccountFormValues>(form, "name", formErrors)}
58+
{...getFormHelpers<AccountFormValues>(form, "name")}
5959
autoFocus
6060
autoComplete="name"
6161
fullWidth
6262
label={Language.nameLabel}
6363
variant="outlined"
6464
/>
6565
<TextField
66-
{...getFormHelpers<AccountFormValues>(form, "email", formErrors)}
66+
{...getFormHelpers<AccountFormValues>(form, "email", formErrors.email)}
6767
onChange={onChangeTrimmed(form)}
6868
autoComplete="email"
6969
fullWidth
7070
label={Language.emailLabel}
7171
variant="outlined"
7272
/>
7373
<TextField
74-
{...getFormHelpers<AccountFormValues>(form, "username", formErrors)}
74+
{...getFormHelpers<AccountFormValues>(form, "username", formErrors.username)}
7575
onChange={onChangeTrimmed(form)}
7676
autoComplete="username"
7777
fullWidth

site/src/pages/preferences/account.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe("PreferencesAccountPage", () => {
3636
})
3737

3838
describe("when it is a success", () => {
39-
it.only("shows the success message", async () => {
39+
it("shows the success message", async () => {
4040
jest.spyOn(API, "updateProfile").mockImplementationOnce((userId, data) =>
4141
Promise.resolve({
4242
id: userId,

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