diff --git a/CHANGELOG b/CHANGELOG
index 45ea3529..138b0263 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added fetchPatronEligibility server function that requests a patron's hold request eligibility status from Discovery API (SCC-3762)
- Added patron ineligibility error messaging to HoldRequestErrorBanner component (SCC-3762)
- Added eligibility checks to EDD and on-site request hold pages and API routes (SCC-3762)
+- Added email address field prepopulation on EDD Request form (SCC-4407)
### Updated
diff --git a/__test__/pages/hold/eddRequestPage.test.tsx b/__test__/pages/hold/eddRequestPage.test.tsx
index 68e05bb6..6d114806 100644
--- a/__test__/pages/hold/eddRequestPage.test.tsx
+++ b/__test__/pages/hold/eddRequestPage.test.tsx
@@ -27,6 +27,7 @@ jest.mock("../../../src/server/auth")
jest.mock("../../../src/server/api/bib")
jest.mock("../../../src/server/sierraClient")
jest.mock("../../../src/server/api/hold")
+jest.mock("../../../src/models/MyAccount")
jest.mock("next/router", () => jest.requireActual("next-router-mock"))
@@ -205,6 +206,22 @@ describe("EDD Request page", () => {
expect(screen.getByTestId("edd-request-form")).toBeInTheDocument()
})
})
+ describe("EDD Request prepopulated form fields", () => {
+ beforeEach(() => {
+ render(
+
+ )
+ })
+ it("prepopulates the email field with the patron's email address if present", () => {
+ expect(screen.getByDisplayValue("test@test.com")).toBeInTheDocument()
+ })
+ })
describe("EDD Request form validation", () => {
beforeEach(async () => {
render(
diff --git a/pages/hold/request/[id]/edd.tsx b/pages/hold/request/[id]/edd.tsx
index 5db82933..9e986632 100644
--- a/pages/hold/request/[id]/edd.tsx
+++ b/pages/hold/request/[id]/edd.tsx
@@ -7,6 +7,8 @@ import {
SkeletonLoader,
} from "@nypl/design-system-react-components"
+import sierraClient from "../../../../src/server/sierraClient"
+
import Layout from "../../../../src/components/Layout/Layout"
import EDDRequestForm from "../../../../src/components/HoldPages/EDDRequestForm"
import HoldRequestErrorBanner from "../../../../src/components/HoldPages/HoldRequestErrorBanner"
@@ -16,6 +18,8 @@ import { SITE_NAME, BASE_URL, PATHS } from "../../../../src/config/constants"
import useLoading from "../../../../src/hooks/useLoading"
import { fetchBib } from "../../../../src/server/api/bib"
+import MyAccount from "../../../../src/models/MyAccount"
+
import {
fetchDeliveryLocations,
fetchPatronEligibility,
@@ -43,6 +47,7 @@ interface EDDRequestPropsType {
discoveryBibResult: DiscoveryBibResult
discoveryItemResult: DiscoveryItemResult
patronId: string
+ patronEmail?: string
isAuthenticated?: boolean
errorStatus?: HoldErrorStatus
patronEligibilityStatus?: PatronEligibilityStatus
@@ -55,12 +60,12 @@ export default function EDDRequestPage({
discoveryBibResult,
discoveryItemResult,
patronId,
+ patronEmail,
isAuthenticated,
errorStatus: defaultErrorStatus,
patronEligibilityStatus: defaultEligibilityStatus,
}: EDDRequestPropsType) {
const metadataTitle = `Electronic Delivery Request | ${SITE_NAME}`
-
const bib = new Bib(discoveryBibResult)
const item = new Item(discoveryItemResult, bib)
@@ -71,8 +76,9 @@ export default function EDDRequestPage({
defaultEligibilityStatus
)
- const [eddFormState, setEddFormState] = useState({
+ const [eddFormState, setEddFormState] = useState({
...initialEDDFormState,
+ emailAddress: patronEmail,
patronId,
source: item.source,
})
@@ -250,6 +256,12 @@ export async function getServerSideProps({ params, req, res }) {
const patronEligibilityStatus = await fetchPatronEligibility(patronId)
+ // fetch patron's email to pre-populate the edd form if available
+ const client = await sierraClient()
+ const patronAccount = new MyAccount(client, patronId)
+ const patron = await patronAccount.getPatron()
+ const patronEmail = patron?.emails?.[0]
+
const locationOrEligibilityFetchFailed =
locationStatus !== 200 ||
![200, 401].includes(patronEligibilityStatus?.status)
@@ -259,6 +271,7 @@ export async function getServerSideProps({ params, req, res }) {
discoveryBibResult,
discoveryItemResult,
patronId,
+ patronEmail,
isAuthenticated,
patronEligibilityStatus,
errorStatus: locationOrEligibilityFetchFailed