Skip to content

Commit

Permalink
Add LA repairs text to generated PDF letter. (#2293)
Browse files Browse the repository at this point in the history
* Add issues to letter. not showing up yet

* Add tests and fix bug where repairs weren't showing up

* Run yarn lingui. some not translated properly

* Issue and room names are translated elsewhere and don't need Trans tags

* Fix test - right values now! yay

* Read

* new snapshot
  • Loading branch information
samaratrilling authored May 5, 2022
1 parent c165d38 commit de647e1
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 69 deletions.
5 changes: 5 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@ checks:
# to have lots of return statements than a lot of
# nested ifs.
enabled: false
file-lines:
# Many of our typescript files are actually longer than the
# 250 lines CodeClimate recommends; this unfairly penalizes
# newer files and isn't that helpful anyway.
enabled: false
31 changes: 0 additions & 31 deletions common-data/issue-area-choices-laletterbuilder.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,20 @@ import {
} from "../../../util/letter-content-util";
import { TransformSession } from "../../../util/transform-session";
import { friendlyUTCDate } from "../../../util/date-util";
import {
getLaIssueChoiceLabels,
LaIssueChoice,
} from "../../../../../common-data/issue-choices-laletterbuilder";
import { getLaIssueRoomChoiceLabels } from "../../../../../common-data/issue-room-choices-laletterbuilder";
import { getIssue, getRoom } from "./issues";

type Issue = {
issueLabel: string;
roomLabels: string[];
};
export type HabitabilityLetterContentProps = BaseLetterContentProps & {
accessDates: GraphQLDate[];
issues: Issue[];
};

const LetterTitle: React.FC<HabitabilityLetterContentProps> = (props) => (
Expand Down Expand Up @@ -130,6 +141,7 @@ export function getHabitabilityLetterContentPropsFromSession(
const props: HabitabilityLetterContentProps = {
...baseProps,
accessDates: session.accessDates,
issues: getIssuesFromSession(session.laIssues as LaIssueChoice[]),
};

return props;
Expand Down Expand Up @@ -159,8 +171,7 @@ const LetterBody: React.FC<HabitabilityLetterContentProps> = (props) => {
home referenced below and/or in the public areas of the building:
</Trans>
</p>
<h2>Repairs required</h2>
ADD REPAIRS HERE
<RepairIssues {...props} />
<div className="jf-avoid-page-breaks-within">
<h2>
<Trans id="laletterbuilder.habitability.access-title">
Expand Down Expand Up @@ -203,11 +214,93 @@ const LetterBody: React.FC<HabitabilityLetterContentProps> = (props) => {
);
};

const RepairIssues: React.FC<HabitabilityLetterContentProps> = (props) => {
const comp = (
<section>
<Trans>
<h2>Repairs required</h2>
</Trans>
<ol>
{props.issues.map(({ issueLabel, roomLabels }, i) => (
<li key={i}>
<b>{issueLabel}</b>
<ul>
{roomLabels.map((roomLabel, j) => (
<li key={j}>{roomLabel}</li>
))}
</ul>
</li>
))}
</ol>
</section>
);
return comp;
};

/**
* Reformats the repair issues from
* ["HEALTH_MOLD_KITCHEN", "HEALTH_MOLD_BEDROOM"]
* to
* [
* {
* issueLabel: "Mold",
* roomLabels: ["Kitchen", "Bedroom"]
* }
* ]
* for easier display.
*/
function getIssuesFromSession(sessionIssues: LaIssueChoice[]): Issue[] {
const result: Issue[] = [];
const issuesDict = groupChoicesByIssue(sessionIssues);

const issueLabelTable = getLaIssueChoiceLabels();
const roomLabelTable = getLaIssueRoomChoiceLabels();
for (let key in issuesDict) {
const choiceList = issuesDict[key];
result.push({
issueLabel: issueLabelTable[choiceList[0]],
roomLabels: choiceList.map((choice) => roomLabelTable[getRoom(choice)]),
});
}
return result;
}

/**
* Takes a string[] and creates a dict like:
* {
* "Mold": ["HEALTH_MOLD_KITCHEN", "HEALTH_MOLD_BATHROOM"]
* }
* as an interim step to creating the dict with display labels.
* @param sessionIssues
* @returns
*/
function groupChoicesByIssue(
sessionIssues: LaIssueChoice[]
): { [issue: string]: LaIssueChoice[] } {
let dict: { [issue: string]: LaIssueChoice[] } = {};
for (let issue of sessionIssues) {
const issueName = getIssue(issue);
if (!dict.hasOwnProperty(getIssue(issue))) {
dict[issueName] = [issue];
} else {
dict[issueName].push(issue);
}
}
return dict;
}

/**
* Used for tests
*/
export const habitabilitySampleLetterProps: HabitabilityLetterContentProps = {
...baseSampleLetterProps,
accessDates: ["2022-05-01", "2023-05-02"],
issues: [{ issueLabel: "Peeling paint", roomLabels: ["Bedroom", "Kitchen"] }],
};

/**
* Used for tests
*/
export const HabitabilitySampleLetterSamplePage: React.FC<{
isPdf: boolean;
}> = ({ isPdf }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ function getCategory(issue: LaIssueChoice): LaIssueCategoryChoice {
return issue.split("__")[0] as LaIssueCategoryChoice;
}

function getIssue(issue: LaIssueChoice) {
export function getIssue(issue: LaIssueChoice) {
return issue.split("__")[1];
}

function getRoom(issue: LaIssueChoice): LaIssueRoomChoice {
export function getRoom(issue: LaIssueChoice): LaIssueRoomChoice {
return issue.split("__")[2] as LaIssueRoomChoice;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<HabitabilityContent> works 1`] = `
exports[`<HabitabilityContent> renders 1`] = `
<div>
<h1
class="has-text-right"
Expand Down Expand Up @@ -54,10 +54,26 @@ exports[`<HabitabilityContent> works 1`] = `
<p>
laletterbuilder.habitability.intro-1
</p>
<h2>
Repairs required
</h2>
ADD REPAIRS HERE
<section>
<h2>
Repairs required
</h2>
<ol>
<li>
<b>
Peeling paint
</b>
<ul>
<li>
Bedroom
</li>
<li>
Kitchen
</li>
</ul>
</li>
</ol>
</section>
<div
class="jf-avoid-page-breaks-within"
>
Expand Down Expand Up @@ -101,6 +117,7 @@ Object {
"city": "Brooklyn",
"email": "[email protected]",
"firstName": "Boop",
"issues": Array [],
"landlordAddress": "123 Cloud City Drive
Bespin, NY 12345",
"landlordEmail": "[email protected]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { newSb } from "../../../../tests/session-builder";

describe("<HabitabilityContent>", () => {
it("works", () => {
it("renders", () => {
const pal = new ReactTestingLibraryPal(
(
<HabitabilityLetterContent
Expand All @@ -19,6 +19,22 @@ describe("<HabitabilityContent>", () => {
);
expect(pal.rr.container).toMatchSnapshot();
});

it("includes issues and rooms", () => {
const pal = new ReactTestingLibraryPal(
(
<HabitabilityLetterContent
{...habitabilitySampleLetterProps}
todaysDate="2020-06-10"
/>
)
);
pal.rr.getByText("Peeling paint");
pal.rr.getByText("Bedroom");
pal.rr.getByText("Kitchen");
});

it("translates into spanish", () => {});
});

const filledUser = newSb().withLoggedInJustfixUser().withLandlordDetails();
Expand Down
29 changes: 15 additions & 14 deletions locales/en/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ msgstr "<0>NoRent</0> <1>letters sent by tenants across the USA</1><2>Since Apri
msgid "<0>Notice of COVID-19 impact on rent</0><1/>at <2/>"
msgstr "<0>Notice of COVID-19 impact on rent</0><1/>at <2/>"

#: frontend/lib/laletterbuilder/letter-builder/habitability/habitability-letter-content.tsx:130
msgid "<0>Repairs required</0>"
msgstr "<0>Repairs required</0>"

#. heading of formal letter
#: frontend/lib/util/letter-content-util.tsx:40
msgid "<0>To</0><1/><2>From</2><3/>"
Expand Down Expand Up @@ -412,7 +416,6 @@ msgstr "Build your Letter"
msgid "Build your letter"
msgstr "Build your letter"

#: common-data/issue-area-choices-laletterbuilder.ts:18
#: common-data/issue-category-choices-laletterbuilder.ts:18
msgid "Building and safety"
msgstr "Building and safety"
Expand Down Expand Up @@ -1028,15 +1031,15 @@ msgstr "Got it!"
msgid "Got it, take me there"
msgstr "Got it, take me there"

#: frontend/lib/laletterbuilder/letter-builder/habitability/habitability-letter-content.tsx:10
#: frontend/lib/laletterbuilder/letter-builder/habitability/habitability-letter-content.tsx:13
msgid "Habitability"
msgstr "Habitability"

#: common-data/la-letter-builder-letter-choices.ts:17
msgid "Habitability (CA)"
msgstr "Habitability (CA)"

#: frontend/lib/laletterbuilder/letter-builder/habitability/habitability-letter-content.tsx:15
#: frontend/lib/laletterbuilder/letter-builder/habitability/habitability-letter-content.tsx:18
msgid "Habitability notice sent on behalf of {0}"
msgstr "Habitability notice sent on behalf of {0}"

Expand All @@ -1060,7 +1063,6 @@ msgstr "Harassment (LA City/TAHO)"
msgid "Hawaii"
msgstr "Hawaii"

#: common-data/issue-area-choices-laletterbuilder.ts:16
#: common-data/issue-category-choices-laletterbuilder.ts:16
msgid "Health"
msgstr "Health"
Expand Down Expand Up @@ -1407,7 +1409,7 @@ msgstr "LA Letter Builder Homepage"
msgid "LaLetterBuilder is a collaboration between JustFix.nyc and legal organizations and housing rights non-profits in Los Angeles."
msgstr "LaLetterBuilder is a collaboration between JustFix.nyc and legal organizations and housing rights non-profits in Los Angeles."

#: frontend/lib/laletterbuilder/letter-builder/habitability/habitability-letter-content.tsx:30
#: frontend/lib/laletterbuilder/letter-builder/habitability/habitability-letter-content.tsx:33
msgid "LaLetterBuilder.org <0/>sent on behalf of <1/>"
msgstr "LaLetterBuilder.org <0/>sent on behalf of <1/>"

Expand Down Expand Up @@ -2177,7 +2179,7 @@ msgstr "Rodent infestation"
msgid "Rusty water"
msgstr "Rusty water"

#: frontend/lib/laletterbuilder/letter-builder/habitability/habitability-letter-content.tsx:129
#: frontend/lib/laletterbuilder/letter-builder/habitability/habitability-letter-content.tsx:201
msgid "Sample Habitability letter"
msgstr "Sample Habitability letter"

Expand Down Expand Up @@ -2621,7 +2623,6 @@ msgstr "Unsafe/broken stairs and/or railing"
msgid "Utah"
msgstr "Utah"

#: common-data/issue-area-choices-laletterbuilder.ts:17
#: common-data/issue-category-choices-laletterbuilder.ts:17
msgid "Utilities"
msgstr "Utilities"
Expand Down Expand Up @@ -3140,7 +3141,7 @@ msgstr "Your declaration is ready to send!"
msgid "Your email address"
msgstr "Your email address"

#: frontend/lib/laletterbuilder/letter-builder/habitability/habitability-letter-content.tsx:77
#: frontend/lib/laletterbuilder/letter-builder/habitability/habitability-letter-content.tsx:80
msgid "Your habitability letter"
msgstr "Your habitability letter"

Expand Down Expand Up @@ -3462,31 +3463,31 @@ msgstr "<0>If your apartment is currently rent stabilized, or has been at any po
msgid "justfix.whyIsPhoneNumberNeeded"
msgstr "We’ll use this information to either:<0><1>Log you into your existing account</1><2>Match with a pre-existing account </2><3>Sign you up for a new account.</3></0><4/>An account will allow you to return to our tools at any point in the process without having to start from the beginning, download any documents you complete, and be notified of relevant changes to policies that affect you."

#: frontend/lib/laletterbuilder/letter-builder/habitability/habitability-letter-content.tsx:17
#: frontend/lib/laletterbuilder/letter-builder/habitability/habitability-letter-content.tsx:20
msgid "laletterbuilder.emailToLandlordBody"
msgstr "<0>Please see letter attached from <1/>. </0><2>In order to document communications and avoid misunderstandings, please correspond with <3/> via email at <4>{0}</4> or mail rather than a phone call or in-person visit.</2>"

#: frontend/lib/laletterbuilder/about.tsx:54
msgid "laletterbuilder.explanationAboutWhyWeMadeThisSite"
msgstr "We made this site because xyz"

#: frontend/lib/laletterbuilder/letter-builder/habitability/habitability-letter-content.tsx:95
#: frontend/lib/laletterbuilder/letter-builder/habitability/habitability-letter-content.tsx:97
msgid "laletterbuilder.habitability.access-intro"
msgstr "Below are dates that I am available to be at my home to let in a repair worker. Please contact me (using the information provided at the top of this letter) in order to make arrangements."

#: frontend/lib/laletterbuilder/letter-builder/habitability/habitability-letter-content.tsx:90
#: frontend/lib/laletterbuilder/letter-builder/habitability/habitability-letter-content.tsx:92
msgid "laletterbuilder.habitability.access-title"
msgstr "Available access dates"

#: frontend/lib/laletterbuilder/letter-builder/habitability/habitability-letter-content.tsx:102
#: frontend/lib/laletterbuilder/letter-builder/habitability/habitability-letter-content.tsx:104
msgid "laletterbuilder.habitability.access-warning"
msgstr "Be advised that you are required by law to provide a <0>24-hour written notice of intent</0> to enter the unit to make repairs pursuant California Civil Code 1954. Anyone coming to perform a repair inspection and/or repairs should arrive on the date and time mutually agreed upon."

#: frontend/lib/laletterbuilder/letter-builder/habitability/habitability-letter-content.tsx:115
#: frontend/lib/laletterbuilder/letter-builder/habitability/habitability-letter-content.tsx:117
msgid "laletterbuilder.habitability.consequences"
msgstr "You have 10 business days from the date of this letter to address the repairs outlined. If the repairs are not initiated and/or completed within this reasonable timeframe, I will have to report my habitability issues to the Los Angeles Housing and Community Investment Department (HCID), the Los Angeles Department of Public Health/(LADPH) and the Department of Building and Safety (LADBS)."

#: frontend/lib/laletterbuilder/letter-builder/habitability/habitability-letter-content.tsx:81
#: frontend/lib/laletterbuilder/letter-builder/habitability/habitability-letter-content.tsx:84
msgid "laletterbuilder.habitability.intro-1"
msgstr "This letter is to notify you that I need the following repairs in my home referenced below and/or in the public areas of the building:"

Expand Down
Loading

0 comments on commit de647e1

Please sign in to comment.