diff --git a/lib/utils/error_manifests/dateOfBirth.ts b/lib/utils/error_manifests/dateOfBirth.ts deleted file mode 100644 index 4fcb3caf2..000000000 --- a/lib/utils/error_manifests/dateOfBirth.ts +++ /dev/null @@ -1,63 +0,0 @@ -const dateOfBirthErrorManifest = { - generic: { - serverError: { - summary: "There was an error processing your request. Please try again." - } - }, - validation: { - default: { - summary: "Your request contains validation errors", - inline: "Your request contains validation errors" - }, - invalid: { - summary: "Date of birth must be a real date", - inline: "Date of birth must be a real date" - }, - dateInFuture: { - summary: "The date of birth must be in the past", - inline: "The date of birth must be in the past" - }, - noData: { - summary: "Enter your date of birth", - inline: "Enter your date of birth" - }, - noDayMonth: { - summary: "Date of birth must include a day and a month", - inline: "Date of birth must include a day and a month" - }, - noDayYear: { - summary: "Date of birth must include a day and a year", - inline: "Date of birth must include a day and a year" - }, - noMonthYear: { - summary: "Date of birth must include a month and a year", - inline: "Date of birth must include a month and a year" - }, - noDay: { - summary: "Date of birth must include a day", - inline: "Date of birth must include a day" - }, - noMonth: { - summary: "Date of birth must include a month", - inline: "Date of birth must include a month" - }, - noYear: { - summary: "Date of birth must include a year", - inline: "Date of birth must include a year" - }, - tooOld: { - summary: "You must be less than 110 years old", - inline: "You must be less than 110 years old" - }, - tooYoung: { - summary: "You must be at least 16 years old", - inline: "You must be at least 16 years old" - }, - nonNumeric: { - summary: "Date of birth must only include numbers", - inline: "Date of birth must only include numbers" - } - } -}; - -export default dateOfBirthErrorManifest; diff --git a/locales/cy/what-is-your-date-of-birth.json b/locales/cy/what-is-your-date-of-birth.json new file mode 100644 index 000000000..532615cb8 --- /dev/null +++ b/locales/cy/what-is-your-date-of-birth.json @@ -0,0 +1,19 @@ +{ + "whereDoYouLiveTitle" : "What is your date of birth? welsh", + "whereDoYouLiveHint" : "For example, 31 3 1980 welsh", + "day": "Day welsh", + "month": "Month welsh", + "year": "Year welsh", + "error-default" : "Your request contains validation errors welsh", + "error-invalid" : "Date of birth must be a real date welsh", + "error-dateInFuture" : "The date of birth must be in the past welsh", + "error-noData" : "Enter your date of birth welsh", + "error-noDayMonth" : "Date of birth must include a day and a month welsh", + "error-noDayYear" : "Date of birth must include a day and a year welsh", + "error-noMonthYear" : "Date of birth must include a month and a year welsh", + "error-noDay" : "Date of birth must include a day welsh", + "error-noYear" : "Date of birth must include a year welsh", + "error-tooOld" : "You must be less than 110 years old welsh", + "error-tooYoung" : "You must be at least 16 years old welsh", + "error-nonNumeric" : "Date of birth must only include numbers welsh" +} \ No newline at end of file diff --git a/locales/en/what-is-your-date-of-birth.json b/locales/en/what-is-your-date-of-birth.json new file mode 100644 index 000000000..d7869c329 --- /dev/null +++ b/locales/en/what-is-your-date-of-birth.json @@ -0,0 +1,19 @@ +{ + "whereDoYouLiveTitle" : "What is your date of birth?", + "whereDoYouLiveHint" : "For example, 31 3 1980", + "day": "Day", + "month": "Month", + "year": "Year", + "error-default" : "Your request contains validation errors", + "error-invalid" : "Date of birth must be a real date", + "error-dateInFuture" : "The date of birth must be in the past", + "error-noData" : "Enter your date of birth", + "error-noDayMonth" : "Date of birth must include a day and a month", + "error-noDayYear" : "Date of birth must include a day and a year", + "error-noMonthYear" : "Date of birth must include a month and a year", + "error-noDay" : "Date of birth must include a day", + "error-noYear" : "Date of birth must include a year", + "error-tooOld" : "You must be less than 110 years old", + "error-tooYoung" : "You must be at least 16 years old", + "error-nonNumeric" : "Date of birth must only include numbers" +} \ No newline at end of file diff --git a/src/main/config/index.ts b/src/main/config/index.ts index 94d66c1a4..577dbe46e 100644 --- a/src/main/config/index.ts +++ b/src/main/config/index.ts @@ -6,7 +6,7 @@ const BASE_SOLE_TRADER_URL = `${BASE_VIEWS_URL}/sole-trader`; const BASE_LIMITED_TRADER_URL = `${BASE_VIEWS_URL}/limited`; const BASE_UNINCORPORATED_URL = `${BASE_VIEWS_URL}/unincorporated`; export const HOME = `${BASE_SOLE_TRADER_URL}/index/home`; -export const SOLE_TRADER_DOB = `${BASE_SOLE_TRADER_URL}/date-of-birth/capture-date-of-birth`; +export const SOLE_TRADER_DATE_OF_BIRTH = `${BASE_SOLE_TRADER_URL}/what-is-your-date-of-birth/what-is-your-date-of-birth`; export const SOLE_TRADER_NAME = `${BASE_SOLE_TRADER_URL}/name/capture-name`; export const SOLE_TRADER_ROLE = `${BASE_SOLE_TRADER_URL}/role/statement-relevant-officer`; export const SOLE_TRADER_KICK_OUT = `${BASE_SOLE_TRADER_URL}/kick-out/stop-not-relevant-officer`; diff --git a/src/main/controllers/features/SoleTrader/soleTraderDateOfBirthController.ts b/src/main/controllers/features/SoleTrader/soleTraderDateOfBirthController.ts index 9820e1bad..3c56f1317 100644 --- a/src/main/controllers/features/SoleTrader/soleTraderDateOfBirthController.ts +++ b/src/main/controllers/features/SoleTrader/soleTraderDateOfBirthController.ts @@ -2,33 +2,42 @@ import { NextFunction, Request, Response } from "express"; import * as config from "../../../config"; import { validationResult } from "express-validator"; import { FormattedValidationErrors, formatValidationError } from "../../../validation/validation"; -import { BASE_URL, SOLE_TRADER_WHAT_IS_YOUR_NAME, SOLE_TRADER_WHAT_IS_YOUR_NATIONALITY } from "../../../types/pageURL"; +import { BASE_URL, SOLE_TRADER_WHAT_IS_YOUR_NAME, SOLE_TRADER_WHAT_IS_YOUR_NATIONALITY, SOLE_TRADER_DATE_OF_BIRTH } from "../../../types/pageURL"; +import { selectLang, addLangToUrl, getLocalesService, getLocaleInfo } from "../../../utils/localise"; import { Session } from "@companieshouse/node-session-handler"; import { USER_DATA } from "../../../common/__utils/constants"; import { UserData } from "../../../model/UserData"; export const get = async (req: Request, res: Response, next: NextFunction) => { + const lang = selectLang(req.query.lang); + const locales = getLocalesService(); const session: Session = req.session as any as Session; const userData : UserData = session?.getExtraData(USER_DATA)!; - res.render(config.SOLE_TRADER_DOB, { + res.render(config.SOLE_TRADER_DATE_OF_BIRTH, { title: "What is your date of Birth?", - previousPage: BASE_URL + SOLE_TRADER_WHAT_IS_YOUR_NAME, + ...getLocaleInfo(locales, lang), + previousPage: addLangToUrl(BASE_URL + SOLE_TRADER_WHAT_IS_YOUR_NAME, lang), + currentUrl: BASE_URL + SOLE_TRADER_DATE_OF_BIRTH, firstName: userData?.firstName, lastName: userData?.lastName }); }; export const post = async (req: Request, res: Response, next: NextFunction) => { + const lang = selectLang(req.query.lang); + const locales = getLocalesService(); const session: Session = req.session as any as Session; const userData : UserData = session?.getExtraData(USER_DATA)!; try { const errorList = validationResult(req); if (!errorList.isEmpty()) { - const pageProperties = getPageProperties(formatValidationError(errorList.array())); - res.status(400).render(config.SOLE_TRADER_DOB, { + const pageProperties = getPageProperties(formatValidationError(errorList.array(), lang)); + res.status(400).render(config.SOLE_TRADER_DATE_OF_BIRTH, { + previousPage: addLangToUrl(BASE_URL + SOLE_TRADER_WHAT_IS_YOUR_NAME, lang), title: "What is your date of Birth?", - previousPage: BASE_URL + SOLE_TRADER_WHAT_IS_YOUR_NAME, + ...getLocaleInfo(locales, lang), + currentUrl: BASE_URL + SOLE_TRADER_DATE_OF_BIRTH, pageProperties: pageProperties, payload: req.body, firstName: userData?.firstName, diff --git a/src/main/controllers/features/SoleTrader/typeOfBusinessController.ts b/src/main/controllers/features/SoleTrader/typeOfBusinessController.ts index 33244cbd1..0b15083ac 100644 --- a/src/main/controllers/features/SoleTrader/typeOfBusinessController.ts +++ b/src/main/controllers/features/SoleTrader/typeOfBusinessController.ts @@ -9,7 +9,7 @@ export const get = async (req: Request, res: Response, next: NextFunction) => { const lang = selectLang(req.query.lang); const locales = getLocalesService(); res.render(config.SOLE_TRADER_TYPE_OF_BUSINESS, { - previousPage: addLangToUrl(START, lang), + previousPage: addLangToUrl(BASE_URL + HOME_URL, lang), title: "What type of business are you registering?", ...getLocaleInfo(locales, lang), currentUrl: BASE_URL + TYPE_OF_BUSINESS, @@ -26,7 +26,7 @@ export const post = async (req: Request, res: Response, next: NextFunction) => { if (!errorList.isEmpty()) { const pageProperties = getPageProperties(formatValidationError(errorList.array(), lang)); res.status(400).render(config.SOLE_TRADER_TYPE_OF_BUSINESS, { - previousPage: addLangToUrl(HOME_URL, lang), + previousPage: addLangToUrl(BASE_URL + HOME_URL, lang), title: "What type of business are you registering?", ...getLocaleInfo(locales, lang), currentUrl: BASE_URL + TYPE_OF_BUSINESS, diff --git a/src/main/routes/index.ts b/src/main/routes/index.ts index 4e4d84c5d..16c3b4c8a 100644 --- a/src/main/routes/index.ts +++ b/src/main/routes/index.ts @@ -11,7 +11,7 @@ import { import { correspondenceAddressManualValidator } from "../validation/correspondenceAddressManual"; import { whereDoYouLiveValidator } from "../validation/whereDoYouLive"; -import { dateOfBirthValidator } from "../../../lib/validation/dateOfBirth"; +import { dateOfBirthValidator } from "../validation/dateOfBirth"; import { nameValidator } from "../../../lib/validation/name"; import { correspondenceAddressAutoLookupValidator } from "../validation/correspondenceAddressAutoLookup"; import { correspondenceAddressListValidator } from "../validation/correspondanceAddressList"; diff --git a/lib/validation/dateOfBirth.ts b/src/main/validation/dateOfBirth.ts similarity index 76% rename from lib/validation/dateOfBirth.ts rename to src/main/validation/dateOfBirth.ts index 6838671eb..8c9397c95 100644 --- a/lib/validation/dateOfBirth.ts +++ b/src/main/validation/dateOfBirth.ts @@ -1,5 +1,4 @@ import { body } from "express-validator"; -import dateOfBirthErrorManifest from "../utils/error_manifests/dateOfBirth"; export const dateOfBirthValidator = [ body("dob-day").custom((value, { req }) => dateDayChecker(req.body["dob-day"], req.body["dob-month"], req.body["dob-year"])), @@ -10,29 +9,29 @@ export const dateOfBirthValidator = [ export const dateDayChecker = (day: string, month: string, year: string) => { if (day.trim() === "" && month.trim() === "" && year.trim() === "") { - throw new Error(dateOfBirthErrorManifest.validation.noData.summary); + throw new Error("noData"); } else if (day.trim() === "" && month.trim() === "") { - throw new Error(dateOfBirthErrorManifest.validation.noDayMonth.summary); + throw new Error("noDayMonth"); } else if (day.trim() === "" && year.trim() === "") { - throw new Error(dateOfBirthErrorManifest.validation.noDayYear.summary); + throw new Error("noDayYear"); } else if (day.trim() === "") { - throw new Error(dateOfBirthErrorManifest.validation.noDay.summary); + throw new Error("noDay"); } return true; }; export const dateMonthChecker = (day: string, month: string, year: string) => { if (day.trim() !== "" && month.trim() === "" && year.trim() === "") { - throw new Error(dateOfBirthErrorManifest.validation.noMonthYear.summary); + throw new Error("noMonthYear"); } else if (day.trim() !== "" && month.trim() === "") { - throw new Error(dateOfBirthErrorManifest.validation.noMonth.summary); + throw new Error("noMonth"); } return true; }; export const dateYearChecker = (day: string, month: string, year: string) => { if (day.trim() !== "" && month.trim() !== "" && year.trim() === "") { - throw new Error(dateOfBirthErrorManifest.validation.noYear.summary); + throw new Error("noYear"); } return true; }; @@ -40,15 +39,15 @@ export const dateYearChecker = (day: string, month: string, year: string) => { export const validDataChecker = (day: string, month: string, year: string) => { if (day !== "" && month !== "" && year !== "") { if (!isNumeric(day) || !isNumeric(month) || !isNumeric(year)) { - throw new Error(dateOfBirthErrorManifest.validation.nonNumeric.summary); + throw new Error("nonNumeric"); } else if (+month < 1 || +month > 12 || +year < 1000 || +year > 9999 || !isValidDay(+day, +month, +year) || day.length > 2 || month.length > 2) { - throw new Error(dateOfBirthErrorManifest.validation.invalid.summary); + throw new Error("invalid"); } else if (!isNotInFuture(+day, +month, +year)) { - throw new Error(dateOfBirthErrorManifest.validation.dateInFuture.summary); + throw new Error("dateInFuture"); } else if (!isNotTooYoung(+day, +month, +year)) { - throw new Error(dateOfBirthErrorManifest.validation.tooYoung.summary); + throw new Error("tooYoung"); } else if (!isNotTooOld(+day, +month, +year)) { - throw new Error(dateOfBirthErrorManifest.validation.tooOld.summary); + throw new Error("tooOld"); } } return true; diff --git a/src/main/views/features/sole-trader/date-of-birth/capture-date-of-birth.njk b/src/main/views/features/sole-trader/date-of-birth/capture-date-of-birth.njk deleted file mode 100644 index c3b581adf..000000000 --- a/src/main/views/features/sole-trader/date-of-birth/capture-date-of-birth.njk +++ /dev/null @@ -1,68 +0,0 @@ -{% from "govuk/components/date-input/macro.njk" import govukDateInput %} -{% from "govuk/components/button/macro.njk" import govukButton %} -{% set errors = pageProperties.errors %} -{% extends "layouts/default.njk" %} - -{% block main_content %} - -{% if errors["dob-day"] %} - {% set errorMessageText = errors["dob-day"].text %} -{% elif errors["dob-month"] %} - {% set errorMessageText = errors["dob-month"].text %} -{% elif errors["dob-year"] %} - {% set errorMessageText = errors["dob-year"].text %} -{% endif %} - -