PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.6
Yatra – Travel Booking & Tour Operator Software v3.0.6
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.6, at resources/js/lib/email-templates-catalog.ts

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