generated from ministryofjustice/hmpps-template-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
323 additions
and
10 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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import dayjs from 'dayjs' | ||
import { Adjustment } from '../@types/adjustments/adjustmentsTypes' | ||
import { PrisonApiOffenderSentenceAndOffences, PrisonApiPrisoner } from '../@types/prisonApi/prisonClientTypes' | ||
import { daysBetween } from '../utils/utils' | ||
import ReviewRemandForm from './reviewRemandForm' | ||
|
||
export default class RemandReviewModel { | ||
adjustmentIds: string[] | ||
|
||
constructor( | ||
public prisonerDetail: PrisonApiPrisoner, | ||
public adjustments: { string?: Adjustment }, | ||
private sentencesAndOffences: PrisonApiOffenderSentenceAndOffences[], | ||
public form: ReviewRemandForm, | ||
) { | ||
this.adjustmentIds = Object.keys(adjustments) | ||
} | ||
|
||
public totalDays(): number { | ||
return Object.values(this.adjustments) | ||
.map(it => daysBetween(new Date(it.fromDate), new Date(it.toDate))) | ||
.reduce((sum, current) => sum + current, 0) | ||
} | ||
|
||
public adjustmentSummary(id: string) { | ||
const adjustment = this.adjustments[id] | ||
const offences = this.sentencesAndOffences.flatMap(it => | ||
it.offences.filter(off => adjustment.remand.chargeId.includes(off.offenderChargeId)), | ||
) | ||
return { | ||
rows: [ | ||
{ | ||
key: { | ||
text: 'Remand period', | ||
}, | ||
value: { | ||
text: `${dayjs(adjustment.fromDate).format('DD MMMM YYYY')} to ${dayjs(adjustment.toDate).format( | ||
'DD MMMM YYYY', | ||
)}`, | ||
}, | ||
}, | ||
{ | ||
key: { | ||
text: 'Offences', | ||
}, | ||
value: { | ||
html: `<ul class="govuk-list govuk-list--bullet"> | ||
${offences.map(it => `<li>${it.offenceDescription}</li>`).join('')} | ||
</ul>`, | ||
}, | ||
}, | ||
{ | ||
key: { | ||
text: 'Days spend on remand', | ||
}, | ||
value: { | ||
text: daysBetween(new Date(adjustment.fromDate), new Date(adjustment.toDate)), | ||
}, | ||
}, | ||
], | ||
} | ||
} | ||
|
||
public totalDaysSummary() { | ||
return { | ||
rows: [ | ||
{ | ||
key: { | ||
text: 'Total days', | ||
}, | ||
value: { | ||
text: this.totalDays(), | ||
}, | ||
}, | ||
], | ||
} | ||
} | ||
} |
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,18 @@ | ||
import AbstractForm from './abstractForm' | ||
import ValidationError from './validationError' | ||
|
||
export default class ReviewRemandForm extends AbstractForm<ReviewRemandForm> { | ||
another: 'yes' | 'no' | ||
|
||
async validation(): Promise<ValidationError[]> { | ||
if (!this.another) { | ||
return [ | ||
{ | ||
fields: ['another'], | ||
text: 'Select an answer', | ||
}, | ||
] | ||
} | ||
return [] | ||
} | ||
} |
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,103 @@ | ||
{% extends "../../../partials/layout.njk" %} | ||
{% from "govuk/components/date-input/macro.njk" import govukDateInput %} | ||
{% from "govuk/components/input/macro.njk" import govukInput %} | ||
{% from "govuk/components/error-summary/macro.njk" import govukErrorSummary %} | ||
{% from "govuk/components/button/macro.njk" import govukButton %} | ||
{% from "govuk/components/back-link/macro.njk" import govukBackLink %} | ||
{% from "govuk/components/summary-list/macro.njk" import govukSummaryList %} | ||
{% from "govuk/components/radios/macro.njk" import govukRadios %} | ||
|
||
{% set pageTitle = applicationName + " - Review remand details" %} | ||
{% set mainClasses = "app-container govuk-body" %} | ||
|
||
{% block beforeContent %} | ||
{{ super() }} | ||
<nav> | ||
{% if model.addOrEdit == 'edit' and model.id %} | ||
{% set backlink = "/" + model.prisonerDetail.offenderNo + "/remand/view" %} | ||
{% else %} | ||
{% set backlink = "/" + model.prisonerDetail.offenderNo %} | ||
{% endif %} | ||
{{ govukBackLink({ | ||
text: "Back", | ||
href: backlink | ||
}) }} | ||
</nav> | ||
{% endblock %} | ||
|
||
{% block content %} | ||
|
||
{% if model.form.errors.length %} | ||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-full"> | ||
{{ govukErrorSummary({ | ||
titleText: "There is a problem", | ||
errorList: model.form.errorList() | ||
}) }} | ||
</div> | ||
</div> | ||
{% endif %} | ||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<h1 class="govuk-heading-l"> | ||
<span class="govuk-caption-xl">Adjust release dates</span> | ||
Review remand details | ||
</h1> | ||
</div> | ||
</div> | ||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-full"> | ||
<p class="govuk-body">Check that the remand and offence information is correct. Once you've reviewed it, you can add more remand time if needed.</p> | ||
</div> | ||
</div> | ||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-full"> | ||
<h2 class="govuk-heading-m">Remand details</h2> | ||
|
||
<form class="form" method="post"> | ||
<input type="hidden" name="_csrf" value="{{ csrfToken }}"/> | ||
|
||
{% for adjustmentId in model.adjustmentIds %} | ||
{{ govukSummaryList(model.adjustmentSummary(adjustmentId))}} | ||
{% endfor %} | ||
{{ govukSummaryList(model.totalDaysSummary())}} | ||
|
||
{{ govukRadios({ | ||
classes: "govuk-radios--inline", | ||
name: "another", | ||
fieldset: { | ||
legend: { | ||
text: "Do you need to add another period of remand?", | ||
classes: "govuk-fieldset__legend--m" | ||
} | ||
}, | ||
errorMessage: model.form.messageForField('another'), | ||
items: [ | ||
{ | ||
value: "yes", | ||
text: "Yes" | ||
}, | ||
{ | ||
value: "no", | ||
text: "No" | ||
} | ||
] | ||
}) }} | ||
|
||
<div class="govuk-button-group"> | ||
{{ govukButton({ | ||
text: "Continue", | ||
type: submit, | ||
preventDoubleClick: true, | ||
attributes: { 'data-qa': 'submit-form' } | ||
}) }} | ||
{{ govukButton({ | ||
text: "Cancel", | ||
classes: "govuk-button--secondary", | ||
href: "/" + model.prisonerDetail.offenderNo | ||
}) }} | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
{% endblock %} |