Skip to content
This repository was archived by the owner on Oct 28, 2024. It is now read-only.
Draft
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
166 changes: 166 additions & 0 deletions fsd_config/form_jsons/elig-test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
{
"metadata": {},
"startPage": "/eligiblity-start",
"name": "Eligibility Test",
"pages": [
{
"path": "/eligiblity-start",
"title": "Eligibility",
"components": [
{
"name": "hsyuiX",
"options": {},
"type": "Html",
"content": "<p class=\"govuk-body\">Tell us if you are eligible</p>",
"schema": {}
}
],
"next": [
{
"path": "/eligibility-1"
}
],
"controller": "./pages/start.js"
},
{
"path": "/eligibility-1",
"title": "Eligibility Part 1",
"components": [
{
"name": "areyou",
"options": {},
"type": "RadiosField",
"title": "Do you think you are eligible?",
"list": "eligiblity-list",
"schema": {}
}
],
"next": [
{
"path": "/summary-not-eligible",
"condition": "nonono"
},
{
"path": "/summary",
"condition": "DtRJdr"
}
],
"section": "eAEGhH"
},
{
"path": "/summary-not-eligible",
"title": "You are NOT eligible",
"components": [
{
"name": "sumsum",
"options": {},
"type": "Para",
"content": "* Display answers *",
"schema": {}
}
],
"next": [],
"section": "eAEGhH",
"controller": "./pages/summary.js"
},
{
"path": "/summary",
"title": "You are eligible",
"components": [
{
"name": "BsGzRm",
"options": {},
"type": "Para",
"content": "* Display answers *",
"schema": {}
}
],
"next": [],
"section": "eAEGhH",
"controller": "./pages/summary.js"
}
],
"lists": [
{
"title": "Do you think you are eligible?",
"name": "eligiblity-list",
"type": "string",
"items": [
{
"text": "Yes, I think I am",
"value": "Yes, I think I am"
},
{
"text": "Nope",
"value": "Nope"
}
]
}
],
"sections": [
{
"name": "eAEGhH",
"title": "Eligibility"
}
],
"conditions": [
{
"displayName": "eligible-no",
"name": "nonono",
"value": {
"name": "eligible-no",
"conditions": [
{
"field": {
"name": "areyou",
"type": "RadiosField",
"display": "Do you think you are eligible?"
},
"operator": "is",
"value": {
"type": "Value",
"value": "Nope",
"display": "Nope"
}
}
]
}
},
{
"displayName": "eligible-yes",
"name": "DtRJdr",
"value": {
"name": "eligible-yes",
"conditions": [
{
"field": {
"name": "areyou",
"type": "RadiosField",
"display": "Do you think you are eligible?"
},
"operator": "is",
"value": {
"type": "Value",
"value": "Yes, I think I am",
"display": "Yes, I think I am"
}
}
]
}
}
],
"fees": [],
"outputs": [
{
"name": "update-form",
"title": "Update form in application store",
"type": "savePerPage",
"outputConfiguration": {
"savePerPageUrl": "https://webhook.site/3f3bfa5a-43b3-4b94-81ca-6fa478623f70"
}
}
],
"version": 2,
"skipSummary": false,
"markAsComplete": false
}
147 changes: 147 additions & 0 deletions fsd_config/form_jsons/hsra/hsra-r1-eligibility.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
{
"metadata": {},
"startPage": "/eligiblity-start",
"name": "Eligibility Test",
"pages": [
{
"path": "/eligiblity-start",
"title": "Eligibility",
"components": [
{
"name": "hsyuiX",
"options": {},
"type": "Html",
"content": "<p class=\"govuk-body\">Tell us if you are eligible</p>",
"schema": {}
}
],
"next": [
{
"path": "/eligibility-1"
}
],
"controller": "./pages/start.js"
},
{
"path": "/eligibility-1",
"title": "Eligibility Part 1",
"components": [
{
"name": "areyou",
"options": {},
"type": "RadiosField",
"title": "Do you think you are eligible?",
"list": "eligiblity-list",
"schema": {}
}
],
"next": [
{
"path": "/summary"
}
],
"section": "eAEGhH",
"controller": "EligibilityPageController"
},

{
"path": "/summary",
"title": "Check your answers",
"components": [
{
"name": "BsGzRm",
"options": {},
"type": "Para",
"content": "* Display answers *",
"schema": {}
}
],
"next": [],
"section": "eAEGhH",
"controller": "./pages/summary.js"
}
],
"lists": [
{
"title": "Do you think you are eligible?",
"name": "eligiblity-list",
"type": "string",
"items": [
{
"text": "Yes, I think I am",
"value": "Yes, I think I am"
},
{
"text": "Nope",
"value": "Nope"
}
]
}
],
"sections": [
{
"name": "eAEGhH",
"title": "Eligibility"
}
],
"conditions": [
{
"displayName": "eligible-no",
"name": "nonono",
"value": {
"name": "eligible-no",
"conditions": [
{
"field": {
"name": "areyou",
"type": "RadiosField",
"display": "Do you think you are eligible?"
},
"operator": "is",
"value": {
"type": "Value",
"value": "Nope",
"display": "Nope"
}
}
]
}
},
{
"displayName": "eligible-yes",
"name": "DtRJdr",
"value": {
"name": "eligible-yes",
"conditions": [
{
"field": {
"name": "areyou",
"type": "RadiosField",
"display": "Do you think you are eligible?"
},
"operator": "is",
"value": {
"type": "Value",
"value": "Yes, I think I am",
"display": "Yes, I think I am"
}
}
]
}
}
],
"fees": [],
"outputs": [
{
"name": "update-form",
"title": "Update form in application store",
"type": "savePerPage",
"outputConfiguration": {
"savePerPageUrl": "True"
}
}
],
"version": 2,
"skipSummary": false,
"markAsComplete": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { PageController } from "./PageController";
import { HapiRequest, HapiResponseToolkit } from "server/types";
import config from "server/config";
import { SaveViewModel } from "../models";

export class EligibilityPageController extends PageController {
makePostRouteHandler() {
return async (request: HapiRequest, h: HapiResponseToolkit) => {
const response = await this.handlePostRequest(request, h);
if (response?.source?.context?.errors) {
return response;
}
const { cacheService, statusService } = request.services([]);
const savedState = await cacheService.getState(request);
//This is required to ensure we don't navigate to an incorrect page based on stale state values
let relevantState = this.getConditionEvaluationContext(
this.model,
savedState
);

// Start page check so forms do not save when hitting the "Contine" button on the first page
const startPage = this.model.def.startPage;
const isStartPage = this.path === startPage;

if (config.savePerPage && !isStartPage) {
// Set flag for continous saves on each question?
const saveViewModel = new SaveViewModel(
this.title,
this.model,
relevantState,
request
);

await cacheService.mergeState(request, {
outputs: saveViewModel.outputs,
userCompletedSummary: true,
});
await cacheService.mergeState(request, {
webhookData: saveViewModel.validatedWebhookData,
});

const response = await statusService.savePerPageRequest(request);
const isEligible = response.metadata.is_eligible;
if (isEligible) {
return this.proceed(request, h, relevantState);
}

let redirectUrl = response.metadata.not_eligible_redirect_url;

if (request.query.form_session_identifier) {
redirectUrl += `?form_session_identifier=${request.query.form_session_identifier}`;
}

return h.redirect(redirectUrl);
}
return this.proceed(request, h, relevantState);
};
}
}
2 changes: 2 additions & 0 deletions runner/src/server/plugins/engine/pageControllers/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { PageController } from "./PageController";
import { StartDatePageController } from "./StartDatePageController";
import { StartPageController } from "./StartPageController";
import { SummaryPageController } from "./SummaryPageController";
import { EligibilityPageController } from "./EligibilityPageController";
import { PageControllerBase } from "./PageControllerBase";
import { RepeatingFieldPageController } from "./RepeatingFieldPageController";
import { Page } from "@xgovformbuilder/model";
Expand All @@ -19,6 +20,7 @@ const PageControllers = {
SummaryPageController,
PageControllerBase,
RepeatingFieldPageController,
EligibilityPageController,
};

export const controllerNameFromPath = (filePath: string) => {
Expand Down
1 change: 1 addition & 0 deletions runner/src/server/services/statusService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export class StatusService {
`savePerPageWebhook response: ${response}`
);
}
return response;
} catch (e) {
this.logger.console.error(
`Failed to save per page. savePerPageUrl: ${savePerPageWebhook?.outputData.url}`
Expand Down
Loading