eleven-solutions-common-website-unique-web 22.0.17 → 22.0.19
Sign up to get free protection for your applications and to get access to all the features.
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
8
8
|
});
|
9
9
|
};
|
10
10
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
11
|
-
import { useState, useEffect,
|
11
|
+
import { useState, useEffect, useMemo } from "react";
|
12
12
|
import { addTemplateApi, fetchTemplateByIdApi, updateTemplateApi, } from "../api/template";
|
13
13
|
import toast from "react-hot-toast";
|
14
14
|
import Editor from "./Editor";
|
@@ -17,7 +17,9 @@ const TemplateForm = ({ url }) => {
|
|
17
17
|
const [content, setContent] = useState("");
|
18
18
|
const placeholder = "";
|
19
19
|
const [isEditMode, setIsEditMode] = useState(false);
|
20
|
-
const
|
20
|
+
const [loading, setLoading] = useState(true);
|
21
|
+
const [hasError, setHasError] = useState(false);
|
22
|
+
const [, setTid] = useState("");
|
21
23
|
const config = useMemo(() => ({
|
22
24
|
readonly: false,
|
23
25
|
placeholder: placeholder || "",
|
@@ -39,17 +41,32 @@ const TemplateForm = ({ url }) => {
|
|
39
41
|
if (fetchedUser) {
|
40
42
|
const user = fetchedUser;
|
41
43
|
setIsEditMode(true);
|
44
|
+
setLoading(false);
|
42
45
|
setName(user.name);
|
43
46
|
setContent(user.content);
|
44
47
|
}
|
45
48
|
}
|
46
49
|
catch (error) {
|
47
50
|
console.error("Unable to fetch user data", error);
|
51
|
+
toast.error("Unable to fetch user data", { id: "fetchError" });
|
52
|
+
setLoading(false);
|
53
|
+
setHasError(true);
|
48
54
|
}
|
49
55
|
});
|
50
56
|
fetchTemplateData();
|
51
57
|
}
|
52
58
|
}, [id]);
|
59
|
+
useEffect(() => {
|
60
|
+
if (id) {
|
61
|
+
setTid(id);
|
62
|
+
setIsEditMode(true);
|
63
|
+
setLoading(true);
|
64
|
+
}
|
65
|
+
else {
|
66
|
+
setIsEditMode(false);
|
67
|
+
setLoading(false);
|
68
|
+
}
|
69
|
+
}, [id]);
|
53
70
|
const handleSubmit = (event) => __awaiter(void 0, void 0, void 0, function* () {
|
54
71
|
event.preventDefault();
|
55
72
|
if (!validateForm())
|
@@ -77,6 +94,6 @@ const TemplateForm = ({ url }) => {
|
|
77
94
|
window.history.pushState({}, "", "/admin/template");
|
78
95
|
window.dispatchEvent(new PopStateEvent("popstate"));
|
79
96
|
};
|
80
|
-
return (_jsx("div", { className: "w-full pr-16", children: _jsx("div", { className: "flex-grow p-6", children: _jsxs("form", { children: [_jsx("h1", { className: "text-3xl font-bold text-blue-600 capitalize dark:text-white mb-4", children: isEditMode ? "Edit Template" : "Add Template" }), _jsxs("div", { className: "mb-6 w-full", children: [_jsxs("label", { className: "text-gray-900 dark:text-gray-200 font-semibold", children: ["Name ", _jsx("span", { className: "text-red-500", children: "*" })] }), _jsx("input", { required: true, type: "text", value: name, onChange: (e) => setName(e.target.value), className: "w-full px-4 py-2 mt-2 text-gray-800 bg-white border border-gray-400 rounded-md dark:bg-gray-800 dark:text-gray-300 dark:border-gray-800 focus:border-blue-400 focus:ring-blue-300 focus:ring-opacity-40 dark:focus:border-blue-300 focus:outline-none focus:ring", placeholder: "Enter Name" })] }), _jsxs("div", { className: "mb-6 w-full", children: [_jsxs("label", { className: "text-gray-900 dark:text-gray-200 font-semibold", children: ["Content ", _jsx("span", { className: "text-red-500", children: "*" })] }), _jsx(Editor, { content: content, setContent: setContent, config: config })] }), _jsxs("div", { className: "flex space-x-4 mt-6 justify-start", children: [_jsx("button", { type: "submit", onClick: handleSubmit, className: "px-8 py-2.5 leading-5 text-white transition-colors duration-300 transform bg-blue-600 rounded-md hover:bg-blue-500 focus:outline-none focus:bg-gray-600", children: isEditMode ? "Update" : "Save and Close" }), _jsx("button", { type: "button", onClick: handleCancelClick, className: "px-8 py-2.5 leading-5 text-white transition-colors duration-300 transform bg-blue-600 rounded-md hover:bg-blue-500 focus:outline-none focus:bg-gray-600", children: "Cancel" })] })] }) }) }));
|
97
|
+
return (_jsx("div", { children: _jsx("div", { children: loading ? (_jsx("div", { className: "flex justify-center items-center h-screen", children: _jsx("div", { className: "flex justify-center items-center h-12 w-12 animate-spin rounded-full border-4 border-solid border-current border-e-transparent align-[-0.125em] text-surface motion-reduce:animate-[spin_1.5s_linear_infinite] text-blue-600", role: "status", children: _jsx("span", { className: "!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]", children: "Loading..." }) }) })) : hasError ? (_jsx("div", { className: "flex justify-center items-center h-screen" })) : (_jsx("div", { className: "w-full pr-16", children: _jsx("div", { className: "flex-grow p-6", children: _jsxs("form", { children: [_jsx("h1", { className: "text-3xl font-bold text-blue-600 capitalize dark:text-white mb-4", children: isEditMode ? "Edit Template" : "Add Template" }), _jsxs("div", { className: "mb-6 w-full", children: [_jsxs("label", { className: "text-gray-900 dark:text-gray-200 font-semibold", children: ["Name ", _jsx("span", { className: "text-red-500", children: "*" })] }), _jsx("input", { required: true, type: "text", value: name, onChange: (e) => setName(e.target.value), className: "w-full px-4 py-2 mt-2 text-gray-800 bg-white border border-gray-400 rounded-md dark:bg-gray-800 dark:text-gray-300 dark:border-gray-800 focus:border-blue-400 focus:ring-blue-300 focus:ring-opacity-40 dark:focus:border-blue-300 focus:outline-none focus:ring", placeholder: "Enter Name" })] }), _jsxs("div", { className: "mb-6 w-full", children: [_jsxs("label", { className: "text-gray-900 dark:text-gray-200 font-semibold", children: ["Content ", _jsx("span", { className: "text-red-500", children: "*" })] }), _jsx(Editor, { content: content, setContent: setContent, config: config })] }), _jsxs("div", { className: "flex space-x-4 mt-6 justify-start", children: [_jsx("button", { type: "submit", onClick: handleSubmit, className: "px-8 py-2.5 leading-5 text-white transition-colors duration-300 transform bg-blue-600 rounded-md hover:bg-blue-500 focus:outline-none focus:bg-gray-600", children: isEditMode ? "Update" : "Save and Close" }), _jsx("button", { type: "button", onClick: handleCancelClick, className: "px-8 py-2.5 leading-5 text-white transition-colors duration-300 transform bg-blue-600 rounded-md hover:bg-blue-500 focus:outline-none focus:bg-gray-600", children: "Cancel" })] })] }) }) })) }) }));
|
81
98
|
};
|
82
99
|
export default TemplateForm;
|