Skip to content

CCM-15042: letter render error handling#901

Open
ClareJonesBJSS wants to merge 14 commits intomainfrom
feature/CCM-15042_letter-gen-errors
Open

CCM-15042: letter render error handling#901
ClareJonesBJSS wants to merge 14 commits intomainfrom
feature/CCM-15042_letter-gen-errors

Conversation

@ClareJonesBJSS
Copy link
Copy Markdown
Contributor

@ClareJonesBJSS ClareJonesBJSS commented Apr 8, 2026

Description

  • Adds render check to 'Approve template'
  • Adds empty personalisations check to 'Update preview'
  • Adds new context for the errors so all error summaries can appear at the top whilst remaining separate forms
  • Tweaked the letter render tabs so they don't use unneeded form providers when we're in a read-only context
  • Amended Select, Input and FileInput atoms to correctly apply error styling, and to do so based on field id rather than name - we have to use id so that our use of htmlFor is correct, and the links in the summary go to the right place, don't love having to do the mapping when they don't match, but I don't see an alternative - Also switched a couple of places that weren't using those atoms to use them, resulting in a few fields changing outside of the scope of the ticket, along with some other snapshots updating now the styling is correct, but it felt like too small a bug to bother ticketing separately.

Screenshot_8-4-2026_16289_localhost

Screenshot_10-4-2026_94252_localhost

Context

Type of changes

  • Refactoring (non-breaking change)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would change existing functionality)
  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I am familiar with the contributing guidelines
  • I have followed the code style of the project
  • I have added tests to cover my changes
  • I have updated the documentation accordingly
  • This PR is a result of pair or mob programming

Sensitive Information Declaration

To ensure the utmost confidentiality and protect your and others privacy, we kindly ask you to NOT including PII (Personal Identifiable Information) / PID (Personal Identifiable Data) or any other sensitive data in this PR (Pull Request) and the codebase changes. We will remove any PR that do contain any sensitive information. We really appreciate your cooperation in this matter.

  • I confirm that neither PII/PID nor sensitive data are included in this PR and the codebase changes.

@ClareJonesBJSS ClareJonesBJSS requested a review from a team as a code owner April 8, 2026 15:24
@ClareJonesBJSS ClareJonesBJSS force-pushed the feature/CCM-15042_letter-gen-errors branch 3 times, most recently from 988710d to ab401d0 Compare April 9, 2026 15:29
@ClareJonesBJSS ClareJonesBJSS force-pushed the feature/CCM-15042_letter-gen-errors branch from ab401d0 to f935271 Compare April 9, 2026 16:01
});

describe('LetterRenderErrorProvider', () => {
it('renders children without error', () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't testing that it renders the child components, just that it doesn't error

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

const validatedTemplate = validateLetterTemplate(template);

if (!validatedTemplate || validatedTemplate.letterVersion !== 'AUTHORING') {
return redirect('/invalid-template', RedirectType.replace);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm probably missing something here - but why do we need this check? how would someone get here without a valid authoring letter template?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly just following established patterns of validating templates on retrieval, since I was doing the letterVersion check for type narrowing anyway

const { setParentErrorState, parentErrorState, letterRenderErrorState } =
useLetterRenderError();

useEffect(() => {
Copy link
Copy Markdown
Contributor

@chris-elliott-nhsd chris-elliott-nhsd Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does this need to be in a useEffect? also seen elsewhere

Copy link
Copy Markdown
Contributor Author

@ClareJonesBJSS ClareJonesBJSS Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

React will throw complaining that we're updating one component whilst rendering another if called directly, because we're bridging between NHSNotifyFormProvider and LetterRenderErrorProvider.

I could potentially get rid of some useEffects by making it more of a one-way thing from the letter render component and handling it in the page, but clearing one form's errors when the other triggers was tricky, and I found it much easier to pick through what was going on when I broke it out into the separate provider, plus it feels more easily reusable if we end up genning renders anywhere else

@ClareJonesBJSS ClareJonesBJSS changed the title CCM-15042: letter render error handling Draft: CCM-15042: letter render error handling Apr 10, 2026

return (
<NhsNotifyErrorSummary
errorState={parentErrorState || letterRenderErrorState}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is it called CombinedLetterErrorSummary when it's only showing one of the sets of errors?

Copy link
Copy Markdown
Contributor Author

@ClareJonesBJSS ClareJonesBJSS Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because its pulling errors from two different sources, even if only showing one at a time. Honestly this component and parentErrorState/letterRenderErrorState got renamed a few times, due to repeatedly confusing myself when it was WIP, so very happy to hear if people have other preferences 😆

@ClareJonesBJSS ClareJonesBJSS changed the title Draft: CCM-15042: letter render error handling CCM-15042: letter render error handling Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants