From 3db383133f27e2e3b865aff4e69ad1b06b9baa49 Mon Sep 17 00:00:00 2001 From: Michael Bromley Date: Fri, 3 May 2024 16:27:40 +0200 Subject: [PATCH] docs: Improve email event handler docs --- .../email-event-handler-with-async-data.md | 2 +- .../email-plugin/email-event-handler.md | 13 +++++++++---- .../reference/typescript-api/common/bootstrap.md | 2 +- .../data-access/transactional-connection.md | 2 +- .../email-plugin/src/handler/event-handler.ts | 16 ++++++++++++---- 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/docs/docs/reference/core-plugins/email-plugin/email-event-handler-with-async-data.md b/docs/docs/reference/core-plugins/email-plugin/email-event-handler-with-async-data.md index 0791f30ccb..5482ee6e99 100644 --- a/docs/docs/reference/core-plugins/email-plugin/email-event-handler-with-async-data.md +++ b/docs/docs/reference/core-plugins/email-plugin/email-event-handler-with-async-data.md @@ -11,7 +11,7 @@ import MemberDescription from '@site/src/components/MemberDescription'; ## EmailEventHandlerWithAsyncData - + Identical to the EmailEventHandler but with a `data` property added to the `event` based on the result of the `.loadData()` function. diff --git a/docs/docs/reference/core-plugins/email-plugin/email-event-handler.md b/docs/docs/reference/core-plugins/email-plugin/email-event-handler.md index 90ca488d06..5e925c154c 100644 --- a/docs/docs/reference/core-plugins/email-plugin/email-event-handler.md +++ b/docs/docs/reference/core-plugins/email-plugin/email-event-handler.md @@ -11,7 +11,7 @@ import MemberDescription from '@site/src/components/MemberDescription'; ## EmailEventHandler - + The EmailEventHandler defines how the EmailPlugin will respond to a given event. @@ -25,6 +25,7 @@ const confirmationHandler = new EmailEventListener('order-confirmation') .on(OrderStateTransitionEvent) .filter(event => event.toState === 'PaymentSettled') .setRecipient(event => event.order.customer.emailAddress) + .setFrom('{{ fromAddress }}') .setSubject(`Order confirmation for #{{ order.code }}`) .setTemplateVars(event => ({ order: event.order })); ``` @@ -74,13 +75,16 @@ const quoteRequestedHandler = new EmailEventListener('quote-requested') .on(QuoteRequestedEvent) .setRecipient(event => event.customer.emailAddress) .setSubject(`Here's the quote you requested`) + .setFrom('{{ fromAddress }}') .setTemplateVars(event => ({ details: event.details })); ``` ### 2. Create the email template -Next you need to make sure there is a template defined at `/static/email/templates/quote-requested/body.hbs`. The template -would look something like this: +Next you need to make sure there is a template defined at `/static/email/templates/quote-requested/body.hbs`. The path +segment `quote-requested` must match the string passed to the `EmailEventListener` constructor. + +The template would look something like this: ```handlebars {{> header title="Here's the quote you requested" }} @@ -246,7 +250,8 @@ new EmailEventListener('order-confirmation') .setTemplateVars(event => ({ order: event.order, payments: event.data, - })); + })) + // ... ``` ### setMockEvent diff --git a/docs/docs/reference/typescript-api/common/bootstrap.md b/docs/docs/reference/typescript-api/common/bootstrap.md index 76434b8202..bfd0b186ea 100644 --- a/docs/docs/reference/typescript-api/common/bootstrap.md +++ b/docs/docs/reference/typescript-api/common/bootstrap.md @@ -60,7 +60,7 @@ Parameters ### options -BootstrapOptions`} /> +bootstrap#bootstrapoptions'>BootstrapOptions`} /> diff --git a/docs/docs/reference/typescript-api/data-access/transactional-connection.md b/docs/docs/reference/typescript-api/data-access/transactional-connection.md index 06bc553b84..449dd1ec44 100644 --- a/docs/docs/reference/typescript-api/data-access/transactional-connection.md +++ b/docs/docs/reference/typescript-api/data-access/transactional-connection.md @@ -11,7 +11,7 @@ import MemberDescription from '@site/src/components/MemberDescription'; ## TransactionalConnection - + The TransactionalConnection is a wrapper around the TypeORM `Connection` object which works in conjunction with the Transaction decorator to implement per-request transactions. All services which access the diff --git a/packages/email-plugin/src/handler/event-handler.ts b/packages/email-plugin/src/handler/event-handler.ts index 85a66c1158..773f8f651f 100644 --- a/packages/email-plugin/src/handler/event-handler.ts +++ b/packages/email-plugin/src/handler/event-handler.ts @@ -30,6 +30,7 @@ import { * .on(OrderStateTransitionEvent) * .filter(event => event.toState === 'PaymentSettled') * .setRecipient(event => event.order.customer.emailAddress) + * .setFrom('{{ fromAddress }}') * .setSubject(`Order confirmation for #{{ order.code }}`) * .setTemplateVars(event => ({ order: event.order })); * ``` @@ -78,13 +79,16 @@ import { * .on(QuoteRequestedEvent) * .setRecipient(event => event.customer.emailAddress) * .setSubject(`Here's the quote you requested`) + * .setFrom('{{ fromAddress }}') * .setTemplateVars(event => ({ details: event.details })); * ``` * * ### 2. Create the email template * - * Next you need to make sure there is a template defined at `/static/email/templates/quote-requested/body.hbs`. The template - * would look something like this: + * Next you need to make sure there is a template defined at `/static/email/templates/quote-requested/body.hbs`. The path + * segment `quote-requested` must match the string passed to the `EmailEventListener` constructor. + * + * The template would look something like this: * * ```handlebars * {{> header title="Here's the quote you requested" }} @@ -144,7 +148,10 @@ export class EmailEventHandler | undefined; - constructor(public listener: EmailEventListener, public event: Type) {} + constructor( + public listener: EmailEventListener, + public event: Type, + ) {} /** @internal */ get type(): T { @@ -297,7 +304,8 @@ export class EmailEventHandler ({ * order: event.order, * payments: event.data, - * })); + * })) + * // ... * ``` */ loadData(