-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconst.ts
92 lines (86 loc) · 3.36 KB
/
const.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { type ComponentType } from "react";
import { type EmailEventType } from "@/const";
import CustomEventEmail from "@/emails/templates/custom/CustomEventEmail";
import AccountChangeEmailRequestedEmail from "@/emails/templates/saleor/AccountChangeEmailRequestedEmail";
import AccountConfirmationRequestedEmail from "@/emails/templates/saleor/AccountConfirmationRequestedEmail";
import AccountConfirmedEmail from "@/emails/templates/saleor/AccountConfirmedEmail";
import AccountDeletedEmail from "@/emails/templates/saleor/AccountDeletedEmail";
import AccountDeleteRequestedEmail from "@/emails/templates/saleor/AccountDeleteRequestedEmail";
import AccountEmailChangedEmail from "@/emails/templates/saleor/AccountEmailChangedEmail";
import AccountSetPasswordRequestedEmail from "@/emails/templates/saleor/AccountSetPasswordRequestedEmail";
import FulfillmentCreatedEmail from "@/emails/templates/saleor/FulfillmentCreatedEmail";
import FulfillmentTrackingNumberUpdatedEmail from "@/emails/templates/saleor/FulfillmentTrackingNumberUpdatedEmail";
import GiftCardSentEmail from "@/emails/templates/saleor/GiftCardSentEmail";
import OrderCancelledEmail from "@/emails/templates/saleor/OrderCancelledEmail";
import OrderCreatedEmail from "@/emails/templates/saleor/OrderCreatedEmail";
import OrderRefundedEmail from "@/emails/templates/saleor/OrderRefundedEmail";
const extractEmailFromOrder = (data: { order: { userEmail: string } }) =>
data.order.userEmail;
const extractEmailFromGiftCard = (data: { sentToEmail: string }) =>
data.sentToEmail;
const extractEmailFromUser = (data: { user: { email: string } }) =>
data.user.email;
const extractEmailFromCustomEvent = (data: { email: string }) => data.email;
export const TEMPLATES_MAP: {
[key in EmailEventType]?: {
extractFn: (data: any) => string;
template: ComponentType<any> & { getSubject: (data: any) => string };
};
} = {
order_created: {
template: OrderCreatedEmail,
extractFn: extractEmailFromOrder,
},
order_cancelled: {
template: OrderCancelledEmail,
extractFn: extractEmailFromOrder,
},
order_refunded: {
template: OrderRefundedEmail,
extractFn: extractEmailFromOrder,
},
fulfillment_created: {
template: FulfillmentCreatedEmail,
extractFn: extractEmailFromOrder,
},
fulfillment_tracking_number_updated: {
template: FulfillmentTrackingNumberUpdatedEmail,
extractFn: extractEmailFromOrder,
},
gift_card_sent: {
template: GiftCardSentEmail,
extractFn: extractEmailFromGiftCard,
},
account_set_password_requested: {
template: AccountSetPasswordRequestedEmail,
extractFn: extractEmailFromUser,
},
account_email_changed: {
template: AccountEmailChangedEmail,
extractFn: extractEmailFromUser,
},
account_delete_requested: {
template: AccountDeleteRequestedEmail,
extractFn: extractEmailFromUser,
},
account_deleted: {
template: AccountDeletedEmail,
extractFn: extractEmailFromUser,
},
account_confirmed: {
template: AccountConfirmedEmail,
extractFn: extractEmailFromUser,
},
account_confirmation_requested: {
template: AccountConfirmationRequestedEmail,
extractFn: extractEmailFromUser,
},
account_change_email_requested: {
template: AccountChangeEmailRequestedEmail,
extractFn: extractEmailFromUser,
},
custom_event: {
template: CustomEventEmail,
extractFn: extractEmailFromCustomEvent,
},
};