eleven-solutions-common-website-unique-web 9.0.36 → 9.0.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,13 +8,14 @@ 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 React, { useState, useRef, useMemo } from "react";
12
- import { addTemplateApi } from "../api/template";
11
+ import React, { useState, useEffect, useRef, useMemo } from "react";
12
+ import { addTemplateApi, fetchTemplateByIdApi } from "../api/template";
13
13
  import JoditEditor from "jodit-react";
14
14
  const TemplateForm = () => {
15
15
  const [name, setName] = useState("");
16
16
  const [content, setContent] = useState("");
17
17
  const [placeholder, setPlaceholder] = React.useState("Enter Content Here.");
18
+ const [isEditMode, setIsEditMode] = useState(false);
18
19
  const editor = useRef(null);
19
20
  const config = useMemo(() => ({
20
21
  readonly: false,
@@ -27,6 +28,27 @@ const TemplateForm = () => {
27
28
  }
28
29
  return true;
29
30
  };
31
+ const queryParams = new URLSearchParams(window.location.search);
32
+ const id = queryParams.get("id");
33
+ useEffect(() => {
34
+ if (id) {
35
+ const fetchTemplateData = () => __awaiter(void 0, void 0, void 0, function* () {
36
+ try {
37
+ const fetchedUser = yield fetchTemplateByIdApi(id);
38
+ if (fetchedUser) {
39
+ const user = fetchedUser;
40
+ setIsEditMode(true);
41
+ setName(user.name);
42
+ setContent(user.content);
43
+ }
44
+ }
45
+ catch (error) {
46
+ console.error("Unable to fetch user data", error);
47
+ }
48
+ });
49
+ fetchTemplateData();
50
+ }
51
+ }, [id]);
30
52
  const handleAddClick = (event) => __awaiter(void 0, void 0, void 0, function* () {
31
53
  event.preventDefault();
32
54
  if (!validateForm())
@@ -48,6 +70,6 @@ const TemplateForm = () => {
48
70
  window.history.pushState({}, "", "/admin/template");
49
71
  window.dispatchEvent(new PopStateEvent("popstate"));
50
72
  };
51
- return (_jsx("div", { className: "max-w-4xl p-6 mx-auto dark:bg-gray-800", children: _jsx("div", { children: _jsxs("form", { children: [_jsx("h1", { className: "text-3xl font-bold text-center text-blue-600 capitalize dark:text-white mb-4", children: "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(JoditEditor, { ref: editor, value: content, config: config, onBlur: (newContent) => setContent(newContent), onChange: (newContent) => { } })] }), _jsxs("div", { className: "flex space-x-4 mt-6 justify-end", children: [_jsx("button", { type: "submit", onClick: handleAddClick, 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: "Add" }), _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" })] })] }) }) }));
73
+ return (_jsx("div", { className: "max-w-4xl p-6 mx-auto dark:bg-gray-800", children: _jsx("div", { children: _jsxs("form", { children: [_jsx("h1", { className: "text-3xl font-bold text-center 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(JoditEditor, { ref: editor, value: content, config: config, onBlur: (newContent) => setContent(newContent), onChange: (newContent) => { } })] }), _jsxs("div", { className: "flex space-x-4 mt-6 justify-end", children: [_jsx("button", { type: "submit", onClick: handleAddClick, 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: "Add" }), _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" })] })] }) }) }));
52
74
  };
53
75
  export default TemplateForm;
@@ -1,2 +1,3 @@
1
1
  export declare const addTemplateApi: (name: string, content: string) => Promise<Axios.AxiosXHR<unknown>>;
2
2
  export declare const fetchTemplatesApi: () => Promise<unknown>;
3
+ export declare const fetchTemplateByIdApi: (id: string) => Promise<unknown>;
@@ -44,3 +44,19 @@ export const fetchTemplatesApi = () => __awaiter(void 0, void 0, void 0, functio
44
44
  return false;
45
45
  }
46
46
  });
47
+ export const fetchTemplateByIdApi = (id) => __awaiter(void 0, void 0, void 0, function* () {
48
+ const cookies = new Cookies();
49
+ const token = cookies.get("token");
50
+ try {
51
+ const response = yield axios.get(`${apiUrl}/template/gettemplatebyid/${id}`, {
52
+ headers: {
53
+ Authorization: `Bearer ${token}`,
54
+ },
55
+ });
56
+ return response.data;
57
+ }
58
+ catch (error) {
59
+ console.error("Error fetching template by ID:", error);
60
+ return false;
61
+ }
62
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eleven-solutions-common-website-unique-web",
3
- "version": "9.0.36",
3
+ "version": "9.0.37",
4
4
  "main": "./dist/index.js",
5
5
  "scripts": {
6
6
  "build": "tsc",
@@ -1,5 +1,5 @@
1
- import React, { useState, useRef, useMemo } from "react";
2
- import { addTemplateApi } from "../api/template";
1
+ import React, { useState, useEffect, useRef, useMemo } from "react";
2
+ import { addTemplateApi, fetchTemplateByIdApi } from "../api/template";
3
3
  import JoditEditor from "jodit-react";
4
4
 
5
5
  const TemplateForm = () => {
@@ -7,6 +7,8 @@ const TemplateForm = () => {
7
7
  const [content, setContent] = useState("");
8
8
  const [placeholder, setPlaceholder] = React.useState("Enter Content Here.");
9
9
 
10
+ const [isEditMode, setIsEditMode] = useState<boolean>(false);
11
+
10
12
  const editor = useRef(null);
11
13
  const config: Record<string, any> = useMemo(
12
14
  () => ({
@@ -24,6 +26,31 @@ const TemplateForm = () => {
24
26
  return true;
25
27
  };
26
28
 
29
+ const queryParams = new URLSearchParams(window.location.search);
30
+ const id = queryParams.get("id");
31
+
32
+ useEffect(() => {
33
+ if (id) {
34
+ const fetchTemplateData = async () => {
35
+ try {
36
+ const fetchedUser = await fetchTemplateByIdApi(id);
37
+ if (fetchedUser) {
38
+ const user = fetchedUser as {
39
+ name: string;
40
+ content: string;
41
+ };
42
+ setIsEditMode(true);
43
+ setName(user.name);
44
+ setContent(user.content);
45
+ }
46
+ } catch (error) {
47
+ console.error("Unable to fetch user data", error);
48
+ }
49
+ };
50
+ fetchTemplateData();
51
+ }
52
+ }, [id]);
53
+
27
54
  const handleAddClick = async (event: React.MouseEvent<HTMLButtonElement>) => {
28
55
  event.preventDefault();
29
56
  if (!validateForm()) return;
@@ -51,7 +78,7 @@ const TemplateForm = () => {
51
78
  <div>
52
79
  <form>
53
80
  <h1 className="text-3xl font-bold text-center text-blue-600 capitalize dark:text-white mb-4">
54
- Add Template
81
+ {isEditMode ? "Edit Template" : "Add Template"}
55
82
  </h1>
56
83
 
57
84
  <div className="mb-6 w-full">
@@ -41,3 +41,24 @@ export const fetchTemplatesApi = async () => {
41
41
  return false;
42
42
  }
43
43
  };
44
+
45
+ export const fetchTemplateByIdApi = async (id: string) => {
46
+ const cookies = new Cookies();
47
+ const token = cookies.get("token");
48
+
49
+ try {
50
+ const response = await axios.get(
51
+ `${apiUrl}/template/gettemplatebyid/${id}`,
52
+ {
53
+ headers: {
54
+ Authorization: `Bearer ${token}`,
55
+ },
56
+ }
57
+ );
58
+
59
+ return response.data;
60
+ } catch (error) {
61
+ console.error("Error fetching template by ID:", error);
62
+ return false;
63
+ }
64
+ };