From 3e3ad7d60dff34630ad91e6a9f3215e13b575c83 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Mon, 2 Feb 2026 23:35:42 +0000 Subject: [PATCH] Fixed a supsension error --- .../components/EmailTemplateEditor.tsx | 14 ++-- .../domains/components/MailTemplatesTab.tsx | 82 ++++++++++++------- 2 files changed, 61 insertions(+), 35 deletions(-) diff --git a/src/modules/manager/domains/components/EmailTemplateEditor.tsx b/src/modules/manager/domains/components/EmailTemplateEditor.tsx index be8cc5f..4712626 100644 --- a/src/modules/manager/domains/components/EmailTemplateEditor.tsx +++ b/src/modules/manager/domains/components/EmailTemplateEditor.tsx @@ -1,6 +1,6 @@ import Joi from "joi"; import React, { useEffect } from "react"; -import { Navigate } from "react-router-dom"; +import { Navigate, useParams } from "react-router-dom"; import { toast } from "react-toastify"; import { useTranslation } from "react-i18next"; import { Namespaces } from "../../../../i18n/i18n"; @@ -25,6 +25,8 @@ const EmailTemplateEditor: React.FC = ({ currentMailType, }) => { const { t } = useTranslation(); + const paramsData = useParams<{ domainId: string }>(); + const finalDomainId = domainId || paramsData.domainId; const labelName = t("Subject"); const labelDefinition = t("Definition"); @@ -53,7 +55,7 @@ const EmailTemplateEditor: React.FC = ({ useEffect(() => { const loadTemplate = async () => { try { - if (!domainId) return; + if (!finalDomainId || !currentMailType) return; // Reset form state while loading form.setState({ @@ -66,7 +68,7 @@ const EmailTemplateEditor: React.FC = ({ }, }); - const domainIdValue = BigInt(domainId); + const domainIdValue = BigInt(finalDomainId); var mailTemplate = await mailTemplatesService.getTemplate( MakeGeneralIdRef(domainIdValue), currentMailType, @@ -89,13 +91,13 @@ const EmailTemplateEditor: React.FC = ({ }; void loadTemplate(); - }, [domainId, currentMailType]); // eslint-disable-line react-hooks/exhaustive-deps + }, [finalDomainId, currentMailType]); // eslint-disable-line react-hooks/exhaustive-deps const doSubmit = async (buttonName: string) => { try { const { subject, definition } = form.state.data; - if (!domainId) return; - const domainGeneralIdRef = MakeGeneralIdRef(BigInt(domainId)); + if (!finalDomainId) return; + const domainGeneralIdRef = MakeGeneralIdRef(BigInt(finalDomainId)); const subjectStr = typeof subject === "string" ? subject : ""; const definitionStr = typeof definition === "string" ? definition : ""; const response = await mailTemplatesService.postTemplate( diff --git a/src/modules/manager/domains/components/MailTemplatesTab.tsx b/src/modules/manager/domains/components/MailTemplatesTab.tsx index eef0d41..c9836af 100644 --- a/src/modules/manager/domains/components/MailTemplatesTab.tsx +++ b/src/modules/manager/domains/components/MailTemplatesTab.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState, useCallback } from "react"; +import React, { useEffect, useState, useCallback, Suspense } from "react"; import { useParams } from "react-router-dom"; import mailTemplatesService from "../serrvices/mailTemplatesService"; import HOCEmailTemplateEditor from "./EmailTemplateEditor"; @@ -11,22 +11,62 @@ interface MailType { description: string; } -const MailTemplatesTab: React.FC = () => { +const MailTemplatesTabContent: React.FC<{ + types: MailType[]; + currentMailType: string; + domainId: string | undefined; + onClick: (e: React.MouseEvent) => void; +}> = ({ types, currentMailType, domainId, onClick }) => { const { t: tMail } = useTranslation(Namespaces.MailTypes); + + return ( +
+
+
    + {types.map((x) => { + return ( +
  • + {tMail(x.mailType)} +
  • + ); + })} +
+
+
+ {domainId && currentMailType ? ( + + ) : null} +
+
+ ); +}; + +const MailTemplatesTab: React.FC = () => { const [loaded, setLoaded] = useState(false); const [currentMailType, setCurrentMailType] = useState(""); const [types, setTypes] = useState([]); useEffect(() => { const loadTypes = async () => { - const response = await mailTemplatesService.getTypes(0, 10, "", true); - if (response) { - const nextTypes = response.data as MailType[]; + try { + const response = await mailTemplatesService.getTypes(0, 10, "", true); + const nextTypes = (response?.data as MailType[]) ?? []; setTypes(nextTypes); if (nextTypes.length > 0) { setCurrentMailType(nextTypes[0].mailType); } + } catch (ex) { + console.error(ex); + } finally { setLoaded(true); } }; @@ -54,30 +94,14 @@ const MailTemplatesTab: React.FC = () => { return ( -
-
-
    - {types.map((x) => { - return ( -
  • - {tMail(x.mailType)} -
  • - ); - })} -
-
-
- -
-
+ Loading...}> + +
); };