Skip to content

Commit

Permalink
pr review fixes
Browse files Browse the repository at this point in the history
- fix typos/syntax issues
- add JSDoc and try/catch block to session timeout warning component
- add hof logger to session timeout warning component
- remove beta version in package.json
- - amend content for session timeout warning readme and move it out of components folder into main readme to make it easier for users to find
- update yarn.lock
- amend sub heading levels for components in readme
  • Loading branch information
Rhodine-orleans-lindsay committed Aug 20, 2024
1 parent c54f575 commit 4491fd7
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 106 deletions.
101 changes: 74 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -945,11 +945,11 @@ Using the translation key `fields.field-name.label` will return different values
# HOF Components
## Date Component
## Date Component
A component for handling the rendering and processing of 3-input date fields used in HOF Applications.
## Usage
### Usage
In your fields config:
Expand All @@ -965,7 +965,7 @@ module.exports = {
The above example will create a new date component with the key `'date-field'` and will apply the validators `required` and `before` (before today).
## Configuration
### Configuration
The following optional configuration options are supported:
Expand All @@ -974,7 +974,7 @@ The following optional configuration options are supported:
- `dayOptional {Boolean}` - day defaults to `01` if omitted. Defaults to `false`
- `monthOptional {Boolean}` - month defaults to `01` if omitted. If true then also forces `dayOptional` to be true. Defaults to `false`
## Labels
### Labels
The three intermedate fields have fallback labels of Day, Month and Year, however custom labels can be used by including the translation at the following path:
Expand All @@ -998,13 +998,13 @@ fields.json
}
```
# Summary Page Component
## Summary Page Component
HOF behaviour for showing summary pages
The behaviour mixin will create a set of "locals" data which is compatible with [the `confirm` view from `hof-template-partials`](https://github.com/UKHomeOfficeForms/hof-template-partials/blob/master/views/confirm.html).
## Usage
### Usage
If no sections config is passed, then the mixin will create a section for each step that has fields, and a row within each section for each field on that step.
Expand Down Expand Up @@ -1043,11 +1043,11 @@ Alternatively, sections can be defined manually as follows:
}
```
## Configuration
### Configuration
The `sections` configuration should be a map of arrays, where the entries in the array are the fields that should be shown within that section.
### Field configuration
#### Field configuration
Fields can be defined as simple strings of the field key, in which case all default configuration will be used.
Expand Down Expand Up @@ -1087,30 +1087,30 @@ The `location-addresses` field is one that the application has setup to aggregat
This allows the creation of summary rows based on unknown dynamic user input, i.e. we can not predict in advance how many addresses a user wants to input, what the addresses are and how many categories the user wants to attach to each address. This allows you to easily list them this way.
## Translations
### Translations
The content for section headings and field labels will be loaded from translation files based on the keys.
### Section headings
#### Section headings
Translations for section headings are looked for in the following order:
- `pages.confirm.sections.${key}.header`
- `pages.${key}.header`
### Field labels
#### Field labels
Translations for field labels are looked for in the following order:
- `pages.confirm.fields.${key}.label`
- `fields.${key}.label`
- `fields.${key}.legend`
# Emailer Component
## Emailer Component
HOF behaviour to send emails
## Usage
### Usage
```js
const EmailBehaviour = require('hof').components.emailer;
Expand Down Expand Up @@ -1140,7 +1140,7 @@ steps: {
}
```
## Options
### Options
In addition to the options passed to `hof-emailer`, the following options can be used:
Expand All @@ -1159,17 +1159,17 @@ const emailer = EmailBehaviour({
});
```
# HOF Emailer
## HOF Emailer
An emailer service for HOF applications.
## Installation
### Installation
```bash
$ npm install hof-emailer --save
```
## Usage
### Usage
```js
// first create an emailer instance
Expand All @@ -1192,22 +1192,22 @@ emailer.send(to, body, subject).then(() => {
});
```
## Options
### Options
- `from`: <String>: Address to send emails from. Required.
- `transport`: <String>: Select what mechanism to use to send emails. Defaults: 'smtp'.
- `transportOptions`: <Object>: Set the options for the chosen transport, as defined below. Required.
- `layout`: <String>: Optional path to use a custom layout for email content.
## Transports
### Transports
The following transport options are available:
### `smtp`
#### `smtp`
[nodemailer-smtp-transport](https://github.com/andris9/nodemailer-smtp-transport)
#### Options
##### Options
- `host` <String>: Address of the mailserver. Required.
- `port` <String|Number>: Port of the mailserver. Required.
Expand All @@ -1216,11 +1216,11 @@ The following transport options are available:
- `auth.user` <String>: Mailserver authorisation username.
- `auth.pass` <String>: Mailserver authorisation password.
### `ses`
#### `ses`
[nodemailer-ses-transport](https://github.com/andris9/nodemailer-ses-transport)
#### Options
##### Options
- `accessKeyId` <String>: AWS accessKeyId. Required.
- `secretAccessKey` <String>: AWS accessKeyId. Required.
Expand All @@ -1230,18 +1230,18 @@ The following transport options are available:
- `rateLimit` <String>
- `maxConnections` <String>
### `debug`
#### `debug`
A development option to write the html content of the email to a file for inspection.
`transport: 'debug'`
#### debug options
##### debug options
- `dir` <String>: The location to save html to. Default: `./.emails`. This directory will be created if it does not exist.
- `open` <Boolean>: If set to true, will automatically open the created html file in a browser.
#### debug example
##### debug example
```
transport: 'debug'
Expand All @@ -1251,10 +1251,57 @@ transportOptions: {
}
```
### `stub`
#### `stub`
Disables sending email. No options are required.
## Session Timeout Warning Component
HOF component for customising session timeout related pages
This feature allows you to customise the content related to the session timeout warning, including the messages displayed in the session timeout warning dialog and on the exit page after a user exits the form due to a session timeout.
### Usage
To enable and customize the session timeout behavior, you need to set the component in your project's `hof.settings.json` file:
```js
"behaviours": [
"hof/components/session-timeout-warning"
]
```
By default, the framework uses the standard content provided by HOF. If you wish to override this with custom content at the project level, you must set the following variables to `true` in `hof.settings.json`:
```js
behaviours: [
require('../').components.sessionTimeoutWarning
],
sessionTimeoutWarningContent: true,
exitFormContent: true
```
### Customising content in `pages.json`
Once the variables are set, you can customize the session timeout warning and exit messages in your project's pages.json:
```json
"exit": {
"message": "We have cleared your information to keep it secure. Your information has not been saved."
},
"session-timeout-warning": {
"dialog-title": "Your application will close soon",
"dialog-text": "If that happens, your progress will not be saved.",
"timeout-continue-button": "Stay on this page",
"dialog-exit-link": "Exit this form"
}
```
### Editing content on the Exit Page Header and Title
To edit the exit page's header and title, create an `exit.json` file in your project and set the desired content:
```json
{
"header": "You have left this form",
"title": "You have left this form"
}
```
# UTILITIES
# Autofill Utility
Expand Down
43 changes: 0 additions & 43 deletions components/session-timeout-warning/Readme.md

This file was deleted.

28 changes: 24 additions & 4 deletions components/session-timeout-warning/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
/**
*
* @fileOverview
* Provides custom behavior for handling session timeout warnings and exit actions. This includes
* - Resetting the session if the user exits due to a session timeout.
* - Customizing the session timeout warning dialog content.
* - Setting custom content and titles on the exit page.
*
* @module SessionTimeoutWarningBehavior
* @requires ../../config/hof-defaults
* @param {Class} superclass - The class to be extended.
* @returns {Class} - The extended class with session timeout handling functionality.
*/

'use strict';
const config = require('../../config/hof-defaults');
const logger = require('../../lib/logger')(config);

module.exports = superclass => class extends superclass {
configure(req, res, next) {
// reset the session if user chooses to exit on session timeout warning
if (req.form.options.route === '/exit') {
req.sessionModel.reset();
try {
// Reset the session if the user chooses to exit on session timeout warning
if (req.form.options.route === '/exit') {
req.sessionModel.reset();
logger.log('info', 'Session has been reset on exit');
}
return super.configure(req, res, next);
} catch (error) {
logger.error('Error during session reset:', error);
return next(error); // Pass the error to the next middleware for centralised handling
}
return super.configure(req, res, next);
}

locals(req, res) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "hof",
"description": "A bootstrap for HOF projects",
"version": "22.0.0-timeout-warning-beta.13",
"version": "22.0.0",
"license": "MIT",
"main": "index.js",
"author": "HomeOffice",
Expand Down
Loading

0 comments on commit 4491fd7

Please sign in to comment.