From 0e4567f96cceab259ee47bd7ab0480748969f286 Mon Sep 17 00:00:00 2001 From: Danny White <3104761+dnywh@users.noreply.github.com> Date: Mon, 3 Nov 2025 11:56:50 +1100 Subject: [PATCH] code editor --- .../Auth/EmailTemplates/TemplateEditor.tsx | 69 +++++++++---------- 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/apps/studio/components/interfaces/Auth/EmailTemplates/TemplateEditor.tsx b/apps/studio/components/interfaces/Auth/EmailTemplates/TemplateEditor.tsx index 72c56bec3e9..b0d0861fca5 100644 --- a/apps/studio/components/interfaces/Auth/EmailTemplates/TemplateEditor.tsx +++ b/apps/studio/components/interfaces/Auth/EmailTemplates/TemplateEditor.tsx @@ -1,5 +1,4 @@ import { PermissionAction } from '@supabase/shared-types/out/constants' -import { Code, Monitor } from 'lucide-react' import { editor } from 'monaco-editor' import { useEffect, useMemo, useRef, useState } from 'react' import { useForm } from 'react-hook-form' @@ -8,6 +7,7 @@ import { toast } from 'sonner' import { useParams } from 'common' import CodeEditor from 'components/ui/CodeEditor/CodeEditor' +import TwoOptionToggle from 'components/ui/TwoOptionToggle' import { useAuthConfigQuery } from 'data/auth/auth-config-query' import { useAuthConfigUpdateMutation } from 'data/auth/auth-config-update-mutation' import { useValidateSpamMutation, ValidateSpamResponse } from 'data/auth/validate-spam-mutation' @@ -22,10 +22,6 @@ import { FormField_Shadcn_, Input_Shadcn_, Label_Shadcn_, - Tabs_Shadcn_, - TabsContent_Shadcn_, - TabsList_Shadcn_, - TabsTrigger_Shadcn_, Tooltip, TooltipContent, TooltipTrigger, @@ -75,6 +71,7 @@ export const TemplateEditor = ({ template }: TemplateEditorProps) => { const [bodyValue, setBodyValue] = useState((authConfig && authConfig[messageSlug]) ?? '') const [hasUnsavedChanges, setHasUnsavedChanges] = useState(false) const [isSavingTemplate, setIsSavingTemplate] = useState(false) + const [activeView, setActiveView] = useState<'source' | 'preview'>('source') const spamRules = (validationResult?.rules ?? []).filter((rule) => rule.score > 0) const preventSaveFromSpamCheck = builtInSMTP && spamRules.length > 0 @@ -292,32 +289,33 @@ export const TemplateEditor = ({ template }: TemplateEditorProps) => { {messageProperty && ( <> - Body - - - - - Source - - - - Preview - - - - { - setBodyValue(e ?? '') - if (bodyValue !== e) setHasUnsavedChanges(true) - }} - options={{ wordWrap: 'on', contextmenu: false, padding: { top: 16 } }} - value={bodyValue} - editorRef={editorRef} - /> +
+ Body + setActiveView(option)} + borderOverride="border-muted" + /> +
+ {activeView === 'source' ? ( + <> +
+ { + setBodyValue(e ?? '') + if (bodyValue !== e) setHasUnsavedChanges(true) + }} + options={{ wordWrap: 'on', contextmenu: false, padding: { top: 16 } }} + value={bodyValue} + editorRef={editorRef} + /> +
{messageVariables.length > 0 && (
@@ -341,8 +339,9 @@ export const TemplateEditor = ({ template }: TemplateEditorProps) => {
)} -
- + + ) : ( + <>