-
Notifications
You must be signed in to change notification settings - Fork 1
CCM-14583: Get ready to approve letter template #883
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bhansell1
merged 26 commits into
main
from
feature/CCM-14583_user_approves_their_letter_template
Apr 8, 2026
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
f2dc755
CCM-14583: Empty page for the feature
m-salaudeen abdb796
trivvy
bhansell1 077ce73
CCM-14583: update page with content
bhansell1 afb1fcd
CCM-14583: tests
bhansell1 71140ae
lockfile
bhansell1 8be55bf
typing
bhansell1 f142503
CCM-14583: fix fallout from lintfix
bhansell1 f949db7
lockfile
bhansell1 e78bfdf
CCM-14583: lockfile
bhansell1 7536664
Merge branch 'main' of https://github.com/NHSDigital/nhs-notify-web-t…
bhansell1 b4f8884
CCM-14583: update destination when approving letter authoring
bhansell1 469df8d
typecheck
bhansell1 3092553
Merge branch 'main' of https://github.com/NHSDigital/nhs-notify-web-t…
bhansell1 8464b4e
review comments
bhansell1 0f8c892
CCM-14583: remove lockId check from the review and approve page
bhansell1 28a6536
CCM-14583: review
bhansell1 40acce4
Merge branch 'main' of https://github.com/NHSDigital/nhs-notify-web-t…
bhansell1 05679e9
Revert "CCM-14583: remove lockId check from the review and approve page"
bhansell1 b102a63
CCM-14583: pass through lockNumber
bhansell1 e80484f
CCM-14583: self review
bhansell1 80d714b
Merge branch 'main' into feature/CCM-14583_user_approves_their_letter…
bhansell1 a8d6ce9
Merge branch 'main' of https://github.com/NHSDigital/nhs-notify-web-t…
bhansell1 a132c39
Merge branch 'feature/CCM-14583_user_approves_their_letter_template' …
bhansell1 a9f4c1f
CCM-14583: fix broken fn name from pulling in main
bhansell1 2051dc2
CCM-14583: update lockfile
bhansell1 80fdc1c
Merge branch 'main' into feature/CCM-14583_user_approves_their_letter…
bhansell1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
110 changes: 110 additions & 0 deletions
110
...d/src/__tests__/app/get-ready-to-approve-letter-template/__snapshots__/page.test.tsx.snap
This file contains hidden or 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,110 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`GetReadyToApproveLetterTemplatePage matches snapshot 1`] = ` | ||
| <DocumentFragment> | ||
| <div | ||
| class="nhsuk-width-container" | ||
| > | ||
| <main | ||
| class="nhsuk-main-wrapper" | ||
| id="maincontent" | ||
| role="main" | ||
| > | ||
| <div | ||
| class="nhsuk-grid-row" | ||
| > | ||
| <div | ||
| class="nhsuk-grid-column-two-thirds" | ||
| > | ||
| <span | ||
| class="nhsuk-caption-xl" | ||
| > | ||
| Step 1 of 2 | ||
| </span> | ||
| <h1 | ||
| class="nhsuk-heading-xl" | ||
| id="get-ready-to-approve-authoring-letter-template-name" | ||
| > | ||
| Get ready to approve 'authoring letter template name' | ||
| </h1> | ||
| <p | ||
| class="nhsuk-body-l" | ||
| > | ||
| After you approve this letter, you can use it in your message plans. | ||
| </p> | ||
| <h2 | ||
| class="nhsuk-heading-m" | ||
| id="before-you-approve" | ||
| > | ||
| Before you approve | ||
| </h2> | ||
| <p> | ||
| Make sure: | ||
| </p> | ||
| <ul> | ||
| <li> | ||
| the relevant stakeholders in your team have approved your letter template | ||
| </li> | ||
| <li> | ||
| your letter does not have any errors | ||
| </li> | ||
| </ul> | ||
| <h2 | ||
| class="nhsuk-heading-m" | ||
| id="personalisation" | ||
| > | ||
| Personalisation | ||
| </h2> | ||
| <p> | ||
| Longer personalisation data can affect the final number of pages and price of your letter. | ||
| </p> | ||
| <div | ||
| class="nhsuk-warning-callout" | ||
| > | ||
| <h3 | ||
| class="nhsuk-warning-callout__label" | ||
| > | ||
| Important | ||
| <span | ||
| class="nhsuk-u-visually-hidden" | ||
| > | ||
| : | ||
| </span> | ||
| </h3> | ||
| <p> | ||
| You cannot change your template settings after you approve this template. | ||
| </p> | ||
| <p> | ||
| If you need to make changes, edit your original template file on your computer then upload it as a new template. | ||
| </p> | ||
| </div> | ||
| <div | ||
| class="nhsuk-form-group" | ||
| > | ||
| <a | ||
| aria-disabled="false" | ||
| class="nhsuk-button" | ||
| data-testid="continue-button" | ||
| draggable="false" | ||
| href="/templates/review-and-approve-letter-template/authoring-letter-template-id?lockNumber=1" | ||
| role="button" | ||
| > | ||
| Continue | ||
| </a> | ||
| <a | ||
| aria-disabled="false" | ||
| class="nhsuk-button nhsuk-button--secondary nhsuk-u-margin-left-3" | ||
| data-testid="back-button" | ||
| draggable="false" | ||
| href="/templates/preview-letter-template/authoring-letter-template-id" | ||
| role="button" | ||
| > | ||
| Go back | ||
| </a> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </main> | ||
| </div> | ||
| </DocumentFragment> | ||
| `; |
127 changes: 127 additions & 0 deletions
127
frontend/src/__tests__/app/get-ready-to-approve-letter-template/page.test.tsx
This file contains hidden or 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,127 @@ | ||
| import GetReadyToApproveLetterTemplatePage, { | ||
| generateMetadata, | ||
| } from '@app/get-ready-to-approve-letter-template/[templateId]/page'; | ||
| import { render } from '@testing-library/react'; | ||
| import pageContent from '@content/content'; | ||
| import { redirect } from 'next/navigation'; | ||
| import { getTemplate } from '@utils/form-actions'; | ||
| import { | ||
| EMAIL_TEMPLATE, | ||
| NHS_APP_TEMPLATE, | ||
| AUTHORING_LETTER_TEMPLATE, | ||
| SMS_TEMPLATE, | ||
| PDF_LETTER_TEMPLATE, | ||
| } from '@testhelpers/helpers'; | ||
|
|
||
| jest.mock('@utils/form-actions'); | ||
| jest.mock('next/navigation'); | ||
|
|
||
| const getTemplateMock = jest.mocked(getTemplate); | ||
| const redirectMock = jest.mocked(redirect); | ||
|
|
||
| const { | ||
| pageTitle, | ||
| continue: continueLink, | ||
| back, | ||
| } = pageContent.pages.getReadyToApproveLetterTemplate; | ||
|
|
||
| describe('GetReadyToApproveLetterTemplatePage', () => { | ||
| beforeEach(() => { | ||
| jest.resetAllMocks(); | ||
| }); | ||
|
|
||
| it('matches snapshot', async () => { | ||
| getTemplateMock.mockResolvedValueOnce(AUTHORING_LETTER_TEMPLATE); | ||
|
|
||
| const page = render( | ||
| await GetReadyToApproveLetterTemplatePage({ | ||
| params: Promise.resolve({ | ||
| templateId: AUTHORING_LETTER_TEMPLATE.id, | ||
| }), | ||
| searchParams: Promise.resolve({ lockNumber: '1' }), | ||
| }) | ||
| ); | ||
|
|
||
| const continueElement = page.getByRole('button', { | ||
| name: continueLink.text, | ||
| }); | ||
|
|
||
| expect(continueElement).toHaveAttribute( | ||
| 'href', | ||
| `/templates/review-and-approve-letter-template/${AUTHORING_LETTER_TEMPLATE.id}?lockNumber=1` | ||
| ); | ||
|
|
||
| const backLinkElement = page.getByRole('button', { name: back.text }); | ||
|
|
||
| expect(backLinkElement).toHaveAttribute( | ||
| 'href', | ||
| `/templates/preview-letter-template/${AUTHORING_LETTER_TEMPLATE.id}` | ||
| ); | ||
|
|
||
| expect(page.asFragment()).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| it('should return metadata', async () => { | ||
| expect(await generateMetadata()).toEqual({ | ||
| title: pageTitle, | ||
| }); | ||
| }); | ||
|
|
||
| test.each([ | ||
| ['NHS_APP', NHS_APP_TEMPLATE], | ||
| ['SMS', SMS_TEMPLATE], | ||
| ['EMAIL', EMAIL_TEMPLATE], | ||
| ])('should redirect user when templateType is %s', async (_, template) => { | ||
| getTemplateMock.mockResolvedValueOnce(template); | ||
|
|
||
| render( | ||
| await GetReadyToApproveLetterTemplatePage({ | ||
| params: Promise.resolve({ | ||
| templateId: template.id, | ||
| }), | ||
| }) | ||
| ); | ||
| expect(redirectMock).toHaveBeenCalledWith('/invalid-template', 'replace'); | ||
| }); | ||
|
|
||
| it('should redirect to invalid template page when letter template is not an authoring template', async () => { | ||
| getTemplateMock.mockResolvedValueOnce(PDF_LETTER_TEMPLATE); | ||
|
|
||
| await GetReadyToApproveLetterTemplatePage({ | ||
| params: Promise.resolve({ | ||
| templateId: PDF_LETTER_TEMPLATE.id, | ||
| }), | ||
| }); | ||
|
|
||
| expect(redirectMock).toHaveBeenCalledWith('/invalid-template', 'replace'); | ||
| }); | ||
|
|
||
| it('should redirect to invalid template page when no template is found', async () => { | ||
| getTemplateMock.mockResolvedValueOnce(undefined); | ||
|
|
||
| await GetReadyToApproveLetterTemplatePage({ | ||
| params: Promise.resolve({ | ||
| templateId: 'template-id', | ||
| }), | ||
| searchParams: Promise.resolve({ lockNumber: '1' }), | ||
| }); | ||
|
|
||
| expect(redirectMock).toHaveBeenCalledWith('/invalid-template', 'replace'); | ||
| }); | ||
|
|
||
| it('should redirect to preview page when template is valid but lockNumber is missing', async () => { | ||
| getTemplateMock.mockResolvedValueOnce(AUTHORING_LETTER_TEMPLATE); | ||
|
|
||
| await GetReadyToApproveLetterTemplatePage({ | ||
| params: Promise.resolve({ | ||
| templateId: AUTHORING_LETTER_TEMPLATE.id, | ||
| }), | ||
| searchParams: Promise.resolve({ notLockNumber: 'value' }), | ||
| }); | ||
|
|
||
| expect(redirectMock).toHaveBeenCalledWith( | ||
| `/preview-letter-template/${AUTHORING_LETTER_TEMPLATE.id}`, | ||
| 'replace' | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or 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
94 changes: 94 additions & 0 deletions
94
frontend/src/app/get-ready-to-approve-letter-template/[templateId]/page.tsx
This file contains hidden or 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,94 @@ | ||
| import { Metadata } from 'next'; | ||
| import { redirect, RedirectType } from 'next/navigation'; | ||
| import { | ||
| getPreviewURL, | ||
| TemplatePageProps, | ||
| validateLetterTemplate, | ||
| } from 'nhs-notify-web-template-management-utils'; | ||
| import { ContentRenderer } from '@molecules/ContentRenderer/ContentRenderer'; | ||
| import { getTemplate } from '@utils/form-actions'; | ||
| import { interpolate } from '@utils/interpolate'; | ||
| import { NHSNotifyButton } from '@atoms/NHSNotifyButton/NHSNotifyButton'; | ||
| import { NHSNotifyContainer } from '@layouts/container/container'; | ||
| import { NHSNotifyMain } from '@atoms/NHSNotifyMain/NHSNotifyMain'; | ||
| import { $LockNumber } from 'nhs-notify-backend-client/schemas'; | ||
| import content from '@content/content'; | ||
|
|
||
| const pageContent = content.pages.getReadyToApproveLetterTemplate; | ||
|
|
||
| export async function generateMetadata(): Promise<Metadata> { | ||
| return { | ||
| title: pageContent.pageTitle, | ||
| }; | ||
| } | ||
| const GetReadyToApproveLetterTemplatePage = async ( | ||
| props: TemplatePageProps | ||
| ) => { | ||
| const { templateId } = await props.params; | ||
|
|
||
| const template = await getTemplate(templateId); | ||
|
|
||
| const validatedTemplate = validateLetterTemplate(template); | ||
|
|
||
| if (!validatedTemplate || validatedTemplate.letterVersion !== 'AUTHORING') { | ||
bhansell1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return redirect('/invalid-template', RedirectType.replace); | ||
| } | ||
|
|
||
| const searchParams = await props.searchParams; | ||
|
|
||
| const lockNumberResult = $LockNumber.safeParse(searchParams?.lockNumber); | ||
|
|
||
| if (!lockNumberResult.success) { | ||
| return redirect(getPreviewURL(validatedTemplate), RedirectType.replace); | ||
| } | ||
|
|
||
| return ( | ||
| <NHSNotifyContainer> | ||
| <NHSNotifyMain> | ||
| <div className='nhsuk-grid-row'> | ||
| <div className='nhsuk-grid-column-two-thirds'> | ||
| <span className='nhsuk-caption-xl'>{pageContent.stepCounter}</span> | ||
|
|
||
| <ContentRenderer | ||
| content={pageContent.body} | ||
| variables={{ templateName: validatedTemplate.name }} | ||
| /> | ||
|
|
||
| <div className='nhsuk-warning-callout'> | ||
bhansell1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <h3 className='nhsuk-warning-callout__label'> | ||
| {pageContent.callout.label} | ||
| <span className='nhsuk-u-visually-hidden'>:</span> | ||
| </h3> | ||
| <ContentRenderer content={pageContent.callout.content} /> | ||
| </div> | ||
|
|
||
| <div className='nhsuk-form-group'> | ||
| <NHSNotifyButton | ||
| href={interpolate(pageContent.continue.href, { | ||
| templateId: validatedTemplate.id, | ||
| lockNumber: lockNumberResult.data, | ||
| })} | ||
| data-testid='continue-button' | ||
| > | ||
| {pageContent.continue.text} | ||
| </NHSNotifyButton> | ||
|
|
||
| <NHSNotifyButton | ||
| secondary | ||
| href={interpolate(pageContent.back.href, { | ||
| templateId: validatedTemplate.id, | ||
| })} | ||
| className='nhsuk-u-margin-left-3' | ||
| data-testid='back-button' | ||
| > | ||
| {pageContent.back.text} | ||
| </NHSNotifyButton> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </NHSNotifyMain> | ||
| </NHSNotifyContainer> | ||
| ); | ||
| }; | ||
|
|
||
| export default GetReadyToApproveLetterTemplatePage; | ||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.