PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.8
Yatra – Travel Booking & Tour Operator Software v3.0.8
3.0.16 3.0.15 3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 All 84 releases
yatra / resources / js / lib / email-templates-catalog.ts

email-templates-catalog.ts in Yatra – Travel Booking & Tour Operator Software 3.0.8, at resources/js/lib/email-templates-catalog.ts

700 lines 26.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Canonical list of system email templates (aligned with Yatra Pro seeds).
3 * When Email Automation is off, settings-backed templates stay editable in the free plugin;
4 * Pro-only catalog rows stay visible but locked until Pro + Email Automation is on.
5 * Module-gated templates (e.g. trip consent, abandoned recovery) stay listed with real
6 * on/off + content from site settings while the module is off — view-only until the module is active.
7 */
8
9 import { __, sprintf, brandName } from "./i18n";
10
11 // Pre-compute "{brand} Pro" once at module load. Used by the
12 // operator-facing template descriptions below so a white-labelled
13 // site shows the operator's brand instead of literal "Yatra Pro".
14 // brandName() reads window.yatraAdmin.brandName which is injected
15 // before any React module loads, so this value is always correct.
16 const BRAND_PRO_NAME = brandName() + " Pro";
17 import type { EmailSettingsValues } from "../components/settings/email-settings-types";
18
19 /** Rich booking merge tags (gateway, schedule, travelers, booking meta, special requests). */
20 const BOOKING_RICH_MERGE_TAGS =
21 "{{payment_gateway}}, {{payment_gateway_label}}, {{payment_schedule}}, {{payment_schedule_label}}, {{travelers_list}}, {{travelers_list_html}}, {{traveler_custom_fields_html}}, {{booking_custom_fields_html}}, {{special_requests}}, {{special_requests_html}}";
22
23 export type EmailCatalogEntry = {
24 template_key: string;
25 event_key: string;
26 name: string;
27 description: string;
28 category: string;
29 recipient_type: "customer" | "admin";
30 to_email: string;
31 /** When true, subject/body/active map to EmailSettingsValues keys. */
32 isCoreFree: boolean;
33 /** If set, subject/body cannot be edited until Pro + this module slug is active (row still listed). */
34 requiresModule?: string;
35 settingsFlag?: keyof EmailSettingsValues;
36 settingsSubject?: keyof EmailSettingsValues;
37 settingsBody?: keyof EmailSettingsValues;
38 /** Shown in core editor sidebar for merge tags */
39 mergeTags?: string;
40 };
41
42 export const CORE_FREE_TEMPLATE_KEYS = [
43 "booking_confirmation",
44 "payment_received",
45 "booking_cancelled",
46 "trip_reminder",
47 "trip_consent_request",
48 "customer_email_verification",
49 "guest_email_verification",
50 "booking_completed",
51 "booking_expired_customer",
52 "admin_booking_expired",
53 "scheduled_payment_reminder",
54 "scheduled_payment_succeeded",
55 "scheduled_payment_failed",
56 "admin_scheduled_payment_failed",
57 "enquiry_received",
58 "enquiry_admin",
59 "enquiry_response",
60 "review_request",
61 "abandoned_booking_recovery_first",
62 "abandoned_booking_recovery_second",
63 "abandoned_booking_recovery_final",
64 "admin_new_booking",
65 "admin_payment_received",
66 "admin_booking_cancelled",
67 ] as const;
68
69 export type CoreFreeTemplateKey = (typeof CORE_FREE_TEMPLATE_KEYS)[number];
70
71 export function isCoreTemplateSlug(
72 slug: string | null | undefined,
73 ): slug is CoreFreeTemplateKey {
74 return (
75 !!slug && (CORE_FREE_TEMPLATE_KEYS as readonly string[]).includes(slug)
76 );
77 }
78
79 export const EMAIL_TEMPLATES_CATALOG: EmailCatalogEntry[] = [
80 {
81 template_key: "booking_confirmation",
82 event_key: "booking.created",
83 name: __("Booking Confirmation", "yatra"),
84 description: __(
85 "Customer email for checkout, admin bookings, and confirmed status.",
86 "yatra",
87 ),
88 category: "booking",
89 recipient_type: "customer",
90 to_email: "{customer_email}",
91 isCoreFree: true,
92 settingsFlag: "email_template_booking",
93 settingsSubject: "email_tpl_booking_subject",
94 settingsBody: "email_tpl_booking_body",
95 mergeTags:
96 "{{site_name}}, {{customer_name}}, {{customer_first_name}}, {{booking_reference}}, {{booking_id}}, {{trip_name}}, {{travel_date}}, {{travelers_count}}, {{total_amount_formatted}}, {{amount_due_formatted}}, {{currency}}, {{intro_paragraph}}, {{details_html}}, {{footer_note}}, " +
97 BOOKING_RICH_MERGE_TAGS,
98 },
99 {
100 template_key: "payment_received",
101 event_key: "payment.received",
102 name: __("Payment Received", "yatra"),
103 description: __("Sent when a payment is recorded for a booking.", "yatra"),
104 category: "payment",
105 recipient_type: "customer",
106 to_email: "{customer_email}",
107 isCoreFree: true,
108 settingsFlag: "email_template_confirmation",
109 settingsSubject: "email_tpl_payment_subject",
110 settingsBody: "email_tpl_payment_body",
111 mergeTags:
112 "{{site_name}}, {{customer_name}}, {{customer_first_name}}, {{booking_reference}}, {{trip_name}}, {{travel_date}}, {{payment_amount_formatted}}, {{payment_method}}, {{transaction_id}}, {{total_amount_formatted}}, {{currency}}, " +
113 BOOKING_RICH_MERGE_TAGS,
114 },
115 {
116 template_key: "booking_cancelled",
117 event_key: "booking.cancelled",
118 name: __("Booking Cancellation", "yatra"),
119 description: __("Sent when a booking is marked cancelled.", "yatra"),
120 category: "booking",
121 recipient_type: "customer",
122 to_email: "{customer_email}",
123 isCoreFree: true,
124 settingsFlag: "email_template_cancellation",
125 settingsSubject: "email_tpl_cancellation_subject",
126 settingsBody: "email_tpl_cancellation_body",
127 mergeTags:
128 "{{site_name}}, {{customer_name}}, {{customer_first_name}}, {{booking_reference}}, {{trip_name}}, {{travel_date}}, {{travelers_count}}, " +
129 BOOKING_RICH_MERGE_TAGS,
130 },
131 {
132 template_key: "trip_reminder",
133 event_key: "reminder.trip",
134 name: __("Trip Reminder", "yatra"),
135 description: __(
136 "Scheduled reminder before departure (see Booking settings).",
137 "yatra",
138 ),
139 category: "reminder",
140 recipient_type: "customer",
141 to_email: "{customer_email}",
142 isCoreFree: true,
143 settingsFlag: "email_template_reminder",
144 settingsSubject: "email_tpl_reminder_subject",
145 settingsBody: "email_tpl_reminder_body",
146 mergeTags:
147 "{{site_name}}, {{customer_name}}, {{booking_reference}}, {{trip_name}}, {{travel_date}}, {{travelers_count}}, {{reminder_days}}, {{days_until_trip}}, {{amount_due_formatted}}, {{reminder_extra_html}}, " +
148 BOOKING_RICH_MERGE_TAGS,
149 },
150 {
151 template_key: "trip_consent_request",
152 event_key: "consent.requested",
153 name: __("Trip consent request", "yatra"),
154 description: __(
155 "Sent when a traveler must sign a trip consent form (Trip Consent module).",
156 "yatra",
157 ),
158 category: "booking",
159 recipient_type: "customer",
160 to_email: "{customer_email}",
161 isCoreFree: true,
162 requiresModule: "trip_consent",
163 settingsFlag: "email_template_trip_consent",
164 settingsSubject: "email_tpl_trip_consent_subject",
165 settingsBody: "email_tpl_trip_consent_body",
166 mergeTags:
167 "{{site_name}}, {{recipient_name}}, {{form_name}}, {{consent_link}}, {{trip_name}}, {{travel_date}}, {{booking_reference}}, {{expiry_notice_html}}, {{consent_test_notice_html}}",
168 },
169 {
170 template_key: "customer_email_verification",
171 event_key: "account.email_verification",
172 name: __("Customer email verification", "yatra"),
173 description: __(
174 "Sent when a customer registers (e.g. from checkout) and must verify their email before logging in.",
175 "yatra",
176 ),
177 category: "account",
178 recipient_type: "customer",
179 to_email: "{customer_email}",
180 isCoreFree: true,
181 settingsFlag: "email_template_customer_verification",
182 settingsSubject: "email_tpl_customer_verification_subject",
183 settingsBody: "email_tpl_customer_verification_body",
184 mergeTags:
185 "{{site_name}}, {{site_url}}, {{customer_first_name}}, {{customer_name}}, {{verification_link}}, {{intro_paragraph}}, {{expiry_notice_html}}, {{footer_note}}",
186 },
187 {
188 template_key: "guest_email_verification",
189 event_key: "account.email_verification",
190 name: __("Guest email verification (checkout)", "yatra"),
191 description: __(
192 "Sent to a guest at checkout who must verify their email before the booking is finalized (when 'Require guest email verification' is enabled). Distinct from the account-registration verification above.",
193 "yatra",
194 ),
195 category: "account",
196 recipient_type: "customer",
197 to_email: "{customer_email}",
198 isCoreFree: true,
199 settingsFlag: "email_template_guest_verification",
200 settingsSubject: "email_tpl_guest_verification_subject",
201 settingsBody: "email_tpl_guest_verification_body",
202 mergeTags:
203 "{{site_name}}, {{site_url}}, {{customer_first_name}}, {{customer_name}}, {{verification_link}}, {{intro_paragraph}}, {{expiry_notice_html}}, {{footer_note}}",
204 },
205 {
206 template_key: "admin_new_booking",
207 event_key: "booking.created",
208 name: __("Admin: New Booking", "yatra"),
209 description: __(
210 "Sent to your admin email when a booking is created. Turn off here to stop this email.",
211 "yatra",
212 ),
213 category: "booking",
214 recipient_type: "admin",
215 to_email: "{{admin_email}}",
216 isCoreFree: true,
217 settingsFlag: "email_template_admin_new_booking",
218 settingsSubject: "email_tpl_admin_booking_subject",
219 settingsBody: "email_tpl_admin_booking_body",
220 mergeTags:
221 "{{site_name}}, {{site_url}}, {{admin_url}}, {{booking_reference}}, {{booking_id}}, {{customer_name}}, {{customer_email}}, {{customer_phone}}, {{trip_name}}, {{travel_date}}, {{travelers_count}}, {{total_amount_formatted}}, {{currency}}, {{booking_status}}, {{payment_status}}, " +
222 BOOKING_RICH_MERGE_TAGS,
223 },
224 {
225 template_key: "admin_payment_received",
226 event_key: "payment.received",
227 name: __("Admin: Payment received", "yatra"),
228 description: __(
229 "Sent to your admin email when a payment is recorded. Customer receipt uses the Payment Received template.",
230 "yatra",
231 ),
232 category: "payment",
233 recipient_type: "admin",
234 to_email: "{{admin_email}}",
235 isCoreFree: true,
236 settingsFlag: "email_template_admin_payment",
237 settingsSubject: "email_tpl_admin_payment_subject",
238 settingsBody: "email_tpl_admin_payment_body",
239 mergeTags:
240 "{{site_name}}, {{admin_url}}, {{booking_reference}}, {{booking_id}}, {{customer_name}}, {{payment_amount_formatted}}, {{payment_method}}, {{transaction_id}}, " +
241 BOOKING_RICH_MERGE_TAGS,
242 },
243 {
244 template_key: "admin_booking_cancelled",
245 event_key: "booking.cancelled",
246 name: __("Admin: Booking cancelled", "yatra"),
247 description: __(
248 "Sent to your admin email when a booking is cancelled. Customer notice uses the Booking Cancellation template.",
249 "yatra",
250 ),
251 category: "booking",
252 recipient_type: "admin",
253 to_email: "{{admin_email}}",
254 isCoreFree: true,
255 settingsFlag: "email_template_admin_cancellation",
256 settingsSubject: "email_tpl_admin_cancellation_subject",
257 settingsBody: "email_tpl_admin_cancellation_body",
258 mergeTags:
259 "{{site_name}}, {{admin_url}}, {{booking_reference}}, {{booking_id}}, {{customer_name}}, {{trip_name}}, {{travel_date}}, " +
260 BOOKING_RICH_MERGE_TAGS,
261 },
262 {
263 template_key: "new_booking",
264 event_key: "booking.created",
265 name: __("New Booking Confirmation", "yatra"),
266 description: __(
267 "Pro automation alternative for the free Booking Confirmation template. Enable Email Automation to edit and send.",
268 "yatra",
269 ),
270 category: "booking",
271 recipient_type: "customer",
272 to_email: "{customer_email}",
273 isCoreFree: false,
274 // Gate behind Email Automation so the free / Pro versions don't appear as
275 // a confusing duplicate in the customer's view (e.g. two "Payment Received"
276 // rows). isModuleGatedLocked() reads this and locks the row when the
277 // module isn't active.
278 requiresModule: "email_automation",
279 },
280 {
281 template_key: "booking_payment",
282 event_key: "payment.received",
283 name: __("Booking payment notice", "yatra"),
284 description: __(
285 "Pro automation alternative for the free Payment Received template. Enable Email Automation to edit and send.",
286 "yatra",
287 ),
288 category: "payment",
289 recipient_type: "customer",
290 to_email: "{customer_email}",
291 isCoreFree: false,
292 requiresModule: "email_automation",
293 },
294 {
295 template_key: "booking_confirmed",
296 event_key: "booking.confirmed",
297 name: __("Booking Confirmed", "yatra"),
298 description: __(
299 "Pro automation template fired on booking confirmation. Enable Email Automation to edit and send.",
300 "yatra",
301 ),
302 category: "booking",
303 recipient_type: "customer",
304 to_email: "{customer_email}",
305 isCoreFree: false,
306 requiresModule: "email_automation",
307 },
308 {
309 template_key: "booking_completed",
310 event_key: "booking.completed",
311 name: __("Trip completed", "yatra"),
312 description: __(
313 "Sent when a booking is marked completed (after travel).",
314 "yatra",
315 ),
316 category: "booking",
317 recipient_type: "customer",
318 to_email: "{customer_email}",
319 isCoreFree: true,
320 settingsFlag: "email_template_booking_completed",
321 settingsSubject: "email_tpl_booking_completed_subject",
322 settingsBody: "email_tpl_booking_completed_body",
323 mergeTags:
324 "{{site_name}}, {{customer_name}}, {{booking_reference}}, {{booking_id}}, {{trip_name}}, {{travel_date}}, {{trip_url}}, " +
325 BOOKING_RICH_MERGE_TAGS,
326 },
327 {
328 template_key: "booking_expired_customer",
329 event_key: "booking.expired",
330 name: __("Booking expired (customer)", "yatra"),
331 description: __(
332 "Sent when a pending booking is auto-cancelled for non-payment.",
333 "yatra",
334 ),
335 category: "booking",
336 recipient_type: "customer",
337 to_email: "{customer_email}",
338 isCoreFree: true,
339 settingsFlag: "email_template_booking_expired_customer",
340 settingsSubject: "email_tpl_booking_expired_customer_subject",
341 settingsBody: "email_tpl_booking_expired_customer_body",
342 mergeTags:
343 "{{site_name}}, {{customer_name}}, {{booking_reference}}, {{trip_name}}, {{travel_date}}, {{trip_url}}, {{expiry_policy_note}}, " +
344 BOOKING_RICH_MERGE_TAGS,
345 },
346 {
347 template_key: "admin_booking_expired",
348 event_key: "booking.expired",
349 name: __("Admin: Booking expired", "yatra"),
350 description: __(
351 "Admin notice when a booking is auto-cancelled for non-payment.",
352 "yatra",
353 ),
354 category: "booking",
355 recipient_type: "admin",
356 to_email: "{{admin_email}}",
357 isCoreFree: true,
358 settingsFlag: "email_template_admin_booking_expired",
359 settingsSubject: "email_tpl_admin_booking_expired_subject",
360 settingsBody: "email_tpl_admin_booking_expired_body",
361 mergeTags:
362 "{{site_name}}, {{admin_url}}, {{booking_reference}}, {{booking_id}}, {{customer_name}}, {{customer_email}}, {{trip_name}}, " +
363 BOOKING_RICH_MERGE_TAGS,
364 },
365 {
366 template_key: "scheduled_payment_reminder",
367 event_key: "scheduled.payment.reminder",
368 name: __("Scheduled payment reminder", "yatra"),
369 description: __(
370 "Sent before an installment or gateway-scheduled charge when Scheduled payments is enabled in settings.",
371 "yatra",
372 ),
373 category: "payment",
374 recipient_type: "customer",
375 to_email: "{customer_email}",
376 isCoreFree: true,
377 requiresModule: "scheduled_payments",
378 settingsFlag: "email_template_scheduled_payment_reminder",
379 settingsSubject: "email_tpl_scheduled_payment_reminder_subject",
380 settingsBody: "email_tpl_scheduled_payment_reminder_body",
381 mergeTags:
382 "{{site_name}}, {{customer_first_name}}, {{customer_name}}, {{booking_reference}}, {{booking_id}}, {{trip_name}}, {{trip_url}}, {{scheduled_amount_formatted}}, {{scheduled_date_formatted}}, {{payment_type_label}}, {{scheduled_payment_id}}, {{currency}}, " +
383 BOOKING_RICH_MERGE_TAGS,
384 },
385 {
386 template_key: "scheduled_payment_succeeded",
387 event_key: "scheduled.payment.succeeded",
388 name: __("Scheduled payment succeeded", "yatra"),
389 description: __(
390 "Sent after a scheduled / installment charge succeeds.",
391 "yatra",
392 ),
393 category: "payment",
394 recipient_type: "customer",
395 to_email: "{customer_email}",
396 isCoreFree: true,
397 requiresModule: "scheduled_payments",
398 settingsFlag: "email_template_scheduled_payment_succeeded",
399 settingsSubject: "email_tpl_scheduled_payment_succeeded_subject",
400 settingsBody: "email_tpl_scheduled_payment_succeeded_body",
401 mergeTags:
402 "{{site_name}}, {{customer_first_name}}, {{customer_name}}, {{booking_reference}}, {{booking_id}}, {{trip_name}}, {{scheduled_amount_formatted}}, {{payment_type_label}}, {{balance_after_formatted}}, {{scheduled_payment_id}}, {{currency}}, " +
403 BOOKING_RICH_MERGE_TAGS,
404 },
405 {
406 template_key: "scheduled_payment_failed",
407 event_key: "scheduled.payment.failed",
408 name: __("Scheduled payment failed", "yatra"),
409 description: __(
410 "Sent when a scheduled charge fails (temporary or final).",
411 "yatra",
412 ),
413 category: "payment",
414 recipient_type: "customer",
415 to_email: "{customer_email}",
416 isCoreFree: true,
417 requiresModule: "scheduled_payments",
418 settingsFlag: "email_template_scheduled_payment_failed",
419 settingsSubject: "email_tpl_scheduled_payment_failed_subject",
420 settingsBody: "email_tpl_scheduled_payment_failed_body",
421 mergeTags:
422 "{{site_name}}, {{customer_first_name}}, {{customer_name}}, {{booking_reference}}, {{booking_id}}, {{trip_name}}, {{scheduled_amount_formatted}}, {{scheduled_payment_id}}, {{failure_reason}}, {{failure_intro_html}}, {{failure_followup_html}}, " +
423 BOOKING_RICH_MERGE_TAGS,
424 },
425 {
426 template_key: "admin_scheduled_payment_failed",
427 event_key: "scheduled.payment.failed",
428 name: __("Admin: Scheduled payment failed", "yatra"),
429 description: __(
430 "Admin notice when a scheduled payment permanently fails.",
431 "yatra",
432 ),
433 category: "payment",
434 recipient_type: "admin",
435 to_email: "{{admin_email}}",
436 isCoreFree: true,
437 requiresModule: "scheduled_payments",
438 settingsFlag: "email_template_admin_scheduled_payment_failed",
439 settingsSubject: "email_tpl_admin_scheduled_payment_failed_subject",
440 settingsBody: "email_tpl_admin_scheduled_payment_failed_body",
441 mergeTags:
442 "{{site_name}}, {{admin_url}}, {{booking_reference}}, {{booking_id}}, {{trip_name}}, {{customer_name}}, {{customer_email}}, {{scheduled_amount_formatted}}, {{scheduled_payment_id}}, {{failure_reason}}, " +
443 BOOKING_RICH_MERGE_TAGS,
444 },
445 {
446 template_key: "payment_reminder",
447 event_key: "payment.reminder",
448 name: __("Payment Reminder", "yatra"),
449 description: __(
450 "Pro automation template. Enable Email Automation to edit and send.",
451 "yatra",
452 ),
453 category: "payment",
454 recipient_type: "customer",
455 to_email: "{customer_email}",
456 isCoreFree: false,
457 },
458 {
459 template_key: "enquiry_received",
460 event_key: "enquiry.created",
461 name: __("Enquiry Received", "yatra"),
462 description: __(
463 "Confirmation sent to the customer after they submit an enquiry.",
464 "yatra",
465 ),
466 category: "enquiry",
467 recipient_type: "customer",
468 to_email: "{customer_email}",
469 isCoreFree: true,
470 settingsFlag: "email_template_enquiry_received",
471 settingsSubject: "email_tpl_enquiry_received_subject",
472 settingsBody: "email_tpl_enquiry_received_body",
473 mergeTags:
474 "{{site_name}}, {{customer_name}}, {{customer_email}}, {{customer_phone}}, {{trip_name}}, {{trip_url}}, {{message}}",
475 },
476 {
477 template_key: "enquiry_admin",
478 event_key: "enquiry.created",
479 name: __("Admin: New Enquiry", "yatra"),
480 description: __(
481 "Sent to your admin email when a new enquiry is submitted.",
482 "yatra",
483 ),
484 category: "enquiry",
485 recipient_type: "admin",
486 to_email: "{{admin_email}}",
487 isCoreFree: true,
488 settingsFlag: "email_template_enquiry_admin",
489 settingsSubject: "email_tpl_enquiry_admin_subject",
490 settingsBody: "email_tpl_enquiry_admin_body",
491 mergeTags:
492 "{{site_name}}, {{admin_url}}, {{customer_name}}, {{customer_email}}, {{customer_phone}}, {{trip_name}}, {{message}}",
493 },
494 {
495 template_key: "enquiry_response",
496 event_key: "enquiry.responded",
497 name: __("Enquiry Response", "yatra"),
498 description: __(
499 "Sent to the customer when you reply to their enquiry.",
500 "yatra",
501 ),
502 category: "enquiry",
503 recipient_type: "customer",
504 to_email: "{customer_email}",
505 isCoreFree: true,
506 settingsFlag: "email_template_enquiry_response",
507 settingsSubject: "email_tpl_enquiry_response_subject",
508 settingsBody: "email_tpl_enquiry_response_body",
509 mergeTags:
510 "{{site_name}}, {{customer_name}}, {{customer_email}}, {{trip_name}}, {{trip_url}}, {{response}}, {{response_message}}, {{original_message}}",
511 },
512 {
513 template_key: "review_request",
514 event_key: "marketing.review_request",
515 name: __("Review Request", "yatra"),
516 description: __(
517 "Queued when a booking is marked completed, then sent after the delay in Review settings (if reviews are enabled).",
518 "yatra",
519 ),
520 category: "marketing",
521 recipient_type: "customer",
522 to_email: "{customer_email}",
523 isCoreFree: true,
524 settingsFlag: "email_template_review_request",
525 settingsSubject: "email_tpl_review_request_subject",
526 settingsBody: "email_tpl_review_request_body",
527 mergeTags:
528 "{{site_name}}, {{customer_name}}, {{trip_name}}, {{review_url}}, {{booking_reference}}, " +
529 BOOKING_RICH_MERGE_TAGS,
530 },
531 {
532 template_key: "abandoned_booking_recovery_first",
533 event_key: "booking.abandoned_recovery",
534 name: __("Abandoned booking recovery (First)", "yatra"),
535 description: sprintf(
536 /* translators: %s: brand name (e.g. "Yatra Pro" or operator's white-labeled brand) */
537 __(
538 "First reminder sent by %s abandoned checkout recovery (module copy in {{recovery_intro_html}}).",
539 "yatra",
540 ),
541 BRAND_PRO_NAME,
542 ),
543 category: "booking",
544 recipient_type: "customer",
545 to_email: "{customer_email}",
546 isCoreFree: true,
547 requiresModule: "abandoned_booking_recovery",
548 settingsFlag: "email_template_abandoned_booking_recovery_first",
549 settingsSubject: "email_tpl_abandoned_booking_recovery_first_subject",
550 settingsBody: "email_tpl_abandoned_booking_recovery_first_body",
551 mergeTags:
552 "{{site_name}}, {{customer_name}}, {{trip_name}}, {{recovery_link}}, {{booking_reference}}, {{recovery_reminder_label}}, {{recovery_intro_html}}, " +
553 BOOKING_RICH_MERGE_TAGS,
554 },
555 {
556 template_key: "abandoned_booking_recovery_second",
557 event_key: "booking.abandoned_recovery",
558 name: __("Abandoned booking recovery (Second)", "yatra"),
559 description: sprintf(
560 /* translators: %s: brand name */
561 __(
562 "Second reminder sent by %s abandoned checkout recovery (module copy in {{recovery_intro_html}}).",
563 "yatra",
564 ),
565 BRAND_PRO_NAME,
566 ),
567 category: "booking",
568 recipient_type: "customer",
569 to_email: "{customer_email}",
570 isCoreFree: true,
571 requiresModule: "abandoned_booking_recovery",
572 settingsFlag: "email_template_abandoned_booking_recovery_second",
573 settingsSubject: "email_tpl_abandoned_booking_recovery_second_subject",
574 settingsBody: "email_tpl_abandoned_booking_recovery_second_body",
575 mergeTags:
576 "{{site_name}}, {{customer_name}}, {{trip_name}}, {{recovery_link}}, {{booking_reference}}, {{recovery_reminder_label}}, {{recovery_intro_html}}, " +
577 BOOKING_RICH_MERGE_TAGS,
578 },
579 {
580 template_key: "abandoned_booking_recovery_final",
581 event_key: "booking.abandoned_recovery",
582 name: __("Abandoned booking recovery (Final)", "yatra"),
583 description: sprintf(
584 /* translators: %s: brand name */
585 __(
586 "Final reminder sent by %s abandoned checkout recovery (module copy in {{recovery_intro_html}}).",
587 "yatra",
588 ),
589 BRAND_PRO_NAME,
590 ),
591 category: "booking",
592 recipient_type: "customer",
593 to_email: "{customer_email}",
594 isCoreFree: true,
595 requiresModule: "abandoned_booking_recovery",
596 settingsFlag: "email_template_abandoned_booking_recovery_final",
597 settingsSubject: "email_tpl_abandoned_booking_recovery_final_subject",
598 settingsBody: "email_tpl_abandoned_booking_recovery_final_body",
599 mergeTags:
600 "{{site_name}}, {{customer_name}}, {{trip_name}}, {{recovery_link}}, {{booking_reference}}, {{recovery_reminder_label}}, {{recovery_intro_html}}, " +
601 BOOKING_RICH_MERGE_TAGS,
602 },
603 ];
604
605 export function getCatalogEntryByTemplateKey(
606 key: string,
607 ): EmailCatalogEntry | undefined {
608 return EMAIL_TEMPLATES_CATALOG.find((e) => e.template_key === key);
609 }
610
611 export function getCoreTemplateDefinition(
612 slug: string,
613 ): EmailCatalogEntry | undefined {
614 const e = getCatalogEntryByTemplateKey(slug);
615 return e?.isCoreFree ? e : undefined;
616 }
617
618 /** UI row shape for the shared templates table (API or settings-backed). */
619 export type UnifiedEmailTemplate = {
620 id: string | number;
621 template_key: string;
622 event_key: string;
623 name: string;
624 description: string;
625 subject: string;
626 body: string;
627 category: string;
628 recipient_type: "customer" | "admin";
629 to_email?: string;
630 from_email?: string;
631 from_name?: string;
632 reply_to?: string;
633 is_active: boolean;
634 is_system: boolean;
635 is_locked: boolean;
636 variables: string[];
637 created_at?: string;
638 updated_at?: string;
639 };
640
641 export type BuildLocalTemplateRowsOptions = {
642 isProPluginActive: boolean;
643 isModuleActive: (slug: string) => boolean;
644 };
645
646 export function buildLocalTemplateRows(
647 values: EmailSettingsValues,
648 options?: BuildLocalTemplateRowsOptions,
649 ): UnifiedEmailTemplate[] {
650 const pro = options?.isProPluginActive ?? false;
651 const moduleOk = (slug: string) =>
652 options?.isModuleActive ? options.isModuleActive(slug) : false;
653
654 return EMAIL_TEMPLATES_CATALOG.map((entry) => {
655 const moduleGateOk =
656 !entry.requiresModule || (pro && moduleOk(entry.requiresModule));
657
658 const proCatalogLocked = !entry.isCoreFree;
659 const moduleContentLocked = Boolean(entry.requiresModule) && !moduleGateOk;
660
661 const is_locked = proCatalogLocked || moduleContentLocked;
662
663 const hasSettingsKeys = Boolean(
664 entry.settingsFlag && entry.settingsSubject && entry.settingsBody,
665 );
666
667 const subject = entry.settingsSubject
668 ? String(values[entry.settingsSubject] ?? "")
669 : "";
670 const body = entry.settingsBody
671 ? String(values[entry.settingsBody] ?? "")
672 : "";
673 const isActive = entry.settingsFlag
674 ? Boolean(values[entry.settingsFlag])
675 : false;
676
677 const id =
678 entry.isCoreFree || hasSettingsKeys
679 ? `core:${entry.template_key}`
680 : `locked:${entry.template_key}`;
681
682 return {
683 id,
684 template_key: entry.template_key,
685 event_key: entry.event_key,
686 name: entry.name,
687 description: entry.description,
688 subject,
689 body,
690 category: entry.category,
691 recipient_type: entry.recipient_type,
692 to_email: entry.to_email,
693 is_active: hasSettingsKeys ? isActive : false,
694 is_system: true,
695 is_locked,
696 variables: [],
697 };
698 });
699 }
700