Files
bedolaga-cabinet/src/api/adminEmailTemplates.ts
c0mrade 8b2501d908 feat(admin): show common placeholders group in email template editor
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.
2026-06-10 23:37:31 +03:00

113 lines
3.1 KiB
TypeScript

import apiClient from './client';
export interface EmailTemplateLanguageStatus {
has_custom: boolean;
}
export interface EmailTemplateType {
type: string;
label: Record<string, string>;
description: Record<string, string>;
context_vars: string[];
languages: Record<string, EmailTemplateLanguageStatus>;
}
export interface EmailTemplateListResponse {
items: EmailTemplateType[];
available_languages: string[];
/** Placeholders available in every template regardless of type */
common_context_vars: string[];
}
export interface EmailTemplateLanguageData {
subject: string;
body_html: string;
is_default: boolean;
default_subject: string;
default_body_html: string;
}
export interface EmailTemplateDetail {
notification_type: string;
label: Record<string, string>;
description: Record<string, string>;
context_vars: string[];
/** Placeholders available in every template regardless of type */
common_context_vars?: string[];
languages: Record<string, EmailTemplateLanguageData>;
}
export interface EmailTemplateUpdateRequest {
subject: string;
body_html: string;
}
export interface EmailTemplatePreviewRequest {
language: string;
subject?: string;
body_html?: string;
}
export interface EmailTemplatePreviewResponse {
subject: string;
body_html: string;
}
export interface EmailTemplateSendTestRequest {
language: string;
email?: string;
/** Current editor content — when set, the test sends it instead of the saved template */
subject?: string;
body_html?: string;
}
export const adminEmailTemplatesApi = {
getTemplateTypes: async (): Promise<EmailTemplateListResponse> => {
const response = await apiClient.get<EmailTemplateListResponse>(
'/cabinet/admin/email-templates',
);
return response.data;
},
getTemplate: async (notificationType: string): Promise<EmailTemplateDetail> => {
const response = await apiClient.get<EmailTemplateDetail>(
`/cabinet/admin/email-templates/${notificationType}`,
);
return response.data;
},
updateTemplate: async (
notificationType: string,
language: string,
data: EmailTemplateUpdateRequest,
): Promise<void> => {
await apiClient.put(`/cabinet/admin/email-templates/${notificationType}/${language}`, data);
},
deleteTemplate: async (notificationType: string, language: string): Promise<void> => {
await apiClient.delete(`/cabinet/admin/email-templates/${notificationType}/${language}`);
},
previewTemplate: async (
notificationType: string,
data: EmailTemplatePreviewRequest,
): Promise<EmailTemplatePreviewResponse> => {
const response = await apiClient.post<EmailTemplatePreviewResponse>(
`/cabinet/admin/email-templates/${notificationType}/preview`,
data,
);
return response.data;
},
sendTestEmail: async (
notificationType: string,
data: EmailTemplateSendTestRequest,
): Promise<{ sent_to: string }> => {
const response = await apiClient.post<{ status: string; sent_to: string }>(
`/cabinet/admin/email-templates/${notificationType}/test`,
data,
);
return response.data;
},
};