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

361 lines 11.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, the four isCoreFree rows are editable via site settings;
4 * all other rows appear locked until the module is enabled.
5 */
6
7 import { __ } from "./i18n";
8 import type { EmailSettingsValues } from "../components/settings/email-settings-types";
9
10 export type EmailCatalogEntry = {
11 template_key: string;
12 event_key: string;
13 name: string;
14 description: string;
15 category: string;
16 recipient_type: "customer" | "admin";
17 to_email: string;
18 /** When true, subject/body/active map to EmailSettingsValues keys. */
19 isCoreFree: boolean;
20 settingsFlag?: keyof EmailSettingsValues;
21 settingsSubject?: keyof EmailSettingsValues;
22 settingsBody?: keyof EmailSettingsValues;
23 /** Shown in core editor sidebar for merge tags */
24 mergeTags?: string;
25 };
26
27 export const CORE_FREE_TEMPLATE_KEYS = [
28 "booking_confirmation",
29 "payment_received",
30 "booking_cancelled",
31 "trip_reminder",
32 "admin_new_booking",
33 "admin_payment_received",
34 "admin_booking_cancelled",
35 ] as const;
36
37 export type CoreFreeTemplateKey = (typeof CORE_FREE_TEMPLATE_KEYS)[number];
38
39 export function isCoreTemplateSlug(
40 slug: string | null | undefined,
41 ): slug is CoreFreeTemplateKey {
42 return (
43 !!slug && (CORE_FREE_TEMPLATE_KEYS as readonly string[]).includes(slug)
44 );
45 }
46
47 export const EMAIL_TEMPLATES_CATALOG: EmailCatalogEntry[] = [
48 {
49 template_key: "booking_confirmation",
50 event_key: "booking.created",
51 name: __("Booking Confirmation", "yatra"),
52 description: __(
53 "Customer email for checkout, admin bookings, and confirmed status.",
54 "yatra",
55 ),
56 category: "booking",
57 recipient_type: "customer",
58 to_email: "{customer_email}",
59 isCoreFree: true,
60 settingsFlag: "email_template_booking",
61 settingsSubject: "email_tpl_booking_subject",
62 settingsBody: "email_tpl_booking_body",
63 mergeTags:
64 "{{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}}",
65 },
66 {
67 template_key: "payment_received",
68 event_key: "payment.received",
69 name: __("Payment Received", "yatra"),
70 description: __("Sent when a payment is recorded for a booking.", "yatra"),
71 category: "payment",
72 recipient_type: "customer",
73 to_email: "{customer_email}",
74 isCoreFree: true,
75 settingsFlag: "email_template_confirmation",
76 settingsSubject: "email_tpl_payment_subject",
77 settingsBody: "email_tpl_payment_body",
78 mergeTags:
79 "{{site_name}}, {{customer_name}}, {{customer_first_name}}, {{booking_reference}}, {{trip_name}}, {{travel_date}}, {{payment_amount_formatted}}, {{payment_method}}, {{transaction_id}}, {{total_amount_formatted}}, {{currency}}",
80 },
81 {
82 template_key: "booking_cancelled",
83 event_key: "booking.cancelled",
84 name: __("Booking Cancellation", "yatra"),
85 description: __("Sent when a booking is marked cancelled.", "yatra"),
86 category: "booking",
87 recipient_type: "customer",
88 to_email: "{customer_email}",
89 isCoreFree: true,
90 settingsFlag: "email_template_cancellation",
91 settingsSubject: "email_tpl_cancellation_subject",
92 settingsBody: "email_tpl_cancellation_body",
93 mergeTags:
94 "{{site_name}}, {{customer_name}}, {{customer_first_name}}, {{booking_reference}}, {{trip_name}}, {{travel_date}}, {{travelers_count}}",
95 },
96 {
97 template_key: "trip_reminder",
98 event_key: "reminder.trip",
99 name: __("Trip Reminder", "yatra"),
100 description: __(
101 "Scheduled reminder before departure (see Booking settings).",
102 "yatra",
103 ),
104 category: "reminder",
105 recipient_type: "customer",
106 to_email: "{customer_email}",
107 isCoreFree: true,
108 settingsFlag: "email_template_reminder",
109 settingsSubject: "email_tpl_reminder_subject",
110 settingsBody: "email_tpl_reminder_body",
111 mergeTags:
112 "{{site_name}}, {{customer_name}}, {{booking_reference}}, {{trip_name}}, {{travel_date}}, {{travelers_count}}, {{reminder_days}}, {{days_until_trip}}, {{amount_due_formatted}}, {{reminder_extra_html}}",
113 },
114 {
115 template_key: "admin_new_booking",
116 event_key: "booking.created",
117 name: __("Admin: New Booking", "yatra"),
118 description: __(
119 "Sent to your admin email when a booking is created. Turn off here to stop this email.",
120 "yatra",
121 ),
122 category: "booking",
123 recipient_type: "admin",
124 to_email: "{{admin_email}}",
125 isCoreFree: true,
126 settingsFlag: "email_template_admin_new_booking",
127 settingsSubject: "email_tpl_admin_booking_subject",
128 settingsBody: "email_tpl_admin_booking_body",
129 mergeTags:
130 "{{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}}",
131 },
132 {
133 template_key: "admin_payment_received",
134 event_key: "payment.received",
135 name: __("Admin: Payment received", "yatra"),
136 description: __(
137 "Sent to your admin email when a payment is recorded. Customer receipt uses the Payment Received template.",
138 "yatra",
139 ),
140 category: "payment",
141 recipient_type: "admin",
142 to_email: "{{admin_email}}",
143 isCoreFree: true,
144 settingsFlag: "email_template_admin_payment",
145 settingsSubject: "email_tpl_admin_payment_subject",
146 settingsBody: "email_tpl_admin_payment_body",
147 mergeTags:
148 "{{site_name}}, {{admin_url}}, {{booking_reference}}, {{booking_id}}, {{customer_name}}, {{payment_amount_formatted}}, {{payment_method}}, {{transaction_id}}",
149 },
150 {
151 template_key: "admin_booking_cancelled",
152 event_key: "booking.cancelled",
153 name: __("Admin: Booking cancelled", "yatra"),
154 description: __(
155 "Sent to your admin email when a booking is cancelled. Customer notice uses the Booking Cancellation template.",
156 "yatra",
157 ),
158 category: "booking",
159 recipient_type: "admin",
160 to_email: "{{admin_email}}",
161 isCoreFree: true,
162 settingsFlag: "email_template_admin_cancellation",
163 settingsSubject: "email_tpl_admin_cancellation_subject",
164 settingsBody: "email_tpl_admin_cancellation_body",
165 mergeTags:
166 "{{site_name}}, {{admin_url}}, {{booking_reference}}, {{booking_id}}, {{customer_name}}, {{trip_name}}, {{travel_date}}",
167 },
168 {
169 template_key: "new_booking",
170 event_key: "new_booking",
171 name: __("New Booking Confirmation", "yatra"),
172 description: __(
173 "Pro automation template. Enable Email Automation to edit and send.",
174 "yatra",
175 ),
176 category: "booking",
177 recipient_type: "customer",
178 to_email: "{customer_email}",
179 isCoreFree: false,
180 },
181 {
182 template_key: "booking_payment",
183 event_key: "booking_payment",
184 name: __("Booking payment notice", "yatra"),
185 description: __(
186 "Pro automation template. Enable Email Automation to edit and send.",
187 "yatra",
188 ),
189 category: "payment",
190 recipient_type: "customer",
191 to_email: "{customer_email}",
192 isCoreFree: false,
193 },
194 {
195 template_key: "booking_confirmed",
196 event_key: "booking.confirmed",
197 name: __("Booking Confirmed", "yatra"),
198 description: __(
199 "Pro automation template. Enable Email Automation to edit and send.",
200 "yatra",
201 ),
202 category: "booking",
203 recipient_type: "customer",
204 to_email: "{customer_email}",
205 isCoreFree: false,
206 },
207 {
208 template_key: "booking_completed",
209 event_key: "booking.completed",
210 name: __("Trip Completed", "yatra"),
211 description: __(
212 "Pro automation template. Enable Email Automation to edit and send.",
213 "yatra",
214 ),
215 category: "booking",
216 recipient_type: "customer",
217 to_email: "{customer_email}",
218 isCoreFree: false,
219 },
220 {
221 template_key: "payment_reminder",
222 event_key: "payment.reminder",
223 name: __("Payment Reminder", "yatra"),
224 description: __(
225 "Pro automation template. Enable Email Automation to edit and send.",
226 "yatra",
227 ),
228 category: "payment",
229 recipient_type: "customer",
230 to_email: "{customer_email}",
231 isCoreFree: false,
232 },
233 {
234 template_key: "enquiry_received",
235 event_key: "enquiry.created",
236 name: __("Enquiry Received", "yatra"),
237 description: __(
238 "Pro automation template. Enable Email Automation to edit and send.",
239 "yatra",
240 ),
241 category: "enquiry",
242 recipient_type: "customer",
243 to_email: "{customer_email}",
244 isCoreFree: false,
245 },
246 {
247 template_key: "enquiry_admin",
248 event_key: "enquiry.created",
249 name: __("Admin: New Enquiry", "yatra"),
250 description: __(
251 "Pro automation template. Enable Email Automation to edit and send.",
252 "yatra",
253 ),
254 category: "enquiry",
255 recipient_type: "admin",
256 to_email: "",
257 isCoreFree: false,
258 },
259 {
260 template_key: "enquiry_response",
261 event_key: "enquiry.responded",
262 name: __("Enquiry Response", "yatra"),
263 description: __(
264 "Pro automation template. Enable Email Automation to edit and send.",
265 "yatra",
266 ),
267 category: "enquiry",
268 recipient_type: "customer",
269 to_email: "{customer_email}",
270 isCoreFree: false,
271 },
272 {
273 template_key: "review_request",
274 event_key: "marketing.review_request",
275 name: __("Review Request", "yatra"),
276 description: __(
277 "Pro automation template. Enable Email Automation to edit and send.",
278 "yatra",
279 ),
280 category: "marketing",
281 recipient_type: "customer",
282 to_email: "{customer_email}",
283 isCoreFree: false,
284 },
285 ];
286
287 export function getCatalogEntryByTemplateKey(
288 key: string,
289 ): EmailCatalogEntry | undefined {
290 return EMAIL_TEMPLATES_CATALOG.find((e) => e.template_key === key);
291 }
292
293 export function getCoreTemplateDefinition(
294 slug: string,
295 ): EmailCatalogEntry | undefined {
296 const e = getCatalogEntryByTemplateKey(slug);
297 return e?.isCoreFree ? e : undefined;
298 }
299
300 /** UI row shape for the shared templates table (API or settings-backed). */
301 export type UnifiedEmailTemplate = {
302 id: string | number;
303 template_key: string;
304 event_key: string;
305 name: string;
306 description: string;
307 subject: string;
308 body: string;
309 category: string;
310 recipient_type: "customer" | "admin";
311 to_email?: string;
312 from_email?: string;
313 from_name?: string;
314 reply_to?: string;
315 is_active: boolean;
316 is_system: boolean;
317 is_locked: boolean;
318 variables: string[];
319 created_at?: string;
320 updated_at?: string;
321 };
322
323 export function buildLocalTemplateRows(
324 values: EmailSettingsValues,
325 ): UnifiedEmailTemplate[] {
326 return EMAIL_TEMPLATES_CATALOG.map((entry) => {
327 const locked = !entry.isCoreFree;
328 const subject =
329 entry.settingsSubject && !locked
330 ? String(values[entry.settingsSubject] ?? "")
331 : "";
332 const body =
333 entry.settingsBody && !locked
334 ? String(values[entry.settingsBody] ?? "")
335 : "";
336 const isActive =
337 entry.settingsFlag && !locked
338 ? Boolean(values[entry.settingsFlag])
339 : false;
340
341 return {
342 id: locked
343 ? `locked:${entry.template_key}`
344 : `core:${entry.template_key}`,
345 template_key: entry.template_key,
346 event_key: entry.event_key,
347 name: entry.name,
348 description: entry.description,
349 subject,
350 body,
351 category: entry.category,
352 recipient_type: entry.recipient_type,
353 to_email: entry.to_email,
354 is_active: locked ? false : isActive,
355 is_system: true,
356 is_locked: locked,
357 variables: [],
358 };
359 });
360 }
361