-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Add a function to manually send or resend (EmailEventHandler trigger) email to the UI for Order and Customer #3016
Comments
This is a feature I'm working on at the moment and I'd love to see it inside vendure core. Once my task is complete, I can create a PR to solve this problem for our company and also for the Vendure Community |
Also, I'd like to add an sms plugin. Absolutely the same as for EmailPlugin. I would like to have such a plugin inside Vendure core And also I want to add a function to translate text in a template by keys using i18n. With this, it will be possible to use just 1 template for different languages |
Hi Eugene, Thanks for this thoughtful suggestion. I agree that it would be good to support the ability to re-send emails. Here are my first thoughts based on the outline you provided. (note: I wrote this as I was reading and understanding the PR, so there is a bit of back-and-forth as I get a better idea of your concept). General implementationI find the naming of the "handler" function unintuitive, and based on the
Admin UI partsWill the Admin UI need to have a coupling with the EmailPlugin now? Or do you plan to use a ui extension to implement the required UI parts? Danger of re-publishing events
I just looked at the actual implementation and realized that you already thought of this and it is not an issue 👍 NamingThe handler function As mentioned above I think this is mis-named. filter function The part specifically dealing with the UI is the But also looking at the implementation in the PR, this function is also used to prevent re-publishing the event. In which case maybe idea: do we need 2 separate functions? Thinking about these 2 functions further, I am wondering whether we really need 2 separate functions? What is we had a single function like this? createEvent: (
ctx: RequestContext,
injector: Injector,
entity: InstanceType<E>,
languageCode?: LanguageCode,
) => Promise<InputEvent | false> | InputEvent | false; then, if the given entity is not eligible for re-send for whatever reason, you return false. What are you thoughts on this approach? SummaryIn summary I like the general direction of this proposal and think we should go ahead with adding it to the EmailPlugin.
Please open separate issues for these. Both sound interesting, I'd like to hear more detail on what you think this would involve. |
Yeah, you got that right. At the moment I wrote the code I have just to test this idea, I tried to do it as soon as possible. Now that you have approved this feature I will rename all methods and variables to be more in line with this function. Today I'm gonna create a separate issues for SMS and translations |
I'm thinking of adding UI as custom component which will be inside EmailPlugin |
I also thought a lot about how to make it possible to provide a special UI that could be added to pass some special data to generate an EmailEvent. We have a plugin with which we use dynamic email templates that admins add themselves via Vendure UI Admin. This solution is ideal for creating a select component to select a template, since the event is used the same. This is not the final version yet, but I'm still working on it This should make a very versatile function for manually sending emails or sms export interface EventHandlerResendOptions<
InputEvent extends EventWithContext = EventWithContext,
Entity extends UIEmailEventEntities = UIEmailEventEntities,
ConfArgs extends ConfigArgs = ConfigArgs,
> {
entityType: Entity;
label: Array<Omit<LocalizedString, '__typename'>>;
description?: Array<Omit<LocalizedString, '__typename'>>;
options?: ConfigurableOperationDefOptions<ConfArgs>;
createEvent: (
ctx: RequestContext,
injector: Injector,
entity: InstanceType<Entity>,
args: ConfigArgValues<ConfArgs>,
) => Promise<InputEvent> | InputEvent;
canResend: (
ctx: RequestContext,
injector: Injector,
entity: InstanceType<Entity>,
) => Promise<boolean> | boolean;
}
const orderConfirmationHandler = new EmailEventListener('order-confirmation')
.on(OrderStateTransitionEvent)
.filter(
event =>
event.toState === 'PaymentSettled' && event.fromState !== 'Modifying' && !!event.order.customer,
)
.setResendOptions({
entityType: Order,
label: [
{
value: 'Order confirmation.',
languageCode: LanguageCode.en,
},
],
description: [
{
value: 'Order confirmation can be send only for specific reasons.',
languageCode: LanguageCode.en,
},
],
options: { // **this is ConfigurableOperationDefOptions**
// this is just an example how we can use it with custom UI component, it will be super extendable
description: [],
args: {
emailEventTemplateId: {
type: 'ID',
ui: { component: 'email-event-template-list' },
label: [{ languageCode: LanguageCode.en, value: 'Select specific event email' }],
},
},
},
canResend: (_ctx, _injector, _entity) => {
return true;
},
createEvent: (ctx, _injector, entity, _args) => {
return new OrderStateTransitionEvent('ArrangingPayment', 'PaymentSettled', ctx, entity);
},
}) |
Is your feature request related to a problem? Please describe.
At the moment we need to add the ability to send some emails to our customers because sometimes they may add the wrong email in their order and do not receive notification that the order needs to be paid or that the order has been paid. Due to the fact that we don't have a feature to manually send emails from admin panel, we needed a feature to allow our managers to send emails at any time just by clicking the button.
Describe the solution you'd like
I reviewed the available options and discovered an interesting approach.
We can extend
EmailEventHandler
and add a property to specify a UI block for displaying the list of emails to resend, along with a function to generate the event from the UI. For instance, we can introducesetUiOptions
and add properties likeblock(order, customer)
and a function to generate data for these events.This way, you can automatically integrate events into pre-prepared UI blocks. When adding a new event, you only need to create an event generator function, which can then be incorporated into Vendure core.
This enhancement can be added to the default
EmailPlugin
.API:
This way we can get a list of events with data on which events need to be added to the UI in order to be able to resend an email
Describe alternatives you've considered
From the alternatives I found only ways in which you need to manually add these blocks to the interface and process for each event request for sending separately
The text was updated successfully, but these errors were encountered: