Skip to content

Commit

Permalink
Merge pull request #194 from ukhsa-collaboration/feat/OOC-4383/back-b…
Browse files Browse the repository at this point in the history
…utton-check-your-answers

OOC-4383 Add back button to check your answers page
  • Loading branch information
emilyjevans authored Jun 13, 2024
2 parents c853812 + e28e655 commit e5b15a3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions runner/src/server/plugins/engine/models/SummaryViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export class SummaryViewModel {
message: string;
}[]
| undefined;
backLink?: string;

_outputs: any; // TODO
_payApiKey: FormDefinition["payApiKey"];
Expand All @@ -67,6 +68,7 @@ export class SummaryViewModel {
) {
this.pageTitle = pageTitle;
this.name = model.name;
this.backLink = state?.progress?.[state?.progress.length - 1];
const { relevantPages, endPage } = this.getRelevantPages(model, state);
const details = this.summaryDetails(request, model, state, relevantPages);
const { def } = model;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,21 @@ export class SummaryPageController extends PageController {
return this.makePostRouteHandler()(request, h);
}
const state = await cacheService.getState(request);
const viewModel = new SummaryViewModel(this.title, model, state, request);
const progress = state.progress || [];
const currentPath = `/${this.model.basePath}${this.path}${request.url.search}`;

const viewModel = new SummaryViewModel(this.title, model, state, request);
/**
* used for when a user clicks the "back" link. Progress is stored in the state. This is a safer alternative to running javascript that pops the history `onclick`.
*/
const lastVisited = progress[progress.length - 1];
if (!lastVisited || !lastVisited.startsWith(currentPath)) {
if (progress[progress.length - 2] === currentPath) {
progress.pop();
} else {
progress.push(currentPath);
}
}
if (viewModel.endPage) {
return redirectTo(
request,
Expand Down
9 changes: 9 additions & 0 deletions runner/src/server/views/summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
html: 'This is a new service – your <a class="govuk-link" href=" + feedbackLink + " target="_blank">feedback</a> will help us to improve
it.'
}) }}

{% if backLink %}
{{
govukBackLink({
href: backLink,
text: "Back"
})
}}
{% endif %}
{% endblock %}

{% block content %}
Expand Down

0 comments on commit e5b15a3

Please sign in to comment.