hof-behaviour-feedback

2.0.2 • Public • Published

hof-behaviour-feedback

HOF behaviour allowing a custom feedback page to be deployed as part of the hof form, which will then be linked to as part of the banner.

When configured correctly the user will be taken to the custom feedback form, and redirected back to the page they came from when the form has been submitted.

It is possible to use a single feedback instance for multiple hof forms - e.g. by including it in a 'common' app with no base url and setting a custom feedback url of '/feedback'.

Installation

npm install [--save] hof-behaviour-feedback;

Usage

hof app initialisation (top level index.js)

const app = hof({
  ...
  behaviours: [
    require('hof-behaviour-feedback').SetFeedbackReturnUrl
  ],
  ...
});

Customising the feedback form step path (Optional, defaults to ${app.baseUrl}/feedback):

Note that if setting a custom url for the feedback form the app.baseUrl will not be applied automatically.

app.use((req, res, next) => {
  // Set custom feedback path
  res.locals.feedbackUrl='/my-feedback-url';
  next();
});

app/myapp/index.js

const UploadFeedback = require('hof-behaviour-feedback').SubmitFeedback

module.exports = {
  ...
  steps: {
    ...
    '/feedback': {
      fields: [...],
      behaviours: [UploadFeedback],
      feedbackConfig: {
        ...
      }
    } 
  }
}

Configure the fields for the feedback step as normal.

Submission types

While currently only GovUK email is supported this library is designed to be easily extensible to support other types of feedback submission.

Email via GovUK Notify

Requires notifications-node-client if notify is configured.

feedbackConfig: {
  notify: {
    apiKey: config.govukNotify.notifyApiKey,
    email: {
      templateId: config.govukNotify.templateFormFeedback, 
      emailAddress: config.govukNotify.feedbackEmail,
      fieldMappings: { 
          'feedbackText': 'feedback',
          'feedbackName' : 'name',
          'feedbackEmail' : ' email'
      },
      includeBaseUrlAs : "process",
      includeSourcePathAs : "path"
    }
  }
}
  • apiKey - the notify api key.
  • templateId - id of the GovUk notify email template.
  • emailAddress - address the feedback email should be sent to.
  • fieldMappings - associative array of input names to the corresponding variable name in the notify email template. Any inputs which are not explicitly mapped here will not be sent to notify.
  • includeBaseUrlAs (Optional) - if included the application base url will be sent to notify with the given variable name.
  • includeSourcePathAs (Optional) - if included the originating page path (i.e. the page the user was on before they clicked the feedback link) will be sent to notify with the given variable name.

Readme

Keywords

none

Package Sidebar

Install

npm i hof-behaviour-feedback

Weekly Downloads

0

Version

2.0.2

License

MIT

Unpacked Size

44.7 kB

Total Files

21

Last publish

Collaborators

  • andrew.moody.ho