diff --git a/pages/api/hold/request/[id]/edd.ts b/pages/api/hold/request/[id]/edd.ts index f3aecc7bb..6be152ff4 100644 --- a/pages/api/hold/request/[id]/edd.ts +++ b/pages/api/hold/request/[id]/edd.ts @@ -5,7 +5,7 @@ import { fetchPatronEligibility, } from "../../../../../src/server/api/hold" import { - initialEDDInvalidFields, + defaultValidatedEDDFields, validateEDDForm, eddFormIsInvalid, } from "../../../../../src/utils/holdPageUtils" @@ -28,7 +28,10 @@ async function handler(req: NextApiRequest, res: NextApiResponse) { const holdId = req.query.id as string // Server-side form validation - const validatedFields = validateEDDForm(formState, initialEDDInvalidFields) + const validatedFields = validateEDDForm( + formState, + defaultValidatedEDDFields + ) const [, itemId] = holdId.split("-") diff --git a/src/components/HoldPages/EDDRequestForm.tsx b/src/components/HoldPages/EDDRequestForm.tsx index ecbf3d47d..2e8da2f89 100644 --- a/src/components/HoldPages/EDDRequestForm.tsx +++ b/src/components/HoldPages/EDDRequestForm.tsx @@ -21,7 +21,7 @@ import { validateEDDForm, isInvalidField, holdButtonDisabledStatuses, - initialEDDInvalidFields, + defaultValidatedEDDFields, getFirstInvalidEDDField, } from "../../utils/holdPageUtils" import type { @@ -61,7 +61,7 @@ const EDDRequestForm = ({ // Set the invalid fields as an array in state to keep track of the first invalid field for focus on submit const [invalidFields, setInvalidFields] = useState( - serverValidatedFields || initialEDDInvalidFields + serverValidatedFields || defaultValidatedEDDFields ) // Create refs for fields that require validation to focus on the first invalid field on submit diff --git a/src/utils/holdPageUtils.ts b/src/utils/holdPageUtils.ts index 09f33e84b..5517ddd1c 100644 --- a/src/utils/holdPageUtils.ts +++ b/src/utils/holdPageUtils.ts @@ -23,7 +23,7 @@ export const initialEDDFormState: EDDRequestParams = { } // Initial state for invalid fields in the EDD form to keep track of the first invalid field for focus on submit -export const initialEDDInvalidFields: EDDFormValidatedField[] = [ +export const defaultValidatedEDDFields: EDDFormValidatedField[] = [ { key: "emailAddress", isInvalid: false }, { key: "startPage", isInvalid: false }, { key: "endPage", isInvalid: false }, diff --git a/src/utils/utilsTests/holdPageUtils.test.ts b/src/utils/utilsTests/holdPageUtils.test.ts index 08efa1f56..75538bc29 100644 --- a/src/utils/utilsTests/holdPageUtils.test.ts +++ b/src/utils/utilsTests/holdPageUtils.test.ts @@ -1,5 +1,5 @@ import { - initialEDDInvalidFields, + defaultValidatedEDDFields, getUpdatedInvalidFields, } from "../holdPageUtils" @@ -7,7 +7,11 @@ describe("holdPageUtils", () => { describe("getUpdatedInvalidFields", () => { it("returns correctly updated field validation statuses for different inputs", () => { expect( - getUpdatedInvalidFields("emailAddress", "test", initialEDDInvalidFields) + getUpdatedInvalidFields( + "emailAddress", + "test", + defaultValidatedEDDFields + ) ).toStrictEqual([ { isInvalid: true, key: "emailAddress" }, { isInvalid: false, key: "startPage" }, @@ -18,7 +22,7 @@ describe("holdPageUtils", () => { getUpdatedInvalidFields( "emailAddress", "test@test.com", - initialEDDInvalidFields + defaultValidatedEDDFields ) ).toStrictEqual([ { isInvalid: false, key: "emailAddress" }, @@ -27,7 +31,7 @@ describe("holdPageUtils", () => { { isInvalid: false, key: "chapterTitle" }, ]) expect( - getUpdatedInvalidFields("emailAddress", "", initialEDDInvalidFields) + getUpdatedInvalidFields("emailAddress", "", defaultValidatedEDDFields) ).toStrictEqual([ { isInvalid: true, key: "emailAddress" }, { isInvalid: false, key: "startPage" }, @@ -35,7 +39,7 @@ describe("holdPageUtils", () => { { isInvalid: false, key: "chapterTitle" }, ]) expect( - getUpdatedInvalidFields("startPage", "", initialEDDInvalidFields) + getUpdatedInvalidFields("startPage", "", defaultValidatedEDDFields) ).toStrictEqual([ { isInvalid: false, key: "emailAddress" }, { isInvalid: true, key: "startPage" }, @@ -43,7 +47,7 @@ describe("holdPageUtils", () => { { isInvalid: false, key: "chapterTitle" }, ]) expect( - getUpdatedInvalidFields("endPage", "", initialEDDInvalidFields) + getUpdatedInvalidFields("endPage", "", defaultValidatedEDDFields) ).toStrictEqual([ { isInvalid: false, key: "emailAddress" }, { isInvalid: false, key: "startPage" }, @@ -51,7 +55,7 @@ describe("holdPageUtils", () => { { isInvalid: false, key: "chapterTitle" }, ]) expect( - getUpdatedInvalidFields("chapterTitle", "", initialEDDInvalidFields) + getUpdatedInvalidFields("chapterTitle", "", defaultValidatedEDDFields) ).toStrictEqual([ { isInvalid: false, key: "emailAddress" }, { isInvalid: false, key: "startPage" },