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

https://jira.collab.test-and-trace.nhs.uk/browse/OOC-4383 OOC - 4383 Add back button to check your answers page #186

Merged
merged 7 commits into from
Jun 7, 2024
Merged
15 changes: 8 additions & 7 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 Expand Up @@ -147,7 +149,6 @@ export class SummaryViewModel {
this.state = state;
this.value = result.value;
this.callback = state.callback;

}

private processErrors(result, details) {
Expand All @@ -163,7 +164,7 @@ export class SummaryViewModel {
}
return errorObject;
}

this.errors = result.error.details.map((err) => {
const name = err.path[err.path.length - 1];
function extractContentBetweenQuotes(inputString) {
Expand All @@ -174,7 +175,7 @@ export class SummaryViewModel {
return null; // Return null if no content is found between quotes
}
}
const path = extractContentBetweenQuotes(err.message)
const path = extractContentBetweenQuotes(err.message);
const errorObject = {
path: path,
name: name,
Expand All @@ -183,20 +184,20 @@ export class SummaryViewModel {
console.log("details", details);
console.log("errorObject", errorObject);
const error = replaceNameWithTitleIfInMessage(details, errorObject);

console.log("ERRORS LIST", error);
return error;
});

details.forEach((detail) => {
const sectionErr = this.errors?.find((err) => err.path === detail.name);

detail.items.forEach((item) => {
if (sectionErr) {
item.inError = true;
return;
}

const err = this.errors?.find(
(err) =>
err.path ===
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ export class SummaryPageController extends PageController {
request: HapiRequest,
h: HapiResponseToolkit
) {



if (viewModel.errors) {
const errorToFix = viewModel.errors[0];
const { path } = errorToFix;
Expand All @@ -31,7 +28,6 @@ export class SummaryPageController extends PageController {
// Existing error filtering logic
})[0];


if (pageWithError) {
const params = {
returnUrl: redirectUrl(request, `/${this.model.basePath}/summary`),
Expand All @@ -55,8 +51,6 @@ export class SummaryPageController extends PageController {
* Returns an async function. This is called in plugin.ts when there is a GET request at `/{id}/{path*}`,
*/
makeGetRouteHandler() {


return async (request: HapiRequest, h: HapiResponseToolkit) => {
this.langFromRequest(request);

Expand All @@ -68,8 +62,23 @@ export class SummaryPageController extends PageController {
return this.makePostRouteHandler()(request, h);
}
const state = await cacheService.getState(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