diff --git a/CHANGELOG.md b/CHANGELOG.md index 173558b1c5..8f22936d2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,8 @@ All notable changes to this project will be documented in this file. The format - **Breaking Change**: Removed ListingsList component and replaced with more generalizable ListingCard component which represents the image and table for one listing - Remove formatIncome helper from ui-components ([#1744](https://github.com/bloom-housing/bloom/pull/1744)) (Emily Jablonski) - **Breaking Change** + - Removed business logic from HouseholdMemberForm component ([#1722](https://github.com/bloom-housing/bloom/pull/1722)) (Emily Jablonski) + - **Breaking Change**: Removed existing props except for editMode and replaced with a set not dependent on data model ### Backend diff --git a/sites/public/pages/applications/household/add-members.tsx b/sites/public/pages/applications/household/add-members.tsx index 87911f0290..52d2d75015 100644 --- a/sites/public/pages/applications/household/add-members.tsx +++ b/sites/public/pages/applications/household/add-members.tsx @@ -41,12 +41,26 @@ const ApplicationAddMembers = () => { const applicant = application.applicant - const membersSection = application.householdMembers.map((member) => { + const editMember = (orderId: number) => { + if (orderId != undefined && orderId >= 0) { + void router.push({ + pathname: "/applications/household/member", + query: { memberId: orderId }, + }) + } else { + void router.push("/applications/contact/name") + } + } + + const membersSection = application.householdMembers.map((member, index) => { return ( ) }) @@ -91,9 +105,11 @@ const ApplicationAddMembers = () => {
{membersSection}
diff --git a/ui-components/__tests__/forms/HouseholdMemberForm.test.tsx b/ui-components/__tests__/forms/HouseholdMemberForm.test.tsx index 948b71769b..e378c97ff9 100644 --- a/ui-components/__tests__/forms/HouseholdMemberForm.test.tsx +++ b/ui-components/__tests__/forms/HouseholdMemberForm.test.tsx @@ -1,22 +1,10 @@ import React from "react" import { render, cleanup, fireEvent } from "@testing-library/react" import { HouseholdMemberForm } from "../../src/forms/HouseholdMemberForm" -import { HouseholdMember } from "@bloom-housing/backend-core/types" import { t } from "../../src/helpers/translator" afterEach(cleanup) -const Member1 = ({ - firstName: "Breana", - lastName: "Oquendo", -} as unknown) as HouseholdMember - -const Member2 = ({ - firstName: "Sonja", - lastName: "Aldenkamp", - orderId: 1234, -} as unknown) as HouseholdMember - describe("", () => { const useContext = jest.spyOn(require("react"), "useContext") @@ -24,29 +12,40 @@ describe("", () => { const router = { push: jest.fn().mockImplementation(() => Promise.resolve()) } useContext.mockReturnValue({ router }) global.scrollTo = jest.fn() + const editMemberSpy = jest.fn() const { getByText } = render( - + ) - expect(getByText(t("application.household.primaryApplicant"))).toBeTruthy() + expect(getByText("Primary Applicant")).toBeTruthy() expect(getByText("Breana Oquendo")).toBeTruthy() fireEvent.click(getByText(t("t.edit"))) - expect(router.push).toHaveBeenCalledWith("/applications/contact/name") + expect(editMemberSpy).toHaveBeenCalledTimes(1) }) it("renders as a household member", () => { const router = { push: jest.fn().mockImplementation(() => Promise.resolve()) } useContext.mockReturnValue({ router }) global.scrollTo = jest.fn() + const editMemberSpy = jest.fn() const { getByText } = render( - + ) expect(getByText(t("application.household.householdMember"))).toBeTruthy() expect(getByText("Sonja Aldenkamp")).toBeTruthy() fireEvent.click(getByText(t("t.edit"))) - expect(router.push).toHaveBeenCalledWith({ - pathname: "/applications/household/member", - query: { memberId: 1234 }, - }) + expect(editMemberSpy).toHaveBeenCalledTimes(1) }) }) diff --git a/ui-components/src/forms/HouseholdMemberForm.stories.tsx b/ui-components/src/forms/HouseholdMemberForm.stories.tsx new file mode 100644 index 0000000000..acbabc2b7f --- /dev/null +++ b/ui-components/src/forms/HouseholdMemberForm.stories.tsx @@ -0,0 +1,27 @@ +import * as React from "react" +import HouseholdMemberForm from "./HouseholdMemberForm" + +export default { + title: "Forms/HouseholdMemberForm", + decorators: [(storyFn: any) =>
{storyFn()}
], +} + +export const editable = () => ( + {}} + /> +) + +export const notEditable = () => ( + +) diff --git a/ui-components/src/forms/HouseholdMemberForm.tsx b/ui-components/src/forms/HouseholdMemberForm.tsx index 6c18557811..367c6a2330 100644 --- a/ui-components/src/forms/HouseholdMemberForm.tsx +++ b/ui-components/src/forms/HouseholdMemberForm.tsx @@ -1,36 +1,31 @@ -import React, { useContext } from "react" -import { NavigationContext } from "../config/NavigationContext" -import { HouseholdMemberUpdate } from "@bloom-housing/backend-core/types" +import React from "react" import { t } from "../helpers/translator" import { Icon, IconFillColors } from "../icons/Icon" import { ViewItem } from "../blocks/ViewItem" -const HouseholdMemberForm = (props: { - member: HouseholdMemberUpdate - type: string +export interface HouseholdMemberFormProps { + editMember?: (memberId: number | undefined) => void editMode?: boolean -}) => { - const { member, type } = props - const { router } = useContext(NavigationContext) - const editMode = props.editMode !== false // undefined should default to true + memberFirstName: string + memberId?: number + memberLastName: string + subtitle: string +} + +const HouseholdMemberForm = (props: HouseholdMemberFormProps) => { + const editMode = props.editMode !== false && props.editMember // undefined should default to true - const editMember = () => { - if (member.orderId != undefined && member.orderId >= 0) { - void router.push({ - pathname: "/applications/household/member", - query: { memberId: member.orderId }, - }) - } else { - void router.push("/applications/contact/name") - } - } return ( - - {member.firstName} {member.lastName} + + {props.memberFirstName} {props.memberLastName} {editMode ? ( - + ) : (