-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Work Order page to NYCHA LOC flow (#2466)
* [sc-15698] add RAD/PACT to housing type options and run migrations * [sc-15701] add routes * testing * add work order field * add work order mutation * update error state languate * use SessionFormMutation instead of DjangoFormMutation to have work order ticket vars persist across session * fix failing frontend test * linter * add backend tests * add frontend test * migrate minor change, fix a bug of 0 appearing in final letter
- Loading branch information
Showing
29 changed files
with
893 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -225,6 +225,7 @@ workflows: | |
filters: | ||
branches: | ||
only: | ||
- nycha-work-order | ||
- master | ||
only_deploy: | ||
jobs: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import React from "react"; | ||
|
||
import JustfixRoutes from "../../justfix-route-info"; | ||
import LetterOfComplaintRoutes from "../routes"; | ||
import { AppTesterPal } from "../../tests/app-tester-pal"; | ||
import { newSb } from "../../tests/session-builder"; | ||
import { WorkOrderTicketsMutation } from "../../queries/WorkOrderTicketsMutation"; | ||
|
||
describe("work order tickets page", () => { | ||
it("redirects to next step after submitting valid work order tickets", async () => { | ||
const pal = new AppTesterPal(<LetterOfComplaintRoutes />, { | ||
url: JustfixRoutes.locale.loc.workOrders, | ||
session: newSb().withLoggedInNychaJustfixUser().value, | ||
}); | ||
|
||
pal.fillFirstFormField([/Work order ticket number/i, "ABCDE12345"]); | ||
pal.clickButtonOrLink("Next"); | ||
pal.withFormMutation(WorkOrderTicketsMutation).respondWith({ | ||
errors: [], | ||
session: { workOrderTickets: ["ABCDE12345"] }, | ||
}); | ||
|
||
await pal.rt.waitFor(() => pal.rr.getByText(/Landlord information/i)); | ||
const { mock } = pal.appContext.updateSession; | ||
expect(mock.calls).toHaveLength(1); | ||
expect(mock.calls[0][0]).toEqual({ workOrderTickets: ["ABCDE12345"] }); | ||
}); | ||
}); | ||
|
||
describe("work order tickets page", () => { | ||
it("redirects to next step after selecting `I don't have a ticket number`", async () => { | ||
const pal = new AppTesterPal(<LetterOfComplaintRoutes />, { | ||
url: JustfixRoutes.locale.loc.workOrders, | ||
session: newSb().withLoggedInNychaJustfixUser().value, | ||
}); | ||
pal.clickRadioOrCheckbox("I don't have a ticket number"); | ||
pal.clickButtonOrLink("Next"); | ||
|
||
pal.withFormMutation(WorkOrderTicketsMutation).respondWith({ | ||
errors: [], | ||
session: { workOrderTickets: [] }, | ||
}); | ||
|
||
await pal.rt.waitFor(() => pal.rr.getByText(/Landlord information/i)); | ||
const { mock } = pal.appContext.updateSession; | ||
expect(mock.calls).toHaveLength(1); | ||
expect(mock.calls[0][0]).toEqual({ workOrderTickets: [] }); | ||
}); | ||
}); | ||
|
||
describe("work order tickets page", () => { | ||
it("displays error message if no ticket numbers are entered", async () => { | ||
const pal = new AppTesterPal(<LetterOfComplaintRoutes />, { | ||
url: JustfixRoutes.locale.loc.workOrders, | ||
session: newSb().withLoggedInNychaJustfixUser().value, | ||
}); | ||
|
||
pal.clickButtonOrLink("Next"); | ||
pal.withFormMutation(WorkOrderTicketsMutation).respondWith({ | ||
errors: [ | ||
{ | ||
field: "__all__", | ||
extendedMessages: [ | ||
{ | ||
message: | ||
"Enter at least 1 ticket number or select `I don't have a ticket number.`", | ||
code: null, | ||
}, | ||
], | ||
}, | ||
], | ||
session: null, | ||
}); | ||
|
||
await pal.rt.waitFor(() => | ||
pal.rr.getByText(/Enter at least 1 ticket number/i) | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import React from "react"; | ||
|
||
import Page from "../ui/page"; | ||
import { SessionUpdatingFormSubmitter } from "../forms/session-updating-form-submitter"; | ||
import { WorkOrderTicketsMutation } from "../queries/WorkOrderTicketsMutation"; | ||
import { TextualFormField, CheckboxFormField } from "../forms/form-fields"; | ||
import { ProgressButtons } from "../ui/buttons"; | ||
import { MiddleProgressStep } from "../progress/progress-step-route"; | ||
import { Formset } from "../forms/formset"; | ||
import { WorkOrderTicketsInput } from "../queries/globalTypes"; | ||
|
||
const MAX_TICKETS: number = 10; | ||
|
||
function ticketNumberLabel(i: number): string { | ||
let label: string = "Work order ticket number"; | ||
return i > 0 ? label + ` #${i + 1}` : label; | ||
} | ||
|
||
function getInitialState( | ||
ticketNumbers: string[] | null | ||
): WorkOrderTicketsInput { | ||
if (!ticketNumbers) { | ||
return { | ||
ticketNumbers: [], | ||
noTicket: false, // so that checkbox is not selected on load | ||
}; | ||
} | ||
return { | ||
ticketNumbers: ticketNumbers.map((item) => ({ ticketNumber: item })), | ||
noTicket: ticketNumbers.length == 0, | ||
}; | ||
} | ||
|
||
const WorkOrdersPage = MiddleProgressStep((props) => { | ||
return ( | ||
<Page title="Work order repairs ticket"> | ||
<div> | ||
<h1 className="title is-4 is-spaced">Work order repairs ticket</h1> | ||
<p className="subtitle is-6"> | ||
Enter at least one work ticket number. We’ll include these in your | ||
letter so management can see the issues you’ve already reported.{" "} | ||
</p> | ||
<SessionUpdatingFormSubmitter | ||
mutation={WorkOrderTicketsMutation} | ||
initialState={(session) => getInitialState(session.workOrderTickets)} | ||
onSuccessRedirect={props.nextStep} | ||
> | ||
{(ctx) => ( | ||
<> | ||
<Formset | ||
{...ctx.formsetPropsFor("ticketNumbers")} | ||
maxNum={MAX_TICKETS} | ||
emptyForm={{ ticketNumber: "" }} | ||
> | ||
{(formsetCtx, i) => ( | ||
<TextualFormField | ||
label={ticketNumberLabel(i)} | ||
{...formsetCtx.fieldPropsFor("ticketNumber")} | ||
isDisabled={ctx.options.currentState.noTicket} | ||
/> | ||
)} | ||
</Formset> | ||
{ctx.options.currentState.ticketNumbers.length == MAX_TICKETS && ( | ||
<p> | ||
The maximum number of tickets you can enter is {MAX_TICKETS}. | ||
</p> | ||
)} | ||
<CheckboxFormField | ||
{...ctx.fieldPropsFor("noTicket")} | ||
onChange={(value) => { | ||
ctx.options.setField("noTicket", value); | ||
ctx.options.setField("ticketNumbers", []); | ||
}} | ||
> | ||
I don't have a ticket number | ||
</CheckboxFormField> | ||
<ProgressButtons | ||
back={props.prevStep} | ||
isLoading={ctx.isLoading} | ||
/> | ||
</> | ||
)} | ||
</SessionUpdatingFormSubmitter> | ||
</div> | ||
</Page> | ||
); | ||
}); | ||
|
||
export default WorkOrdersPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
frontend/lib/queries/autogen/WorkOrderTicketsMutation.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# This file was auto-generated by querybuilder, please do not edit it. | ||
mutation WorkOrderTicketsMutation($input: WorkOrderTicketsInput!) { | ||
output: workOrderTickets(input: $input) { | ||
errors { ...ExtendedFormFieldErrors }, | ||
session { | ||
workOrderTickets | ||
} | ||
} | ||
} |
Oops, something went wrong.