From 8b2501d908b17a4f5402571da778e0cb793cc934 Mon Sep 17 00:00:00 2001 From: c0mrade Date: Wed, 10 Jun 2026 23:37:31 +0300 Subject: [PATCH] feat(admin): show common placeholders group in email template editor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Companion to the bot-side change: the variables hint now renders two groups — type-specific vars and common ones ({service_name}, {cabinet_url}, {support_username}, {username}, {email}, {date}) that work in every template. The block is visible even for types with no vars of their own (previously it was hidden entirely, looking like placeholders didn't exist). Common chips insert at cursor the same way. --- src/api/adminEmailTemplates.ts | 4 +++ src/locales/en.json | 3 +- src/locales/fa.json | 3 +- src/locales/ru.json | 3 +- src/locales/zh.json | 3 +- src/pages/AdminEmailTemplates.tsx | 59 +++++++++++++++++++++---------- 6 files changed, 53 insertions(+), 22 deletions(-) diff --git a/src/api/adminEmailTemplates.ts b/src/api/adminEmailTemplates.ts index d1cd1af..68e1332 100644 --- a/src/api/adminEmailTemplates.ts +++ b/src/api/adminEmailTemplates.ts @@ -15,6 +15,8 @@ export interface EmailTemplateType { export interface EmailTemplateListResponse { items: EmailTemplateType[]; available_languages: string[]; + /** Placeholders available in every template regardless of type */ + common_context_vars: string[]; } export interface EmailTemplateLanguageData { @@ -30,6 +32,8 @@ export interface EmailTemplateDetail { label: Record; description: Record; context_vars: string[]; + /** Placeholders available in every template regardless of type */ + common_context_vars?: string[]; languages: Record; } diff --git a/src/locales/en.json b/src/locales/en.json index 8c940cb..63eeeb0 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -1547,7 +1547,8 @@ "insertDefault": "Insert default template", "insertDefaultConfirm": "Replace the current content with the default template?", "testRecipientPlaceholder": "Recipient email (defaults to yours)", - "testHint": "Sends the current editor content with sample values in place of variables." + "testHint": "Sends the current editor content with sample values in place of variables.", + "variablesCommon": "Common variables (work in all templates)" }, "payments": { "title": "Payments", diff --git a/src/locales/fa.json b/src/locales/fa.json index bed1ae2..c9d4d59 100644 --- a/src/locales/fa.json +++ b/src/locales/fa.json @@ -1420,7 +1420,8 @@ "insertDefault": "درج قالب پیش‌فرض", "insertDefaultConfirm": "محتوای فعلی با قالب پیش‌فرض جایگزین شود؟", "testRecipientPlaceholder": "ایمیل گیرنده (پیش‌فرض: ایمیل شما)", - "testHint": "محتوای فعلی ویرایشگر با مقادیر نمونه به جای متغیرها ارسال می‌شود." + "testHint": "محتوای فعلی ویرایشگر با مقادیر نمونه به جای متغیرها ارسال می‌شود.", + "variablesCommon": "متغیرهای عمومی (در همه قالب‌ها کار می‌کنند)" }, "wheel": { "title": "تنظیمات چرخ شانس", diff --git a/src/locales/ru.json b/src/locales/ru.json index 73ce6b9..caec2c7 100644 --- a/src/locales/ru.json +++ b/src/locales/ru.json @@ -1569,7 +1569,8 @@ "insertDefault": "Вставить шаблон по умолчанию", "insertDefaultConfirm": "Заменить текущее содержимое шаблоном по умолчанию?", "testRecipientPlaceholder": "Email получателя (по умолчанию — ваш)", - "testHint": "Отправит текущее содержимое редактора с примерами значений вместо переменных." + "testHint": "Отправит текущее содержимое редактора с примерами значений вместо переменных.", + "variablesCommon": "Общие переменные (работают во всех шаблонах)" }, "payments": { "title": "Платежи", diff --git a/src/locales/zh.json b/src/locales/zh.json index 7164943..f78ac6c 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -1461,7 +1461,8 @@ "insertDefault": "插入默认模板", "insertDefaultConfirm": "用默认模板替换当前内容?", "testRecipientPlaceholder": "收件人邮箱(默认为您的邮箱)", - "testHint": "发送当前编辑器内容,变量将替换为示例值。" + "testHint": "发送当前编辑器内容,变量将替换为示例值。", + "variablesCommon": "通用变量(适用于所有模板)" }, "payments": { "title": "支付", diff --git a/src/pages/AdminEmailTemplates.tsx b/src/pages/AdminEmailTemplates.tsx index 5cabdd6..90b3ef8 100644 --- a/src/pages/AdminEmailTemplates.tsx +++ b/src/pages/AdminEmailTemplates.tsx @@ -362,24 +362,47 @@ function TemplateEditor({ /> - {/* Context variables hint */} - {detail.context_vars.length > 0 && ( -
-

- {t('admin.emailTemplates.variables')} -

-
- {detail.context_vars.map((v) => ( - insertVariable(v)} - > - {`{${v}}`} - - ))} -
+ {/* Context variables hint: type-specific + common (available in all templates) */} + {(detail.context_vars.length > 0 || (detail.common_context_vars?.length ?? 0) > 0) && ( +
+ {detail.context_vars.length > 0 && ( +
+

+ {t('admin.emailTemplates.variables')} +

+
+ {detail.context_vars.map((v) => ( + insertVariable(v)} + > + {`{${v}}`} + + ))} +
+
+ )} + {(detail.common_context_vars?.length ?? 0) > 0 && ( +
+

+ {t('admin.emailTemplates.variablesCommon')} +

+
+ {detail.common_context_vars!.map((v) => ( + insertVariable(v)} + > + {`{${v}}`} + + ))} +
+
+ )}
)}