From 5de9aee56b23a13374dab942a24b55570a6b3a8f Mon Sep 17 00:00:00 2001 From: Pete Littlewood <30798627+plittlewood-rpt@users.noreply.github.com> Date: Thu, 7 Dec 2023 15:06:25 +0000 Subject: [PATCH] feat: 10243 Update templates with designs from ANZ (#10245) * Update templates with designs from ANZ * Fix issue with missing padding round email content Update to attempt to address recipient by first name * Fix lint errors * Fixed missed linting error * Tweak * small refactor * small refactor * adds tests --------- Co-authored-by: Will McVay --- .../src/mailer/__tests__/utils.test.ts | 19 +++++ .../src/mailer/custom-mailer.ts | 9 +-- .../mailer/templates/admin-user-invite.mjml | 70 +++++++++---------- .../templates/confirm-registration.mjml | 56 +++++++-------- .../src/mailer/templates/forgot-password.mjml | 55 +++++++-------- .../src/mailer/utils.ts | 34 +++++++++ 6 files changed, 142 insertions(+), 101 deletions(-) create mode 100644 packages/cognito-custom-mail-lambda/src/mailer/__tests__/utils.test.ts create mode 100644 packages/cognito-custom-mail-lambda/src/mailer/utils.ts diff --git a/packages/cognito-custom-mail-lambda/src/mailer/__tests__/utils.test.ts b/packages/cognito-custom-mail-lambda/src/mailer/__tests__/utils.test.ts new file mode 100644 index 0000000000..f7298a088b --- /dev/null +++ b/packages/cognito-custom-mail-lambda/src/mailer/__tests__/utils.test.ts @@ -0,0 +1,19 @@ +import { tryGetFirstName } from '../utils' + +describe('tryGetFirstName', () => { + it('should return the input if the input length is less than 2', () => { + expect(tryGetFirstName('A')).toBe('A') + }) + + it('should return the first part of the name if the name has less than 3 parts', () => { + expect(tryGetFirstName('John Doe')).toBe('John') + }) + + it('should return the second part of the name if the first part is a title', () => { + expect(tryGetFirstName('Mr John Doe')).toBe('John') + }) + + it('should return the first part of the name if the first part is not a title', () => { + expect(tryGetFirstName('John Mr Doe')).toBe('John') + }) +}) diff --git a/packages/cognito-custom-mail-lambda/src/mailer/custom-mailer.ts b/packages/cognito-custom-mail-lambda/src/mailer/custom-mailer.ts index def23a62f5..e7880bef2d 100644 --- a/packages/cognito-custom-mail-lambda/src/mailer/custom-mailer.ts +++ b/packages/cognito-custom-mail-lambda/src/mailer/custom-mailer.ts @@ -4,6 +4,7 @@ import confirmRegistrationTemplate from './templates/confirm-registration.html' import adminUserInviteTemplate from './templates/admin-user-invite.html' import { UserModel } from '@reapit/foundations-ts-definitions' import * as oldTemplates from './templates/old-templates' +import { tryGetFirstName } from './utils' const confirmRegistrationUrl = `${process.env.MARKET_PLACE_URL}/login` const resetPasswordUrl = `${process.env.MARKET_PLACE_URL}/reset-password` @@ -52,7 +53,7 @@ export const customMailer: CognitoUserPoolTriggerHandler = async (event, _contex event.response.emailSubject = 'Reapit Connect - Forgotten Password' const obj = { verificationCode: event.request.codeParameter as string, - userName: event.request.userAttributes.name, + userName: tryGetFirstName(event.request.userAttributes.name), url: resetPasswordUrl, } event.response.emailMessage = useOldTemplates @@ -65,7 +66,7 @@ export const customMailer: CognitoUserPoolTriggerHandler = async (event, _contex event.response.emailSubject = 'Welcome to Reapit Connect' const obj = { url: await getConfirmRegistrationUrl(event.request.userAttributes.email), - userName: event.request.userAttributes.name, + userName: tryGetFirstName(event.request.userAttributes.name), } event.response.emailMessage = useOldTemplates ? oldTemplates.confirmRegistrationTemplate(obj) @@ -76,8 +77,8 @@ export const customMailer: CognitoUserPoolTriggerHandler = async (event, _contex case 'CustomMessage_AdminCreateUser': { event.response.emailSubject = 'Welcome to Reapit Connect' const obj = { - name: event.request.userAttributes.name, - userName: event.request.userAttributes.name, + name: tryGetFirstName(event.request.userAttributes.name), + userName: tryGetFirstName(event.request.userAttributes.name), url: await getConfirmRegistrationUrl(event.request.userAttributes.email), verificationCode: event.request.codeParameter as string, } diff --git a/packages/cognito-custom-mail-lambda/src/mailer/templates/admin-user-invite.mjml b/packages/cognito-custom-mail-lambda/src/mailer/templates/admin-user-invite.mjml index dc87b05782..15ada183a8 100644 --- a/packages/cognito-custom-mail-lambda/src/mailer/templates/admin-user-invite.mjml +++ b/packages/cognito-custom-mail-lambda/src/mailer/templates/admin-user-invite.mjml @@ -1,51 +1,51 @@ - + - + - - - - + + + + + + - - - - - - - + + + + + + One login for your Reapit platform. + Welcome to Reapit Connect, {name}. + You now have the power to access all Reapit products and services with a single login. + In order to get started, we’ll need you to sign in with your username and the temporary password provided here. You’ll be asked to reset the password for security purposes. - - - - Welcome to Reapit Connect + + + + Username: {username} - Hi {name}, - Welcome to Reapit Connect. - Reapit Connect is our single sign on solution which allows you to seamlessly access products and services provided by Reapit Ltd. - Please see below your userName and temporary password. When you click the login link, you will be re-directed to a screen where you will be asked to change your password. - User Name: {username} - Temporary Password: {####} - login - When you have successfully changed your temporary password, you will then be presented with a list of products and services available to you. - Please do not reply to this email as this mailbox is not monitored. If you are having an issue or if you have a question about Reapit Connect, please reach out to your help or service desk for support. - Best Regards, - Reapit Team + + Password: {####} + + + + + + Login to Reapit Connect + + + + Please note that this is an automatically generated email, replies will not be answered. If you have any questions or concerns, kindly contact support. - - - www.reapit.com + Copyright © Reapit Ltd. All rights reserved. - + \ No newline at end of file diff --git a/packages/cognito-custom-mail-lambda/src/mailer/templates/confirm-registration.mjml b/packages/cognito-custom-mail-lambda/src/mailer/templates/confirm-registration.mjml index 1d53d4dea5..a53996aa04 100644 --- a/packages/cognito-custom-mail-lambda/src/mailer/templates/confirm-registration.mjml +++ b/packages/cognito-custom-mail-lambda/src/mailer/templates/confirm-registration.mjml @@ -1,47 +1,39 @@ - + - + - - - - + + + + + - - - - - - - + + + + + + One login for your Reapit platform. + Welcome to Reapit Connect, {name}. + You now have the power to access all Reapit products and services with a single login. + In order to get started, we’ll need you to verify your account by clicking the link below. You’ll be asked to reset the password for security purposes. - + + + Verify your account + + - - Welcome to Reapit Connect - - Welcome to Reapit Connect. - Reapit Connect is our single sign on solution which allows you to seamlessly access products and services provided by Reapit Ltd. - Please see below your username and verification code. When you click the verification link, you will be re-directed to a screen where you will be asked to change your password. - VERIFY ACCOUNT - Once your account has been verified, you will be redirected to the login page. - Please do not reply to this email as this mailbox is not monitored. If you are having an issue or if you have a question about Reapit Connect, please reach out to your help or service desk for support. - Best Regards, - Reapit Team + Please note that this is an automatically generated email, replies will not be answered. If you have any questions or concerns, kindly contact support. - - - www.reapit.com + Copyright © Reapit Ltd. All rights reserved. - + \ No newline at end of file diff --git a/packages/cognito-custom-mail-lambda/src/mailer/templates/forgot-password.mjml b/packages/cognito-custom-mail-lambda/src/mailer/templates/forgot-password.mjml index 4048112951..6d64dc3592 100644 --- a/packages/cognito-custom-mail-lambda/src/mailer/templates/forgot-password.mjml +++ b/packages/cognito-custom-mail-lambda/src/mailer/templates/forgot-password.mjml @@ -1,46 +1,41 @@ - + - + - - - - + + + + + + - - - - + + + + + One login for your Reapit platform. + Hi {userName} + Forgot your password? No problem, it happens to everyone. Please use the code below to reset your password. - - + + + + + Verification Code: {####} + - + - - Reapit Connect - Forgotten Password - - Hi {userName} - We have received a request to reset your Reapit Connect password. - Here is your single use verification code: {####} - If you did not make this request, please ignore this email. - Please do not reply to this email as this mailbox is not monitored. If you are having an issue or if you have a question about Reapit Connect, please reach out to your help or service desk for support. - Best Regards, - Reapit Team + Please note that this is an automatically generated email, replies will not be answered. If you have any questions or concerns, kindly contact support. - - - www.reapit.com + Copyright © Reapit Ltd. All rights reserved. - + \ No newline at end of file diff --git a/packages/cognito-custom-mail-lambda/src/mailer/utils.ts b/packages/cognito-custom-mail-lambda/src/mailer/utils.ts new file mode 100644 index 0000000000..0fb1e1a919 --- /dev/null +++ b/packages/cognito-custom-mail-lambda/src/mailer/utils.ts @@ -0,0 +1,34 @@ +const titles: string[] = [ + 'Mr', + 'Mrs', + 'Dr', + 'Doctor', + 'Master', + 'Miss', + 'Ms', + 'Sir', + 'Mdm', + 'Madam', + 'Dame', + 'Lord', + 'Lady', + 'Esq', + 'Prof', + 'Professor', +] + +export const tryGetFirstName = (input: string = '') => { + const trimmed = input.trim() + + if (trimmed.length < 2) { + return input + } + + const nameParts: string[] = trimmed.split(' ') + + if (nameParts.length < 3) { + return nameParts[0] + } + + return titles.includes(nameParts[0]) ? nameParts[1] : nameParts[0] +}