File tree Expand file tree Collapse file tree 3 files changed +7
-14
lines changed Expand file tree Collapse file tree 3 files changed +7
-14
lines changed Original file line number Diff line number Diff line change 1
- import { FormikContextType , FormikErrors , getIn } from "formik"
1
+ import { FormikContextType , getIn } from "formik"
2
2
import { ChangeEvent , ChangeEventHandler , FocusEventHandler } from "react"
3
3
4
4
export * from "./FormCloseButton"
@@ -17,17 +17,10 @@ interface FormHelpers {
17
17
helperText ?: string
18
18
}
19
19
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 => {
25
21
// getIn is a util function from Formik that gets at any depth of nesting, and is necessary for the types to work
26
22
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 )
31
24
return {
32
25
...form . getFieldProps ( name ) ,
33
26
id : name ,
Original file line number Diff line number Diff line change @@ -55,23 +55,23 @@ export const AccountForm: React.FC<AccountFormProps> = ({
55
55
< form onSubmit = { form . handleSubmit } >
56
56
< Stack >
57
57
< TextField
58
- { ...getFormHelpers < AccountFormValues > ( form , "name" , formErrors ) }
58
+ { ...getFormHelpers < AccountFormValues > ( form , "name" ) }
59
59
autoFocus
60
60
autoComplete = "name"
61
61
fullWidth
62
62
label = { Language . nameLabel }
63
63
variant = "outlined"
64
64
/>
65
65
< TextField
66
- { ...getFormHelpers < AccountFormValues > ( form , "email" , formErrors ) }
66
+ { ...getFormHelpers < AccountFormValues > ( form , "email" , formErrors . email ) }
67
67
onChange = { onChangeTrimmed ( form ) }
68
68
autoComplete = "email"
69
69
fullWidth
70
70
label = { Language . emailLabel }
71
71
variant = "outlined"
72
72
/>
73
73
< TextField
74
- { ...getFormHelpers < AccountFormValues > ( form , "username" , formErrors ) }
74
+ { ...getFormHelpers < AccountFormValues > ( form , "username" , formErrors . username ) }
75
75
onChange = { onChangeTrimmed ( form ) }
76
76
autoComplete = "username"
77
77
fullWidth
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ describe("PreferencesAccountPage", () => {
36
36
} )
37
37
38
38
describe ( "when it is a success" , ( ) => {
39
- it . only ( "shows the success message" , async ( ) => {
39
+ it ( "shows the success message" , async ( ) => {
40
40
jest . spyOn ( API , "updateProfile" ) . mockImplementationOnce ( ( userId , data ) =>
41
41
Promise . resolve ( {
42
42
id : userId ,
You can’t perform that action at this time.
0 commit comments