generated from companieshouse/node-review-web-starter-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #189 from companieshouse/feature/add-name-mismatch…
…-reason-screen Name mismatch screen and user input validation
- Loading branch information
Showing
16 changed files
with
755 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name_mismatch_title": "to be translated", | ||
"name_mismatch_born": "to be translated ", | ||
"name_mismatch_details_par1": "to be translated", | ||
"name_mismatch_details_par2": "to be translated", | ||
"name_mismatch_details_par2_link": "to be translated", | ||
"name_mismatch_details_par2_after_link":".", | ||
"name_mismatch_legally_changed": "to be translated", | ||
"name_mismatch_preferred_name": "to be translated", | ||
"name_mismatch_translation_or_convention": "to be translated", | ||
"name_mismatch_register_incorrect": "to be translated", | ||
"name_mismatch_prefer_not_to_say": "to be translated", | ||
"name_mismatch_error_summary": "to be translated", | ||
"name_mismatch_error_inline": "to be translated" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name_mismatch_title": "Why is the name on the public register different to the name this PSC used for identity verification?", | ||
"name_mismatch_born": "Born ", | ||
"name_mismatch_details_par1": "Tell us why the names do not match. We may contact you if we need more information.", | ||
"name_mismatch_details_par2": "You should also consider whether this company needs to ", | ||
"name_mismatch_details_par2_link": "update the PSC name on the public register (opens in a new tab)", | ||
"name_mismatch_details_par2_after_link":".", | ||
"name_mismatch_legally_changed": "Legally changed name (for example, marriage or divorce)", | ||
"name_mismatch_preferred_name": "Preferred name", | ||
"name_mismatch_translation_or_convention":"Translation or a different naming convention", | ||
"name_mismatch_register_incorrect": "Error on the public register", | ||
"name_mismatch_prefer_not_to_say": "Prefer not to say", | ||
"name_mismatch_error_summary": "Tell us why the name on the public register is different to the name this PSC used for identity verification", | ||
"name_mismatch_error_inline": "Tell us why the name on the public register is different to the name this PSC used for identity verification" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
src/routers/handlers/name-mismatch/nameMismatchHandler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import { Request, Response } from "express"; | ||
import { PrefixedUrls, Urls } from "../../../constants"; | ||
import { logger } from "../../../lib/logger"; | ||
import { getLocaleInfo, getLocalesService, selectLang } from "../../../utils/localise"; | ||
import { addSearchParams } from "../../../utils/queryParams"; | ||
import { getUrlWithTransactionIdAndSubmissionId } from "../../../utils/url"; | ||
import { BaseViewData, GenericHandler, ViewModel } from "../generic"; | ||
import { formatDateBorn } from "../../utils"; | ||
import { NameMismatchReasonEnum, PscVerification, PscVerificationData } from "@companieshouse/api-sdk-node/dist/services/psc-verification-link/types"; | ||
import { patchPscVerification } from "../../../services/pscVerificationService"; | ||
import { getPscIndividual } from "../../../services/pscService"; | ||
import { PscVerificationFormsValidator } from "../../../lib/validation/form-validators/pscVerification"; | ||
|
||
interface NameMismatchViewData extends BaseViewData { | ||
pscName: string, | ||
monthYearBorn: string, | ||
nameMismatch: string, | ||
nextPageUrl: string, | ||
legalNameChange: string, | ||
preferredName: string, | ||
translationOrDifferentConvention: string, | ||
publicRegisterError: string, | ||
preferNotToSay: string | ||
} | ||
|
||
export class NameMismatchHandler extends GenericHandler<NameMismatchViewData> { | ||
|
||
private static templatePath = "router_views/name_mismatch/name_mismatch"; | ||
|
||
public async getViewData (req: Request, res: Response): Promise<NameMismatchViewData> { | ||
|
||
const baseViewData = await super.getViewData(req, res); | ||
const verification: PscVerification = res.locals.submission; | ||
const companyNumber = verification.data.companyNumber as string; | ||
const pscIndividual = await getPscIndividual(req, companyNumber, verification.data.pscAppointmentId as string); | ||
const nameMismatch = req.query.nameMismatch as string; | ||
const lang = selectLang(req.query.lang); | ||
const locales = getLocalesService(); | ||
// Note enums match the API | ||
const legalNameChange = NameMismatchReasonEnum.LEGAL_NAME_CHANGE; | ||
const preferredName = NameMismatchReasonEnum.PREFERRED_NAME; | ||
const translationOrDifferentConvention = NameMismatchReasonEnum.DIFFERENT_NAMING_CONVENTION; | ||
const publicRegisterError = NameMismatchReasonEnum.PUBLIC_REGISTER_ERROR; | ||
const preferNotToSay = NameMismatchReasonEnum.PREFER_NOT_TO_SAY; | ||
|
||
return { | ||
...baseViewData, | ||
...getLocaleInfo(locales, lang), | ||
pscName: pscIndividual.resource?.name!, | ||
monthYearBorn: formatDateBorn(pscIndividual.resource?.dateOfBirth, selectLang(req.query.lang)), | ||
nameMismatch, | ||
legalNameChange, | ||
preferredName, | ||
translationOrDifferentConvention, | ||
publicRegisterError, | ||
preferNotToSay, | ||
currentUrl: resolveUrlTemplate(PrefixedUrls.NAME_MISMATCH), | ||
backURL: resolveUrlTemplate(PrefixedUrls.PERSONAL_CODE), | ||
templateName: Urls.NAME_MISMATCH, | ||
backLinkDataEvent: "name-mismatch-back-link" | ||
}; | ||
|
||
function resolveUrlTemplate (prefixedUrl: string): string | null { | ||
return addSearchParams(getUrlWithTransactionIdAndSubmissionId(prefixedUrl, req.params.transactionId, req.params.submissionId), { lang }); | ||
} | ||
} | ||
|
||
public async executeGet (req: Request, res: Response): Promise<ViewModel<NameMismatchViewData>> { | ||
logger.info(`${NameMismatchHandler.name} - ${this.executeGet.name} called for transaction: ${req.params?.transactionId} and submissionId: ${req.params?.submissionId}`); | ||
const viewData = await this.getViewData(req, res); | ||
|
||
viewData.nameMismatch = req.query.nameMismatch as string; | ||
|
||
return { | ||
templatePath: NameMismatchHandler.templatePath, | ||
viewData | ||
}; | ||
} | ||
|
||
public async executePost (req: Request, res: Response): Promise<ViewModel<NameMismatchViewData>> { | ||
logger.info(`${NameMismatchHandler.name} - ${this.executePost.name} called for transaction: ${req.params?.transactionId} and submissionId: ${req.params?.submissionId}`); | ||
const viewData = await this.getViewData(req, res); | ||
|
||
try { | ||
const lang = selectLang(req.query.lang); | ||
const nameMismatchReason = req.body.nameMismatch; | ||
|
||
const queryParams = new URLSearchParams(req.url.split("?")[1]); | ||
const verification: PscVerificationData = { | ||
verificationDetails: { | ||
nameMismatchReason: nameMismatchReason | ||
} | ||
}; | ||
|
||
queryParams.set("lang", lang); | ||
const nextPageUrl = getUrlWithTransactionIdAndSubmissionId(PrefixedUrls.INDIVIDUAL_STATEMENT, req.params.transactionId, req.params.submissionId); | ||
viewData.nextPageUrl = `${nextPageUrl}?${queryParams}`; | ||
const validator = new PscVerificationFormsValidator(lang); | ||
viewData.errors = await validator.validateNameMismatch(req.body, lang, viewData.pscName); | ||
|
||
logger.debug(`${NameMismatchHandler.name} - ${this.executePost.name} - patching name mismatch reason for transaction: ${req.params?.transactionId} and submissionId: ${req.params?.submissionId}`); | ||
await patchPscVerification(req, req.params.transactionId, req.params.submissionId, verification); | ||
|
||
} catch (err: any) { | ||
logger.error(`${req.method} error: problem handling name mismatch request: ${err.message}`); | ||
viewData.errors = this.processHandlerException(err); | ||
} | ||
|
||
return { | ||
templatePath: NameMismatchHandler.templatePath, | ||
viewData | ||
}; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { NextFunction, Request, Response, Router } from "express"; | ||
import { handleExceptions } from "../utils/asyncHandler"; | ||
import { NameMismatchHandler } from "./handlers/name-mismatch/nameMismatchHandler"; | ||
|
||
const nameMismatchRouter: Router = Router({ mergeParams: true }); | ||
|
||
nameMismatchRouter.get("/", handleExceptions(async (req: Request, res: Response) => { | ||
const handler = new NameMismatchHandler(); | ||
const { templatePath, viewData } = await handler.executeGet(req, res); | ||
res.render(templatePath, viewData); | ||
})); | ||
|
||
nameMismatchRouter.post("/", handleExceptions(async (req: Request, res: Response, _next: NextFunction) => { | ||
const handler = new NameMismatchHandler(); | ||
const params = await handler.executePost(req, res); | ||
|
||
if (!Object.keys(params.viewData.errors).length) { | ||
res.redirect(params.viewData.nextPageUrl); | ||
} else { | ||
res.render(params.templatePath, params.viewData); | ||
} | ||
|
||
})); | ||
|
||
export default nameMismatchRouter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
{% extends "layouts/default.njk" %} | ||
|
||
{% from "govuk/components/button/macro.njk" import govukButton %} | ||
{% from "govuk/components/radios/macro.njk" import govukRadios %} | ||
|
||
{% set title = i18n.name_mismatch_title%} | ||
|
||
{% set nameAndDateBirthText = | ||
[pscName," ","(",i18n.name_mismatch_born,monthYearBorn,")"] | join | ||
%} | ||
|
||
{% block main_content %} | ||
|
||
<form action="" method="post"> | ||
{% include "includes/csrf_token.njk" %} | ||
<span class="govuk-caption-xl"> | ||
{{ nameAndDateBirthText }} | ||
</span> | ||
|
||
<h1 class="govuk-heading-l"> | ||
{{ i18n.name_mismatch_title }} | ||
</h1> | ||
|
||
<p class="govuk-body"> | ||
{{ i18n.name_mismatch_details_par1 }} | ||
</p> | ||
|
||
<p class="govuk-body"> | ||
{{ i18n.name_mismatch_details_par2 }} | ||
<a href="https://www.gov.uk/file-changes-to-a-company-with-companies-house" class="govuk-link" rel="noreferrer noopener" target="_blank">{{ i18n.name_mismatch_details_par2_link }}</a> | ||
{{- i18n.name_mismatch_details_par2_after_link }} | ||
</p> | ||
|
||
{% set radioButtonConfig = { | ||
idPrefix: "nameMismatch", | ||
name: "nameMismatch", | ||
value: nameMismatch, | ||
fieldset: { | ||
legend: { | ||
text: "", | ||
isPageHeading: false, | ||
classes: "govuk-fieldset__legend--l" | ||
} | ||
}, | ||
id:"nameMismatch", | ||
items: [ | ||
{ | ||
value: legalNameChange, | ||
text: i18n.name_mismatch_legally_changed, | ||
attributes:{ | ||
"data-event-id": "legally-changed-radio-option" | ||
} | ||
}, | ||
{ | ||
value: preferredName, | ||
text: i18n.name_mismatch_preferred_name, | ||
attributes:{ | ||
"data-event-id": "preferred-name-radio-option" | ||
} | ||
}, | ||
{ | ||
value: translationOrDifferentConvention, | ||
text: i18n.name_mismatch_translation_or_convention, | ||
attributes:{ | ||
"data-event-id": "translation-or-different-naming-convention-radio-option" | ||
} | ||
}, | ||
{ | ||
value: publicRegisterError, | ||
text: i18n.name_mismatch_register_incorrect, | ||
attributes:{ | ||
"data-event-id": "register-incorrect-radio-option" | ||
} | ||
}, | ||
{ | ||
value: preferNotToSay, | ||
text: i18n.name_mismatch_prefer_not_to_say, | ||
attributes:{ | ||
"data-event-id": "prefer-not-to-say-radio-option" | ||
} | ||
} | ||
] | ||
} %} | ||
|
||
{% if errors is not undefined and errors is not null and errors | length %} | ||
{{ govukRadios({ | ||
idPrefix: radioButtonConfig.idPrefix, | ||
name: radioButtonConfig.name, | ||
value: radioButtonConfig.value, | ||
fieldset: radioButtonConfig.fieldset, | ||
id:radioButtonConfig.id, | ||
items: radioButtonConfig.items, | ||
errorMessage: { | ||
text: i18n.name_mismatch_error_inline | ||
} | ||
}) }} | ||
{% else %} | ||
{{ govukRadios(radioButtonConfig) }} | ||
{% endif %} | ||
|
||
{{ govukButton({ | ||
attributes: { | ||
id: "submit", | ||
"data-event-id": "name-mismatch-continue-button" | ||
}, | ||
text: i18n.global_continue_button | ||
}) | ||
}} | ||
</form> | ||
|
||
{% endblock %} |
Oops, something went wrong.