Skip to content

Commit

Permalink
Merge pull request #422 from NYPL/SCC-4407/edd-form-autopopulate-patr…
Browse files Browse the repository at this point in the history
…on-email

SCC-4407 - EDD Form Prepopulate Patron Email
  • Loading branch information
dgcohen authored Dec 20, 2024
2 parents a401427 + b3c0972 commit 2d116fe
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 17 additions & 0 deletions __test__/pages/hold/eddRequestPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"))

Expand Down Expand Up @@ -205,6 +206,22 @@ describe("EDD Request page", () => {
expect(screen.getByTestId("edd-request-form")).toBeInTheDocument()
})
})
describe("EDD Request prepopulated form fields", () => {
beforeEach(() => {
render(
<EDDRequestPage
discoveryBibResult={bibWithItems.resource}
discoveryItemResult={bibWithItems.resource.items[2]}
patronId="123"
patronEmail="[email protected]"
isAuthenticated={true}
/>
)
})
it("prepopulates the email field with the patron's email address if present", () => {
expect(screen.getByDisplayValue("[email protected]")).toBeInTheDocument()
})
})
describe("EDD Request form validation", () => {
beforeEach(async () => {
render(
Expand Down
17 changes: 15 additions & 2 deletions pages/hold/request/[id]/edd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand Down Expand Up @@ -43,6 +47,7 @@ interface EDDRequestPropsType {
discoveryBibResult: DiscoveryBibResult
discoveryItemResult: DiscoveryItemResult
patronId: string
patronEmail?: string
isAuthenticated?: boolean
errorStatus?: HoldErrorStatus
patronEligibilityStatus?: PatronEligibilityStatus
Expand All @@ -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)

Expand All @@ -71,8 +76,9 @@ export default function EDDRequestPage({
defaultEligibilityStatus
)

const [eddFormState, setEddFormState] = useState({
const [eddFormState, setEddFormState] = useState<EDDRequestParams>({
...initialEDDFormState,
emailAddress: patronEmail,
patronId,
source: item.formattedSourceForHoldRequest,
})
Expand Down Expand Up @@ -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)
Expand All @@ -259,6 +271,7 @@ export async function getServerSideProps({ params, req, res }) {
discoveryBibResult,
discoveryItemResult,
patronId,
patronEmail,
isAuthenticated,
patronEligibilityStatus,
errorStatus: locationOrEligibilityFetchFailed
Expand Down

0 comments on commit 2d116fe

Please sign in to comment.