Skip to content

Commit

Permalink
Fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
dgcohen committed Dec 20, 2024
2 parents 4876eda + 2d116fe commit c03586a
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- 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 HoldContactButton component and update error copy per VQA requests (SCC-4427)
- 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 @@ -25,6 +25,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 @@ -203,6 +204,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
19 changes: 16 additions & 3 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,10 +76,11 @@ export default function EDDRequestPage({
defaultEligibilityStatus
)

const [eddFormState, setEddFormState] = useState({
const [eddFormState, setEddFormState] = useState<EDDRequestParams>({
...initialEDDFormState,
emailAddress: patronEmail,
patronId,
source: item.source,
source: item.formattedSourceForHoldRequest,
})
const [formPosting, setFormPosting] = useState(false)

Expand Down Expand Up @@ -251,6 +257,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 @@ -260,6 +272,7 @@ export async function getServerSideProps({ params, req, res }) {
discoveryBibResult,
discoveryItemResult,
patronId,
patronEmail,
isAuthenticated,
patronEligibilityStatus,
errorStatus: locationOrEligibilityFetchFailed
Expand Down
2 changes: 1 addition & 1 deletion pages/hold/request/[id]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ export default function HoldRequestPage({
handleSubmit={handleSubmit}
holdId={holdId}
patronId={patronId}
source={item.source}
errorStatus={errorStatus}
source={item.formattedSourceForHoldRequest}
/>
</>
) : null}
Expand Down
5 changes: 5 additions & 0 deletions src/models/Item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
locationEndpointsMap,
} from "../utils/itemUtils"
import { appConfig } from "../config/config"
import { convertCamelToShishKabobCase } from "../utils/appUtils"

/**
* The Item class contains the data and getter functions
Expand Down Expand Up @@ -81,6 +82,10 @@ export default class Item {
.includes("all")
}

get formattedSourceForHoldRequest(): string {
return convertCamelToShishKabobCase(this.source)
}

// Pre-processing logic for setting Item holding location
getLocationFromItem(item: DiscoveryItemResult): ItemLocation {
let location = defaultNYPLLocation
Expand Down
4 changes: 4 additions & 0 deletions src/models/modelTests/Item.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ describe("Item model", () => {
"A history of spaghetti eating and cooking for: spaghetti dinner."
)
})

it("returns the source in kebabcase for use in hold requests", () => {
expect(item.formattedSourceForHoldRequest).toBe("sierra-nypl")
})
})

describe("ReCAP checks", () => {
Expand Down
16 changes: 16 additions & 0 deletions src/utils/appUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,19 @@ export const convertToSentenceCase = (str: string) =>
str.split(" ").length > 1
? str.charAt(0).toUpperCase() + str.slice(1).toLowerCase()
: str

/**
* Converts camel case string to shish kabob case
*
* e.g. camelToShishKabobCase("RecapPul")
* => "recap-pul"
* camelToShishKabobCase("firstCharCanBeLowerCase")
* => "first-char-can-be-lower-case"
*/
export const convertCamelToShishKabobCase = (str: string) =>
str
// Change capital letters into "-{lowercase letter}"
.replace(/([A-Z])/g, (capitalLetter, placeholderVar, index) => {
// If capital letter is not first character, precede with '-':
return (index > 0 ? "-" : "") + capitalLetter.toLowerCase()
})

0 comments on commit c03586a

Please sign in to comment.