Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arn 2342 dev accommodation design changes #639

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions app/form/v1_0/fields/accommodation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import sections from '../config/sections'
import { dependentOn } from './common/utils'

const immigrationAccommodationHint = `
<div class="govuk-!-width-two-thirds">
<div class="govuk-grid-column-full">
<p class="govuk-hint">This includes:</p>
<ul class="govuk-hint govuk-list govuk-list--bullet">
<li>Schedule 10 - Home Office provides accommodation under the Immigration Act 2016</li>
<hr class="govuk-section-break govuk-section-break--m">
<li>Schedule 4 - Home Office provides accommodation for those on immigration bail, prior to the Immigration Act 2016</li>
</ul>
</div>
Expand Down Expand Up @@ -103,7 +104,10 @@ class AccommodationFieldsFactory extends FieldsFactory {
text: 'Enter expected end date (optional)',
code: 'short_term_accommodation_end_date',
type: FieldType.Date,
validate: [{ fn: utils.validateFutureDate, message: 'Enter a future date' }],
validate: [
{ fn: utils.validateValidDate, message: 'Enter a valid date' },
{ fn: utils.validateFutureDate, message: 'Enter a future date' },
],
dependent: dependentOn(this.typeOfTemporaryAccommodation, 'SHORT_TERM'),
summary: {
displayFn: endDateSummaryDisplay,
Expand Down
7 changes: 6 additions & 1 deletion app/form/v1_0/fields/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ export function validateFutureDate(value: string) {
export function validatePastDate(value: string) {
const now = DateTime.now().startOf('day')
const date = DateTime.fromISO(value)
return !value || value === '' ? true : date.isValid && date <= now
return !value || value === '' ? true : date.isValid && date >= now
}

export function validateValidDate(value: string) {
Copy link
Contributor Author

@Yasmin-jones Yasmin-jones Oct 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's now 3 functions that do specific things but the code is very similar. Not sure if this is okay or are there better ways on coding this?
(Description number 2 of ticket)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot! there is definitely common functionality across these three validators which could be abstracted out in to it's own function, which I think sacrifices some simplicity in favour of maintainability, feel free to give refactoring a go

const date = DateTime.fromISO(value)
return !value || value === '' ? true : date.isValid
}

export function requiredWhenValidator(field: string, requiredValue: string) {
Expand Down
1 change: 1 addition & 0 deletions server/views/components/summary/template.njk
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
{% for answer in summaryField.answers %}
<span class="summary__answer--secondary">{{ answer.text | nl2br | safe }}</span>
{{ renderNestedFields(answer.nestedFields) }}
<hr class="govuk-section-break govuk-section-break--m">
{% endfor %}

{% endif %}
Expand Down
2 changes: 2 additions & 0 deletions server/views/forms/summary/summary-analysis-complete.njk
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@
fields[section + "_practitioner_analysis_strengths_or_protective_factors_no_details"],
changeLink
) }}
<hr class="govuk-section-break govuk-section-break--l">
{{ renderAnalysisSummaryRow(
"Linked to risk of serious harm",
fields[section + "_practitioner_analysis_risk_of_serious_harm"],
fields[section + "_practitioner_analysis_risk_of_serious_harm_yes_details"],
fields[section + "_practitioner_analysis_risk_of_serious_harm_no_details"],
changeLink
) }}
<hr class="govuk-section-break govuk-section-break--l">
{{ renderAnalysisSummaryRow(
"Linked to risk of reoffending",
fields[section + "_practitioner_analysis_risk_of_reoffending"],
Expand Down