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

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.
@@ -24,7 +24,7 @@ const Template = () => {
24
24
  });
25
25
  useEffect(() => {
26
26
  fetchTemplatesData();
27
- });
27
+ }, []);
28
28
  const handleNavigation = (event, path) => {
29
29
  event.preventDefault();
30
30
  window.history.pushState({}, "", path);
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
11
  import React, { useState, useEffect, useRef, useMemo } from "react";
12
- import { addTemplateApi, fetchTemplateByIdApi } from "../api/template";
12
+ import { addTemplateApi, fetchTemplateByIdApi, updateTemplateApi, } from "../api/template";
13
13
  import JoditEditor from "jodit-react";
14
14
  const TemplateForm = () => {
15
15
  const [name, setName] = useState("");
@@ -64,12 +64,33 @@ const TemplateForm = () => {
64
64
  alert("Failed to add template.");
65
65
  }
66
66
  });
67
+ const handleSubmit = (event) => __awaiter(void 0, void 0, void 0, function* () {
68
+ event.preventDefault();
69
+ if (!validateForm())
70
+ return;
71
+ try {
72
+ if (isEditMode) {
73
+ yield updateTemplateApi(id, name, content);
74
+ alert("Template updated successfully");
75
+ }
76
+ else {
77
+ yield addTemplateApi(name, content);
78
+ alert("Template added successfully");
79
+ }
80
+ window.history.pushState({}, "", "/admin/template");
81
+ window.dispatchEvent(new PopStateEvent("popstate"));
82
+ }
83
+ catch (error) {
84
+ console.error("Error adding/updating Template:", error);
85
+ alert("Failed to add/update Template");
86
+ }
87
+ });
67
88
  const handleCancelClick = () => {
68
89
  setName("");
69
90
  setContent("");
70
91
  window.history.pushState({}, "", "/admin/template");
71
92
  window.dispatchEvent(new PopStateEvent("popstate"));
72
93
  };
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" })] })] }) }) }));
94
+ 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: 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 ? "Edit" : "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" })] })] }) }) }));
74
95
  };
75
96
  export default TemplateForm;
@@ -1,3 +1,7 @@
1
1
  export declare const addTemplateApi: (name: string, content: string) => Promise<Axios.AxiosXHR<unknown>>;
2
2
  export declare const fetchTemplatesApi: () => Promise<unknown>;
3
3
  export declare const fetchTemplateByIdApi: (id: string) => Promise<unknown>;
4
+ export declare const updateTemplateApi: (id: string, name: string, content: string) => Promise<unknown>;
5
+ export declare const deleteTemplateApi: (id: string) => Promise<{
6
+ isDeleted: boolean;
7
+ }>;
@@ -60,3 +60,42 @@ export const fetchTemplateByIdApi = (id) => __awaiter(void 0, void 0, void 0, fu
60
60
  return false;
61
61
  }
62
62
  });
63
+ export const updateTemplateApi = (id, name, content) => __awaiter(void 0, void 0, void 0, function* () {
64
+ const token = cookies.get("token");
65
+ try {
66
+ const response = yield axios.post(`${apiUrl}/template/updatetemplate`, {
67
+ id: id,
68
+ name: name,
69
+ content: content,
70
+ }, {
71
+ headers: {
72
+ Authorization: `Bearer ${token}`,
73
+ },
74
+ });
75
+ return response.data;
76
+ }
77
+ catch (error) {
78
+ throw error;
79
+ }
80
+ });
81
+ export const deleteTemplateApi = (id) => __awaiter(void 0, void 0, void 0, function* () {
82
+ const token = cookies.get("token");
83
+ try {
84
+ const response = yield axios.request({
85
+ method: "PATCH",
86
+ url: `${apiUrl}/template/delete/${id}`,
87
+ headers: {
88
+ Authorization: `Bearer ${token}`,
89
+ "Content-Type": "application/json",
90
+ },
91
+ data: {
92
+ isDeleted: true, // Update only the isDeleted property
93
+ },
94
+ });
95
+ return response.data;
96
+ }
97
+ catch (error) {
98
+ console.error("Error updating template:", error);
99
+ throw error;
100
+ }
101
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eleven-solutions-common-website-unique-web",
3
- "version": "9.0.37",
3
+ "version": "9.0.39",
4
4
  "main": "./dist/index.js",
5
5
  "scripts": {
6
6
  "build": "tsc",
@@ -17,7 +17,7 @@ const Template = () => {
17
17
 
18
18
  useEffect(() => {
19
19
  fetchTemplatesData();
20
- });
20
+ }, []);
21
21
 
22
22
  const handleNavigation = (event: React.MouseEvent, path: string) => {
23
23
  event.preventDefault();
@@ -1,5 +1,9 @@
1
1
  import React, { useState, useEffect, useRef, useMemo } from "react";
2
- import { addTemplateApi, fetchTemplateByIdApi } from "../api/template";
2
+ import {
3
+ addTemplateApi,
4
+ fetchTemplateByIdApi,
5
+ updateTemplateApi,
6
+ } from "../api/template";
3
7
  import JoditEditor from "jodit-react";
4
8
 
5
9
  const TemplateForm = () => {
@@ -65,6 +69,26 @@ const TemplateForm = () => {
65
69
  }
66
70
  };
67
71
 
72
+ const handleSubmit = async (event: React.MouseEvent<HTMLButtonElement>) => {
73
+ event.preventDefault();
74
+ if (!validateForm()) return;
75
+
76
+ try {
77
+ if (isEditMode) {
78
+ await updateTemplateApi(id, name, content);
79
+ alert("Template updated successfully");
80
+ } else {
81
+ await addTemplateApi(name, content);
82
+ alert("Template added successfully");
83
+ }
84
+ window.history.pushState({}, "", "/admin/template");
85
+ window.dispatchEvent(new PopStateEvent("popstate"));
86
+ } catch (error) {
87
+ console.error("Error adding/updating Template:", error);
88
+ alert("Failed to add/update Template");
89
+ }
90
+ };
91
+
68
92
  const handleCancelClick = () => {
69
93
  setName("");
70
94
  setContent("");
@@ -110,10 +134,10 @@ const TemplateForm = () => {
110
134
  <div className="flex space-x-4 mt-6 justify-end">
111
135
  <button
112
136
  type="submit"
113
- onClick={handleAddClick}
137
+ onClick={handleSubmit}
114
138
  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"
115
139
  >
116
- Add
140
+ {isEditMode ? "Edit" : "Add"}
117
141
  </button>
118
142
  <button
119
143
  type="button"
@@ -62,3 +62,52 @@ export const fetchTemplateByIdApi = async (id: string) => {
62
62
  return false;
63
63
  }
64
64
  };
65
+
66
+ export const updateTemplateApi = async (
67
+ id: string,
68
+ name: string,
69
+ content: string
70
+ ) => {
71
+ const token = cookies.get("token");
72
+
73
+ try {
74
+ const response = await axios.post(
75
+ `${apiUrl}/template/updatetemplate`,
76
+ {
77
+ id: id,
78
+ name: name,
79
+ content: content,
80
+ },
81
+ {
82
+ headers: {
83
+ Authorization: `Bearer ${token}`,
84
+ },
85
+ }
86
+ );
87
+ return response.data;
88
+ } catch (error) {
89
+ throw error;
90
+ }
91
+ };
92
+
93
+ export const deleteTemplateApi = async (id: string) => {
94
+ const token = cookies.get("token");
95
+
96
+ try {
97
+ const response = await axios.request({
98
+ method: "PATCH",
99
+ url: `${apiUrl}/template/delete/${id}`,
100
+ headers: {
101
+ Authorization: `Bearer ${token}`,
102
+ "Content-Type": "application/json",
103
+ },
104
+ data: {
105
+ isDeleted: true, // Update only the isDeleted property
106
+ },
107
+ });
108
+ return response.data;
109
+ } catch (error) {
110
+ console.error("Error updating template:", error);
111
+ throw error;
112
+ }
113
+ };