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

OOC-4383 Add back button to check your answers page #194

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading