Skip to content

Commit

Permalink
docs: Improve email event handler docs
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed May 3, 2024
1 parent a3692eb commit 3db3831
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## EmailEventHandlerWithAsyncData

<GenerationInfo sourceFile="packages/email-plugin/src/handler/event-handler.ts" sourceLine="438" packageName="@vendure/email-plugin" />
<GenerationInfo sourceFile="packages/email-plugin/src/handler/event-handler.ts" sourceLine="446" packageName="@vendure/email-plugin" />

Identical to the <a href='/reference/core-plugins/email-plugin/email-event-handler#emaileventhandler'>EmailEventHandler</a> but with a `data` property added to the `event` based on the result
of the `.loadData()` function.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## EmailEventHandler

<GenerationInfo sourceFile="packages/email-plugin/src/handler/event-handler.ts" sourceLine="131" packageName="@vendure/email-plugin" />
<GenerationInfo sourceFile="packages/email-plugin/src/handler/event-handler.ts" sourceLine="135" packageName="@vendure/email-plugin" />

The EmailEventHandler defines how the EmailPlugin will respond to a given event.

Expand All @@ -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 }));
```
Expand Down Expand Up @@ -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 `<app root>/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 `<app root>/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" }}
Expand Down Expand Up @@ -246,7 +250,8 @@ new EmailEventListener('order-confirmation')
.setTemplateVars(event => ({
order: event.order,
payments: event.data,
}));
}))
// ...
```
### setMockEvent

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/reference/typescript-api/common/bootstrap.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Parameters

### options

<MemberInfo kind="parameter" type={`<a href='/reference/typescript-api/common/bootstrap#bootstrapoptions'>BootstrapOptions</a>`} />
<MemberInfo kind="parameter" type={`<a href='/reference/typescript-api/common/<a href='/reference/typescript-api/common/bootstrap#bootstrap'>bootstrap</a>#bootstrapoptions'>BootstrapOptions</a>`} />



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## TransactionalConnection

<GenerationInfo sourceFile="packages/core/src/connection/transactional-connection.ts" sourceLine="39" packageName="@vendure/core" />
<GenerationInfo sourceFile="packages/core/src/connection/transactional-connection.ts" sourceLine="40" packageName="@vendure/core" />

The TransactionalConnection is a wrapper around the TypeORM `Connection` object which works in conjunction
with the <a href='/reference/typescript-api/request/transaction-decorator#transaction'>Transaction</a> decorator to implement per-request transactions. All services which access the
Expand Down
16 changes: 12 additions & 4 deletions packages/email-plugin/src/handler/event-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
* ```
Expand Down Expand Up @@ -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 `<app root>/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 `<app root>/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" }}
Expand Down Expand Up @@ -144,7 +148,10 @@ export class EmailEventHandler<T extends string = string, Event extends EventWit
};
private _mockEvent: Omit<Event, 'ctx' | 'data'> | undefined;

constructor(public listener: EmailEventListener<T>, public event: Type<Event>) {}
constructor(
public listener: EmailEventListener<T>,
public event: Type<Event>,
) {}

/** @internal */
get type(): T {
Expand Down Expand Up @@ -297,7 +304,8 @@ export class EmailEventHandler<T extends string = string, Event extends EventWit
* .setTemplateVars(event => ({
* order: event.order,
* payments: event.data,
* }));
* }))
* // ...
* ```
*/
loadData<R>(
Expand Down

0 comments on commit 3db3831

Please sign in to comment.