diff --git a/pages/hold/request/[id]/edd.tsx b/pages/hold/request/[id]/edd.tsx index 5db829334..334d59393 100644 --- a/pages/hold/request/[id]/edd.tsx +++ b/pages/hold/request/[id]/edd.tsx @@ -74,7 +74,7 @@ export default function EDDRequestPage({ const [eddFormState, setEddFormState] = useState({ ...initialEDDFormState, patronId, - source: item.source, + source: item.formattedSourceForHoldRequest, }) const [formPosting, setFormPosting] = useState(false) diff --git a/pages/hold/request/[id]/index.tsx b/pages/hold/request/[id]/index.tsx index c040feb8b..1313e5c2d 100644 --- a/pages/hold/request/[id]/index.tsx +++ b/pages/hold/request/[id]/index.tsx @@ -180,7 +180,7 @@ export default function HoldRequestPage({ handleSubmit={handleSubmit} holdId={holdId} patronId={patronId} - source={item.source} + source={item.formattedSourceForHoldRequest} /> ) : null} diff --git a/src/models/Item.ts b/src/models/Item.ts index d3c8c8de7..ae4e81a88 100644 --- a/src/models/Item.ts +++ b/src/models/Item.ts @@ -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 @@ -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 diff --git a/src/models/modelTests/Item.test.ts b/src/models/modelTests/Item.test.ts index db080df42..d07e92901 100644 --- a/src/models/modelTests/Item.test.ts +++ b/src/models/modelTests/Item.test.ts @@ -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", () => { diff --git a/src/utils/appUtils.ts b/src/utils/appUtils.ts index 67a1f8dbb..41a4c9e28 100644 --- a/src/utils/appUtils.ts +++ b/src/utils/appUtils.ts @@ -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() + })