Skip to content

Commit

Permalink
[ASL-4474] Content changes to move to required fields (#1573)
Browse files Browse the repository at this point in the history
* [ASL-4474] Content changes to move to required fields
- Add declaration that details are upto date
- Remove redundant intro text
- Fix reveal error messages not showing in the same order as they appear
- Fix dates showing with leading 0
- Include unvalidated fields in the model data passed to other validators

* [ASL-4474] Update with required updates to asl-components

* [ASL-4474] Update version
  • Loading branch information
jeff-horton-ho-sas authored Feb 21, 2024
1 parent d88b072 commit d3204b6
Show file tree
Hide file tree
Showing 13 changed files with 236 additions and 54 deletions.
6 changes: 3 additions & 3 deletions constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ function getRopsYears(start) {

module.exports = {
dateFormat: {
short: 'DD/MM/YYYY',
short: 'D/M/YYYY',
medium: 'D MMM YYYY',
long: 'DD MMMM YYYY',
datetime: 'DD MMMM YYYY HH:mm'
long: 'D MMMM YYYY',
datetime: 'D MMMM YYYY HH:mm'
},
ropsYears: getRopsYears(2021)
};
9 changes: 5 additions & 4 deletions lib/validation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const defaultValidators = [
}
];

const validateField = (key, { value, validate }, fields, model) => {
const validateField = (key, { value, validate = [] }, fields, model) => {
return validate.reduce((err, options) => {
const { validator, params } = options;
return err || (!validators[validator](key, value, params, fields, model) && validator);
Expand All @@ -32,6 +32,7 @@ const validate = (fields, model) => {

const normaliseValidators = field => {
if (!field.validate) {
field.validate = [];
return field;
}
return {
Expand All @@ -52,7 +53,7 @@ const normaliseValidators = field => {
};
};

const mapDefaults = (field, key) => {
const mapDefaults = (field) => {
const defaults = (defaultValidators.find(v => v.inputType === field.inputType) || {}).validate;
return {
...field,
Expand All @@ -69,9 +70,9 @@ const middleware = (values, schema, model) => {
.mapValues(mapDefaults)
.pickBy((field, key) => {
if (!field.conditionalReveal) {
return field.validate;
return true;
}
return values[`conditional-reveal-${key}`] === 'true' && field.validate;
return values[`conditional-reveal-${key}`] === 'true';
})
.value();

Expand Down
113 changes: 98 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@asl/pages",
"version": "31.0.1",
"version": "31.1.0",
"description": "",
"main": "index.js",
"style": "pages/common/assets/sass/style.scss",
Expand Down Expand Up @@ -29,7 +29,7 @@
"@asl/projects": "^15.0.1",
"@asl/service": "^10.0.0",
"@joefitter/docx": "^4.7.0",
"@ukhomeoffice/asl-components": "13.0.0",
"@ukhomeoffice/asl-components": "13.2.0",
"@ukhomeoffice/asl-constants": "^2.1.0",
"@ukhomeoffice/asl-dictionary": "^2.1.0",
"@ukhomeoffice/frontend-toolkit": "^3.0.0",
Expand Down
6 changes: 3 additions & 3 deletions pages/common/content/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,14 @@ module.exports = {
}
},
errors: {
heading: 'Please fix the following error',
headingPlural: 'Please fix the following errors',
heading: 'There is a problem',
headingPlural: 'There is a problem',
form: {
unchanged: 'No changes have been made',
csrf: 'This form data has been changed somewhere else.'
},
declaration: {
required: 'Please confirm that you understand.'
required: 'Select to confirm that you understand.'
},
default: {
maxLength: 'This field is limited to 256 characters',
Expand Down
15 changes: 11 additions & 4 deletions pages/common/routers/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,14 @@ const schemaWithReveals = (schema) =>
return {
...obj,
[key]: value,
...(value.reveal || {})
...(value.reveal || {}),
...(value.options || []).reduce(
(acc, opt) => ({
...acc,
...(opt.reveal ? schemaWithReveals(opt.reveal) : {})
}),
{}
)
};
},
{}
Expand Down Expand Up @@ -242,11 +249,11 @@ module.exports = ({
process = defaultMiddleware,
validate = defaultMiddleware,
saveValues = defaultMiddleware,
requiresDeclaration = (req) => false,
cancelEdit = (req, res, next) => {
requiresDeclaration = () => false,
cancelEdit = (req, res) => {
return res.redirect(cancelPath);
},
editAnswers = (req, res, next) => {
editAnswers = (req, res) => {
return res.redirect(req.baseUrl.replace(/\/confirm/, ''));
}
} = {}) => {
Expand Down
2 changes: 1 addition & 1 deletion pages/establishment/licence-fees/content/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
},
fees: {
title: 'Estimated licence fees',
period: 'Covering the period:',
period: 'Covering the financial year:',
disclaimer: 'These projections are based on the number of billable licences held and may differ from the final numbers.',
details: {
summary: 'How these fees are calculated',
Expand Down
44 changes: 40 additions & 4 deletions pages/establishment/licence-fees/details/content/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,58 @@ module.exports = merge({}, content, {
title: 'Contact information for billing',
fields: {
contactName: {
label: 'Billing contact'
label: 'Billing contact name'
},
contactNumber: {
label: 'Contact number'
label: 'Telephone number'
},
contactEmail: {
label: 'Contact email address'
label: 'Email address'
},
contactAddress: {
label: 'Billing address'
},
hasPurchaseOrder: {
label: 'Do you have a purchase order number?',
options: {
yes: 'Yes',
no: 'No'
}
},
purchaseOrder: {
label: 'Purchase order number'
},
alternativePaymentMethod: {
label: 'Provide details for your payment method'
},
otherInformation: {
label: 'Any other billing information'
label: 'Other billing information (optional)'
},
declaredCurrent: {
label: 'These details are correct for the period {{ currentPeriod }}'
}
},
errors: {
contactName: {
required: 'Enter a contact name'
},
contactNumber: {
required: 'Enter a telephone number'
},
contactEmail: {
required: 'Enter an email address'
},
contactAddress: {
required: 'Enter an address'
},
purchaseOrder: {
required: 'Enter a purchase order number'
},
alternativePaymentMethod: {
required: 'Enter details for your payment method'
},
declaredCurrent: {
required: 'Select to confirm that all details are up to date'
}
},
actions: {
Expand Down
Loading

0 comments on commit d3204b6

Please sign in to comment.