fix(email-composer): hide template buttons when templates are disabled

This commit is contained in:
Marc Sportiello
2026-07-19 10:08:09 +02:00
committed by Linus Rath
parent f749ee1f2a
commit 0b62afb0f8
+26 -19
View File
@@ -55,6 +55,7 @@ import { RichTextEditor } from "@/components/email/rich-text-editor";
import type { Editor } from "@tiptap/react"; import type { Editor } from "@tiptap/react";
import { htmlToPlainText as htmlToPlainTextShared } from "@/lib/html-to-text"; import { htmlToPlainText as htmlToPlainTextShared } from "@/lib/html-to-text";
import { fileStorage } from "@/lib/plugin-storage"; import { fileStorage } from "@/lib/plugin-storage";
import { usePolicyStore } from "@/stores/policy-store";
/** /**
* Derives the text/plain alternative from the composer's HTML body, preserving * Derives the text/plain alternative from the composer's HTML body, preserving
@@ -290,6 +291,9 @@ export function EmailComposer({
: []; : [];
const primaryIdentity = activeIdentities[0] ?? null; const primaryIdentity = activeIdentities[0] ?? null;
const { isFeatureEnabled } = usePolicyStore();
const templatesEnabled = isFeatureEnabled('templatesEnabled');
// The signature identity used when embedding the signature into the initial // The signature identity used when embedding the signature into the initial
// body for "above quote" mode. Mirrors the signatureIdentity derivation // body for "above quote" mode. Mirrors the signatureIdentity derivation
// below, but uses initialData (or primary) since selectedIdentityId state // below, but uses initialData (or primary) since selectedIdentityId state
@@ -1132,6 +1136,7 @@ export function EmailComposer({
const tag = target?.tagName?.toLowerCase(); const tag = target?.tagName?.toLowerCase();
if (tag === 'input' || tag === 'textarea' || tag === 'select') return; if (tag === 'input' || tag === 'textarea' || tag === 'select') return;
if (target?.getAttribute('contenteditable') === 'true') return; if (target?.getAttribute('contenteditable') === 'true') return;
if (!templatesEnabled) return;
if (e.key === 't' && !e.ctrlKey && !e.metaKey && !e.altKey) { if (e.key === 't' && !e.ctrlKey && !e.metaKey && !e.altKey) {
e.preventDefault(); e.preventDefault();
setShowTemplatePicker(true); setShowTemplatePicker(true);
@@ -1139,7 +1144,7 @@ export function EmailComposer({
}; };
window.addEventListener('keydown', handleTemplateKey); window.addEventListener('keydown', handleTemplateKey);
return () => window.removeEventListener('keydown', handleTemplateKey); return () => window.removeEventListener('keydown', handleTemplateKey);
}, []); }, [templatesEnabled]);
const addFiles = useCallback(async (files: File[]) => { const addFiles = useCallback(async (files: File[]) => {
if (!client || files.length === 0) return; if (!client || files.length === 0) return;
@@ -2562,24 +2567,26 @@ export function EmailComposer({
> >
<Paperclip className="w-4 h-4" /> <Paperclip className="w-4 h-4" />
</Button> </Button>
<Button {templatesEnabled && <>
variant="ghost" <Button
size="icon" variant="ghost"
onClick={() => setShowTemplatePicker(true)} size="icon"
title={t('use_template')} onClick={() => setShowTemplatePicker(true)}
className="h-9 w-9" title={t('use_template')}
> className="h-9 w-9"
<FileText className="w-4 h-4" /> >
</Button> <FileText className="w-4 h-4" />
<Button </Button>
variant="ghost" <Button
size="icon" variant="ghost"
onClick={() => setShowSaveAsTemplate(true)} size="icon"
title={t('save_as_template')} onClick={() => setShowSaveAsTemplate(true)}
className="h-9 w-9" title={t('save_as_template')}
> className="h-9 w-9"
<BookmarkPlus className="w-4 h-4" /> >
</Button> <BookmarkPlus className="w-4 h-4" />
</Button>
</>}
{/* Sign/encrypt controls are contributed by crypto plugins via the {/* Sign/encrypt controls are contributed by crypto plugins via the
composer-toolbar slot (rendered below). */} composer-toolbar slot (rendered below). */}