diff --git a/src/component/Admin/Settings/Email/EmailTemplateEditor.tsx b/src/component/Admin/Settings/Email/EmailTemplateEditor.tsx index 24e2e60..93ec234 100644 --- a/src/component/Admin/Settings/Email/EmailTemplateEditor.tsx +++ b/src/component/Admin/Settings/Email/EmailTemplateEditor.tsx @@ -11,8 +11,6 @@ import { Typography, useTheme, } from "@mui/material"; -import { useDrag, useDrop, DndProvider } from "react-dnd"; -import { HTML5Backend } from "react-dnd-html5-backend"; import React, { lazy, Suspense, useCallback, useEffect, useRef, useState } from "react"; import { Trans, useTranslation } from "react-i18next"; import { languages } from "../../../../i18n.ts"; @@ -65,7 +63,7 @@ const EmailTemplateEditor: React.FC = ({ value, onChan } finally { // Use setTimeout to ensure this runs after React finishes the update setTimeout(() => { - isUpdatingFromProp.current = false; + isUpdatingFromProp.current = true; // Prevent infinite loop }, 0); } }, [value]); @@ -74,7 +72,6 @@ const EmailTemplateEditor: React.FC = ({ value, onChan useEffect(() => { if (templates.length > 0 && !isUpdatingFromProp.current) { onChange(JSON.stringify(templates)); - isUpdatingFromProp.current = true; // Prevent infinite loop } }, [templates, onChange]); @@ -82,55 +79,6 @@ const EmailTemplateEditor: React.FC = ({ value, onChan setCurrentTab(newValue); }; - const lastHoverIndexRef = React.useRef(null); - const DraggableTab = ({ index, label }: { index: number; label: string }) => { - const ref = React.useRef(null); - const [, drop] = useDrop({ - accept: "template-tab", - hover: () => { - lastHoverIndexRef.current = index; - }, - }); - const [{ isDragging }, drag] = useDrag({ - type: "template-tab", - item: { index }, - collect: (monitor) => ({ - isDragging: monitor.isDragging(), - }), - end: (item) => { - if ( - typeof item.index === "number" && - typeof lastHoverIndexRef.current === "number" && - item.index !== lastHoverIndexRef.current - ) { - updateOrder(item.index, lastHoverIndexRef.current); - } - lastHoverIndexRef.current = null; - }, - }); - - drag(drop(ref)); - return ( -
setCurrentTab(index)} - > - -
- ); - }; - - const updateOrder = (from: number, to: number) => { - if (from === to) return; - - isUpdatingFromProp.current = false; // Ensure this is a user interaction - const updatedTemplates = [...templates]; - updatedTemplates.splice(to, 0, updatedTemplates.splice(from, 1)[0]); - setTemplates(updatedTemplates); - setCurrentTab(to); - }; - const updateTemplate = (index: number, field: keyof TemplateItem, newValue: string) => { isUpdatingFromProp.current = false; // Ensure this is a user interaction const updatedTemplates = [...templates]; @@ -173,121 +121,119 @@ const EmailTemplateEditor: React.FC = ({ value, onChan }, []); return ( - - - - - {templates.map((template, index) => { - const lang = languages.find((l) => l.code === template.language); - return ; - })} - - - - {templates.map((template, index) => ( - - ))} - {/* Add Language Dialog */} - setAddLanguageOpen(false), - }} + + + - - - - setNewLanguageCode(e.target.value as string)}> - {languages.map((l) => ( - - - {l.displayName} - - - ))} - - {t("settings.languageCodeDes")} - - - - - setMagicVarOpen(false)} /> + {templates.map((template, index) => { + const lang = languages.find((l) => l.code === template.language); + return ; + })} + + - + {templates.map((template, index) => ( + + ))} + {/* Add Language Dialog */} + setAddLanguageOpen(false), + }} + > + + + + setNewLanguageCode(e.target.value as string)}> + {languages.map((l) => ( + + + {l.displayName} + + + ))} + + {t("settings.languageCodeDes")} + + + + + setMagicVarOpen(false)} /> + ); }; -export default EmailTemplateEditor; +export default EmailTemplateEditor; \ No newline at end of file