feat(email): auto switch for existing language templates, and use friendly lang display name

This commit is contained in:
Darren Yu 2025-08-21 21:21:10 +08:00
parent 3b9bef5ca9
commit 3472e04a16
No known key found for this signature in database
GPG Key ID: 2D69AA5646405984

View File

@ -93,10 +93,12 @@ const EmailTemplateEditor: React.FC<EmailTemplateEditorProps> = ({ value, onChan
if (!newLanguageCode.trim()) return;
// Check if language already exists
if (templates.some((t) => t.language === newLanguageCode)) {
// Could show an error message here
const langTemplateIndex = templates.findIndex(l => l.language === newLanguageCode);
if (langTemplateIndex !== -1) {
setNewLanguageCode("");
setAddLanguageOpen(false);
setCurrentTab(langTemplateIndex);
return;
}
@ -128,9 +130,12 @@ const EmailTemplateEditor: React.FC<EmailTemplateEditorProps> = ({ value, onChan
scrollButtons="auto"
sx={{ flexGrow: 1 }}
>
{templates.map((template, index) => (
<Tab key={index} label={template.language} />
))}
{templates.map((template, index) => {
const lang = languages.find(l => l.code === template.language);
return (
<Tab key={index} label={lang ? lang.displayName : template.language} />
);
})}
</Tabs>
<Button
startIcon={<Add />}