Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ac8d240

Browse files
committed
Replace third arg to getFieldHelpers -is used after all
1 parent 2a09e42 commit ac8d240

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

site/src/pages/TemplateSettingsPage/TemplateSettingsPage.test.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ import { UpdateTemplateMeta } from "api/typesGenerated"
55
import { Language as FooterFormLanguage } from "components/FormFooter/FormFooter"
66
import { MockTemplate } from "../../testHelpers/entities"
77
import { renderWithAuth } from "../../testHelpers/renderHelpers"
8-
import {
9-
getValidationSchema,
10-
} from "./TemplateSettingsForm"
8+
import { getValidationSchema } from "./TemplateSettingsForm"
119
import { TemplateSettingsPage } from "./TemplateSettingsPage"
1210
import i18next from "i18next"
1311

@@ -53,9 +51,7 @@ const fillAndSubmitForm = async ({
5351
await userEvent.type(displayNameField, display_name)
5452

5553
const descriptionLabel = t("descriptionLabel", { ns: "templateSettingsPage" })
56-
const descriptionField = await screen.findByLabelText(
57-
descriptionLabel,
58-
)
54+
const descriptionField = await screen.findByLabelText(descriptionLabel)
5955
await userEvent.clear(descriptionField)
6056
await userEvent.type(descriptionField, description)
6157

@@ -161,7 +157,9 @@ describe("TemplateSettingsPage", () => {
161157
default_ttl_ms: 24 * 7 + 1,
162158
}
163159
const validate = () => getValidationSchema().validateSync(values)
164-
expect(validate).toThrowError(t("ttlMaxError", { ns: "templateSettingsPage" }))
160+
expect(validate).toThrowError(
161+
t("ttlMaxError", { ns: "templateSettingsPage" }),
162+
)
165163
})
166164

167165
it("allows a description of 128 chars", () => {
@@ -181,6 +179,8 @@ describe("TemplateSettingsPage", () => {
181179
"Nam quis nulla. Integer malesuada. In in enim a arcu imperdiet malesuada. Sed vel lectus. Donec odio urna, tempus molestie, port a",
182180
}
183181
const validate = () => getValidationSchema().validateSync(values)
184-
expect(validate).toThrowError(t("descriptionMaxError", { ns: "templateSettingsPage" }))
182+
expect(validate).toThrowError(
183+
t("descriptionMaxError", { ns: "templateSettingsPage" }),
184+
)
185185
})
186186
})

site/src/util/formUtils.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ interface FormHelpers {
3939

4040
export const getFormHelpers =
4141
<T>(form: FormikContextType<T>, error?: Error | unknown) =>
42-
(name: keyof T, HelperText: ReactNode = ""): FormHelpers => {
42+
(
43+
name: keyof T,
44+
HelperText: ReactNode = "",
45+
backendErrorName?: string,
46+
): FormHelpers => {
4347
const apiValidationErrors =
4448
isApiError(error) && hasApiFieldErrors(error)
4549
? (mapApiErrorToFieldErrors(error.response.data) as FormikErrors<T>)
@@ -50,10 +54,12 @@ export const getFormHelpers =
5054
)
5155
}
5256

57+
const apiErrorName = backendErrorName ?? name
58+
5359
// getIn is a util function from Formik that gets at any depth of nesting
5460
// and is necessary for the types to work
5561
const touched = getIn(form.touched, name)
56-
const apiError = getIn(apiValidationErrors, name)
62+
const apiError = getIn(apiValidationErrors, apiErrorName)
5763
const frontendError = getIn(form.errors, name)
5864
const returnError = apiError ?? frontendError
5965
return {

0 commit comments

Comments
 (0)