eleven-solutions-common-website-unique-web 1.0.14 → 1.0.16

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,7 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
11
11
  import { useState, useEffect } from "react";
12
- import { useLocation } from "react-router-dom";
13
12
  import { addTaxonomyApi, fetchTaxonomyByIdApi, updateTaxonomyApi, fetchTaxonomiessApi, addMultipleTaxonomiesApi, deleteTaxonomyApi, isMultipleApi, } from "../api/taxonomy";
14
13
  import { FaPlus } from "react-icons/fa";
15
14
  const TaxonomyForm = () => {
@@ -34,14 +33,104 @@ const TaxonomyForm = () => {
34
33
  }
35
34
  return true;
36
35
  };
37
- const location = useLocation();
36
+ // const location = useLocation();
38
37
  // const navigate = useNavigate();
39
38
  // const { id } = location.state || {};
40
- const getIdFromUrl = () => {
41
- const params = new URLSearchParams(window.location.search);
42
- return params.get("id") || "";
43
- };
44
- const [id, setId] = useState(getIdFromUrl());
39
+ // useEffect(() => {
40
+ // if (id) {
41
+ // const fetchTaxonomyData = async () => {
42
+ // try {
43
+ // const fetchedTaxonomy = await fetchTaxonomyByIdApi(id);
44
+ // if (fetchedTaxonomy) {
45
+ // const taxonomy = fetchedTaxonomy as {
46
+ // type: string;
47
+ // code: string | number;
48
+ // value: string;
49
+ // };
50
+ // setIsEditMode(true);
51
+ // setType(taxonomy.type);
52
+ // setCode(taxonomy.code);
53
+ // setValue(taxonomy.value);
54
+ // }
55
+ // } catch (error) {
56
+ // console.error("Unable to fetch taxonomy data", error);
57
+ // }
58
+ // };
59
+ // fetchTaxonomyData();
60
+ // }
61
+ // }, [id]);
62
+ // useEffect(() => {
63
+ // const handleFetchSimilarTaxonomies = async () => {
64
+ // try {
65
+ // const response = await fetchTaxonomiessApi();
66
+ // // const filteredTaxonomies = response.filter(
67
+ // const filteredTaxonomies = (response as { type: string }[]).filter(
68
+ // (taxonomy: { type: string }) => taxonomy.type === type
69
+ // );
70
+ // setSimilarTaxonomies(filteredTaxonomies);
71
+ // } catch (error) {
72
+ // console.error("Error fetching similar taxonomies", error);
73
+ // }
74
+ // };
75
+ // if (type) {
76
+ // handleFetchSimilarTaxonomies();
77
+ // }
78
+ // }, [type]);
79
+ // useEffect(() => {
80
+ // if (location.pathname === "/taxonomy/taxonomyform") {
81
+ // setIsSimilarTaxonomyOpen(true);
82
+ // }
83
+ // }, [location.pathname]);
84
+ // const handleSubmit = async (event: React.MouseEvent<HTMLButtonElement>) => {
85
+ // event.preventDefault();
86
+ // if (!validateForm()) return;
87
+ // try {
88
+ // if (isEditMode) {
89
+ // await addMultipleTaxonomiesApi(tempTaxonomy);
90
+ // setTempTaxonomy([]);
91
+ // alert("taxonomies added successfully");
92
+ // } else {
93
+ // await addTaxonomyApi(type, Number(code), value);
94
+ // alert("Taxonomy added successfully");
95
+ // }
96
+ // navigate("/admin/taxonomy");
97
+ // } catch (error) {
98
+ // console.error("Error adding/updating Taxonomy:", error);
99
+ // alert("Failed to add/update Taxonomy");
100
+ // }
101
+ // };
102
+ // const handleSave = async (event: React.MouseEvent<HTMLButtonElement>) => {
103
+ // event.preventDefault();
104
+ // if (!validateForm()) return;
105
+ // try {
106
+ // if (isEditMode) {
107
+ // await updateTaxonomyApi(id, type, Number(code), value);
108
+ // alert("Taxonomy updated successfully");
109
+ // } else {
110
+ // await addTaxonomyApi(type, Number(code), value);
111
+ // alert("Taxonomy added successfully");
112
+ // }
113
+ // navigate("/admin/taxonomy");
114
+ // } catch (error) {
115
+ // console.error("Error adding/updating Taxonomy:", error);
116
+ // alert("Failed to add/update Taxonomy");
117
+ // }
118
+ // };
119
+ // useEffect(() => {
120
+ // const fetchIsMultiple = async () => {
121
+ // try {
122
+ // const result = await isMultipleApi(type);
123
+ // setIsMultiple(typeof result === "boolean");
124
+ // } catch (error) {
125
+ // console.error("Error checking if taxonomy is multiple:", error);
126
+ // }
127
+ // };
128
+ // fetchIsMultiple();
129
+ // }, [location.pathname, type]);
130
+ // Extract the id from the URL query parameters
131
+ const queryParams = new URLSearchParams(window.location.search);
132
+ const id = queryParams.get("id");
133
+ // Fetch taxonomy data if id exists
45
134
  useEffect(() => {
46
135
  if (id) {
47
136
  const fetchTaxonomyData = () => __awaiter(void 0, void 0, void 0, function* () {
@@ -62,11 +151,11 @@ const TaxonomyForm = () => {
62
151
  fetchTaxonomyData();
63
152
  }
64
153
  }, [id]);
154
+ // Fetch similar taxonomies based on the type
65
155
  useEffect(() => {
66
156
  const handleFetchSimilarTaxonomies = () => __awaiter(void 0, void 0, void 0, function* () {
67
157
  try {
68
158
  const response = yield fetchTaxonomiessApi();
69
- // const filteredTaxonomies = response.filter(
70
159
  const filteredTaxonomies = response.filter((taxonomy) => taxonomy.type === type);
71
160
  setSimilarTaxonomies(filteredTaxonomies);
72
161
  }
@@ -78,11 +167,13 @@ const TaxonomyForm = () => {
78
167
  handleFetchSimilarTaxonomies();
79
168
  }
80
169
  }, [type]);
170
+ // Check if the current pathname matches "/taxonomy/taxonomyform"
81
171
  useEffect(() => {
82
- if (location.pathname === "/taxonomy/taxonomyform") {
172
+ if (window.location.pathname === "/taxonomy/taxonomyform") {
83
173
  setIsSimilarTaxonomyOpen(true);
84
174
  }
85
- }, [location.pathname]);
175
+ }, []);
176
+ // Handle form submission
86
177
  const handleSubmit = (event) => __awaiter(void 0, void 0, void 0, function* () {
87
178
  event.preventDefault();
88
179
  if (!validateForm())
@@ -91,26 +182,20 @@ const TaxonomyForm = () => {
91
182
  if (isEditMode) {
92
183
  yield addMultipleTaxonomiesApi(tempTaxonomy);
93
184
  setTempTaxonomy([]);
94
- alert("taxonomies added successfully");
185
+ alert("Taxonomies added successfully");
95
186
  }
96
187
  else {
97
188
  yield addTaxonomyApi(type, Number(code), value);
98
189
  alert("Taxonomy added successfully");
99
190
  }
100
- // navigate("/admin/taxonomy");
101
- const link = document.createElement("a");
102
- link.href = "/admin/taxonomy";
103
- link.onclick = (e) => {
104
- e.preventDefault();
105
- window.history.pushState({}, "", "/admin/taxonomy");
106
- };
107
- link.click();
191
+ window.location.href = "/admin/taxonomy";
108
192
  }
109
193
  catch (error) {
110
194
  console.error("Error adding/updating Taxonomy:", error);
111
195
  alert("Failed to add/update Taxonomy");
112
196
  }
113
197
  });
198
+ // Handle save operation
114
199
  const handleSave = (event) => __awaiter(void 0, void 0, void 0, function* () {
115
200
  event.preventDefault();
116
201
  if (!validateForm())
@@ -124,20 +209,14 @@ const TaxonomyForm = () => {
124
209
  yield addTaxonomyApi(type, Number(code), value);
125
210
  alert("Taxonomy added successfully");
126
211
  }
127
- // navigate("/admin/taxonomy");
128
- const link = document.createElement("a");
129
- link.href = "/admin/taxonomy";
130
- link.onclick = (e) => {
131
- e.preventDefault();
132
- window.history.pushState({}, "", "/admin/taxonomy");
133
- };
134
- link.click();
212
+ window.location.href = "/admin/taxonomy"; // Navigate to the taxonomy page
135
213
  }
136
214
  catch (error) {
137
215
  console.error("Error adding/updating Taxonomy:", error);
138
216
  alert("Failed to add/update Taxonomy");
139
217
  }
140
218
  });
219
+ // Fetch "isMultiple" property based on the taxonomy type
141
220
  useEffect(() => {
142
221
  const fetchIsMultiple = () => __awaiter(void 0, void 0, void 0, function* () {
143
222
  try {
@@ -149,19 +228,18 @@ const TaxonomyForm = () => {
149
228
  }
150
229
  });
151
230
  fetchIsMultiple();
152
- }, [location.pathname, type]);
231
+ }, [type]);
232
+ // const handleCancelClick = () => {
233
+ // setType("");
234
+ // setCode("");
235
+ // setValue("");
236
+ // navigate("/admin/taxonomy");
237
+ // };
153
238
  const handleCancelClick = () => {
154
239
  setType("");
155
240
  setCode("");
156
241
  setValue("");
157
- // navigate("/admin/taxonomy");
158
- const link = document.createElement("a");
159
- link.href = "/admin/taxonomy";
160
- link.onclick = (e) => {
161
- e.preventDefault(); // prevent the default behavior of the anchor tag
162
- window.history.pushState({}, "", "/admin/taxonomy");
163
- };
164
- link.click();
242
+ window.location.href = "/admin/taxonomy";
165
243
  };
166
244
  const handleOpenModal = () => {
167
245
  setEditTaxonomyItem(null);
@@ -249,16 +327,24 @@ const TaxonomyForm = () => {
249
327
  console.error("Error deleting Taxonomy:", error);
250
328
  }
251
329
  });
252
- return (_jsxs("div", { className: `${isEditMode && isMultiple ? "w-full" : "max-w-4xl"} p-6 mx-auto dark:bg-gray-800`, children: [_jsxs("div", { className: `transition duration-300 ${isModalOpen ? "filter blur-sm" : ""}`, children: [_jsx("h1", { className: "text-3xl font-bold text-center text-blue-600 capitalize dark:text-white mb-4", children: isEditMode ? "Edit Taxonomy" : "Add Taxonomy" }), _jsx("h1", { className: "text-2xl text-blue-600 capitalize dark:text-white mb-4", children: isEditMode ? `Taxonomy Type: ${type}` : "" }), !isMultiple && (_jsxs("form", { children: [!isEditMode && (_jsxs("div", { className: "mb-6 w-full", children: [_jsxs("label", { className: "text-gray-900 dark:text-gray-200 font-semibold", children: ["Type ", _jsx("span", { className: "text-red-500", children: "*" })] }), _jsx("input", { required: true, value: type, onChange: (e) => setType(e.target.value), type: "text", 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 Type" })] })), _jsxs("div", { className: "mb-6 w-full", children: [_jsxs("label", { className: "text-gray-900 dark:text-gray-200 font-semibold", children: ["Code ", _jsx("span", { className: "text-red-500", children: "*" })] }), _jsx("input", { required: true, value: code, onChange: (e) => setCode(e.target.value === "" ? "" : Number(e.target.value)), type: "number", 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 Code", disabled: similarTaxonomies.some((taxonomy) => taxonomy.isEdit === false) })] }), _jsxs("div", { className: "mb-6 w-full", children: [_jsxs("label", { className: "text-gray-900 dark:text-gray-200 font-semibold", children: ["Value ", _jsx("span", { className: "text-red-500", children: "*" })] }), _jsx("input", { required: true, value: value, onChange: (e) => setValue(e.target.value), type: "text", 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 Value", disabled: similarTaxonomies.some((taxonomy) => taxonomy.isEdit === false) })] }), _jsxs("div", { className: "flex space-x-4 mt-6 justify-between", children: [_jsx("div", { children: isEditMode && (_jsx("div", { children: similarTaxonomies.some((taxonomy) => taxonomy.isEdit) && (_jsx("button", { type: "button", onClick: () => {
330
+ return (_jsxs("div", { className: `${isEditMode && isMultiple ? "w-full" : "max-w-4xl"} p-6 mx-auto dark:bg-gray-800`, children: [_jsxs("div", { className: `transition duration-300 ${isModalOpen ? "filter blur-sm" : ""}`, children: [_jsx("h1", { className: "text-3xl font-bold text-center text-blue-600 capitalize dark:text-white mb-4", children: isEditMode ? "Edit Taxonomy" : "Add Taxonomy" }), _jsx("h1", { className: "text-2xl text-blue-600 capitalize dark:text-white mb-4", children: isEditMode ? `Taxonomy Type: ${type}` : "" }), !isMultiple && (_jsxs("form", { children: [!isEditMode && (_jsxs("div", { className: "mb-6 w-full", children: [_jsxs("label", { className: "text-gray-900 dark:text-gray-200 font-semibold", children: ["Type ", _jsx("span", { className: "text-red-500", children: "*" })] }), _jsx("input", { required: true, value: type, onChange: (e) => setType(e.target.value), type: "text", 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 Type" })] })), _jsxs("div", { className: "mb-6 w-full", children: [_jsxs("label", { className: "text-gray-900 dark:text-gray-200 font-semibold", children: ["Code ", _jsx("span", { className: "text-red-500", children: "*" })] }), _jsx("input", { required: true, value: code, onChange: (e) => setCode(e.target.value === "" ? "" : Number(e.target.value)), type: "number", 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 Code", disabled: similarTaxonomies.some((taxonomy) => taxonomy.isEdit === false) })] }), _jsxs("div", { className: "mb-6 w-full", children: [_jsxs("label", { className: "text-gray-900 dark:text-gray-200 font-semibold", children: ["Value ", _jsx("span", { className: "text-red-500", children: "*" })] }), _jsx("input", { required: true, value: value, onChange: (e) => setValue(e.target.value), type: "text", 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 Value", disabled: similarTaxonomies.some((taxonomy) => taxonomy.isEdit === false) })] }), _jsxs("div", { className: "flex space-x-4 mt-6 justify-between", children: [_jsx("div", { children: isEditMode && (
331
+ // <div>
332
+ // {similarTaxonomies.some((taxonomy) => taxonomy.isEdit) && (
333
+ // <button
334
+ // type="button"
335
+ // onClick={() => {
336
+ // handleDeleteClick(id);
337
+ // navigate("/admin/taxonomy");
338
+ // }}
339
+ // 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"
340
+ // >
341
+ // Delete
342
+ // </button>
343
+ // )}
344
+ // </div>
345
+ _jsx("div", { children: similarTaxonomies.some((taxonomy) => taxonomy.isEdit) && (_jsx("button", { type: "button", onClick: () => {
253
346
  handleDeleteClick(id);
254
- // navigate("/admin/taxonomy");
255
- const link = document.createElement("a");
256
- link.href = "/admin/taxonomy";
257
- link.onclick = (e) => {
258
- e.preventDefault();
259
- window.history.pushState({}, "", "/admin/taxonomy");
260
- };
261
- link.click();
347
+ window.location.href = "/admin/taxonomy";
262
348
  }, 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: "Delete" })) })) }), _jsxs("div", { className: "flex space-x-4 justify-end", children: [similarTaxonomies.some((taxonomy) => taxonomy.isEdit) && (_jsx("button", { type: "submit", onClick: handleSave, 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 ? "Save" : "Add" })), !similarTaxonomies.some((taxonomy) => taxonomy.isEdit) &&
263
349
  !isEditMode && (_jsx("button", { type: "submit", onClick: handleSave, 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 ? "Save" : "Add" })), _jsx("button", { onClick: handleCancelClick, type: "button", 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" })] })] })] })), isSimilarTaxonomyOpen && isMultiple && isEditMode && (_jsxs("div", { className: "flex-grow ml-0 mt-4 w-full", children: [_jsx("div", { className: "overflow-hidden border border-gray-200 dark:border-gray-700 md:rounded-lg mt-6", children: _jsxs("table", { className: "min-w-full divide-y divide-gray-200 dark:divide-gray-700", children: [_jsx("thead", { className: "bg-gray-50 dark:bg-gray-800", children: _jsxs("tr", { children: [similarTaxonomies.some((taxonomy) => taxonomy.isEdit) && (_jsx("th", { className: "px-4 py-3.5 text-md font-normal text-left rtl:text-right text-gray-500 dark:text-gray-400", children: "Actions" })), _jsx("th", { className: "px-4 py-3.5 text-md font-normal text-left rtl:text-right text-gray-500 dark:text-gray-400", children: "Code" }), _jsx("th", { className: "px-4 py-3.5 text-md font-normal text-left rtl:text-right text-gray-500 dark:text-gray-400", children: "Value" })] }) }), _jsx("tbody", { className: "divide-y divide-gray-200", children: similarTaxonomies.map((taxonomy, index) => (_jsxs("tr", { children: [similarTaxonomies.some((taxonomy) => taxonomy.isEdit) && (_jsx("td", { className: "px-4 py-4 text-sm whitespace-nowrap", children: _jsxs("div", { className: "flex items-center gap-x-6", children: [_jsx("button", { type: "button", onClick: () => handleDeleteClick(taxonomy.id), className: "text-gray-500 transition-colors duration-200 dark:hover:text-red-600 dark:text-gray-300 hover:text-red-500 focus:outline-none", children: _jsx("svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", "stroke-width": "1.5", stroke: "currentColor", className: "w-5 h-5", children: _jsx("path", { "stroke-linecap": "round", "stroke-linejoin": "round", d: "M14.74 9l-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 01-2.244 2.077H8.084a2.25 2.25 0 01-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 00-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 013.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 00-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 00-7.5 0" }) }) }), _jsx("button", { type: "button", onClick: () => {
264
350
  handleEditClick(index, taxonomy.id);
@@ -83,7 +83,7 @@ const UserForm = () => {
83
83
  yield addUserApi(userName, email, mobile, address, roleType);
84
84
  alert("User added successfully");
85
85
  }
86
- window.location.href = "/admin/user"; // Redirect using an <a> tag behavior
86
+ window.location.href = "/admin/user";
87
87
  }
88
88
  catch (error) {
89
89
  console.error("Error adding/updating User:", error);
@@ -5,9 +5,9 @@ export { default as Privacy } from "./footer/Privacy";
5
5
  export { default as Login } from "./login/Login";
6
6
  export { default as Header } from "./login/Header";
7
7
  export { default as Users } from "./admin/Users";
8
- export { default as UserForm } from "./admin/Users";
8
+ export { default as UserForm } from "./admin/UserForm";
9
9
  export { default as Taxionomies } from "./admin/Taxionomies";
10
- export { default as TaxonomyForm } from "./admin/Taxionomies";
10
+ export { default as TaxonomyForm } from "./admin/TaxonomyForm";
11
11
  export { default as AdminSideBar } from "./admin/Sidebar";
12
12
  export { default as Dashboard } from "./admin/Dashboard";
13
13
  export { registerApi, loginApi } from "./api/api";
@@ -6,9 +6,9 @@ export { default as Privacy } from "./footer/Privacy";
6
6
  export { default as Login } from "./login/Login";
7
7
  export { default as Header } from "./login/Header";
8
8
  export { default as Users } from "./admin/Users";
9
- export { default as UserForm } from "./admin/Users";
9
+ export { default as UserForm } from "./admin/UserForm";
10
10
  export { default as Taxionomies } from "./admin/Taxionomies";
11
- export { default as TaxonomyForm } from "./admin/Taxionomies";
11
+ export { default as TaxonomyForm } from "./admin/TaxonomyForm";
12
12
  export { default as AdminSideBar } from "./admin/Sidebar";
13
13
  export { default as Dashboard } from "./admin/Dashboard";
14
14
  export { registerApi, loginApi } from "./api/api";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eleven-solutions-common-website-unique-web",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "main": "./dist/index.js",
5
5
  "scripts": {
6
6
  "build": "tsc",
@@ -1,6 +1,5 @@
1
1
  import React from "react";
2
2
  import { useState, useEffect } from "react";
3
- import { useLocation } from "react-router-dom";
4
3
  import {
5
4
  addTaxonomyApi,
6
5
  fetchTaxonomyByIdApi,
@@ -55,16 +54,117 @@ const TaxonomyForm = () => {
55
54
  return true;
56
55
  };
57
56
 
58
- const location = useLocation();
57
+ // const location = useLocation();
59
58
  // const navigate = useNavigate();
60
59
 
61
60
  // const { id } = location.state || {};
62
- const getIdFromUrl = () => {
63
- const params = new URLSearchParams(window.location.search);
64
- return params.get("id") || "";
65
- };
66
- const [id, setId] = useState<string>(getIdFromUrl());
67
61
 
62
+ // useEffect(() => {
63
+ // if (id) {
64
+ // const fetchTaxonomyData = async () => {
65
+ // try {
66
+ // const fetchedTaxonomy = await fetchTaxonomyByIdApi(id);
67
+ // if (fetchedTaxonomy) {
68
+ // const taxonomy = fetchedTaxonomy as {
69
+ // type: string;
70
+ // code: string | number;
71
+ // value: string;
72
+ // };
73
+ // setIsEditMode(true);
74
+ // setType(taxonomy.type);
75
+ // setCode(taxonomy.code);
76
+ // setValue(taxonomy.value);
77
+ // }
78
+ // } catch (error) {
79
+ // console.error("Unable to fetch taxonomy data", error);
80
+ // }
81
+ // };
82
+ // fetchTaxonomyData();
83
+ // }
84
+ // }, [id]);
85
+
86
+ // useEffect(() => {
87
+ // const handleFetchSimilarTaxonomies = async () => {
88
+ // try {
89
+ // const response = await fetchTaxonomiessApi();
90
+ // // const filteredTaxonomies = response.filter(
91
+ // const filteredTaxonomies = (response as { type: string }[]).filter(
92
+ // (taxonomy: { type: string }) => taxonomy.type === type
93
+ // );
94
+ // setSimilarTaxonomies(filteredTaxonomies);
95
+ // } catch (error) {
96
+ // console.error("Error fetching similar taxonomies", error);
97
+ // }
98
+ // };
99
+
100
+ // if (type) {
101
+ // handleFetchSimilarTaxonomies();
102
+ // }
103
+ // }, [type]);
104
+
105
+ // useEffect(() => {
106
+ // if (location.pathname === "/taxonomy/taxonomyform") {
107
+ // setIsSimilarTaxonomyOpen(true);
108
+ // }
109
+ // }, [location.pathname]);
110
+
111
+ // const handleSubmit = async (event: React.MouseEvent<HTMLButtonElement>) => {
112
+ // event.preventDefault();
113
+ // if (!validateForm()) return;
114
+
115
+ // try {
116
+ // if (isEditMode) {
117
+ // await addMultipleTaxonomiesApi(tempTaxonomy);
118
+ // setTempTaxonomy([]);
119
+ // alert("taxonomies added successfully");
120
+ // } else {
121
+ // await addTaxonomyApi(type, Number(code), value);
122
+ // alert("Taxonomy added successfully");
123
+ // }
124
+ // navigate("/admin/taxonomy");
125
+ // } catch (error) {
126
+ // console.error("Error adding/updating Taxonomy:", error);
127
+ // alert("Failed to add/update Taxonomy");
128
+ // }
129
+ // };
130
+
131
+ // const handleSave = async (event: React.MouseEvent<HTMLButtonElement>) => {
132
+ // event.preventDefault();
133
+ // if (!validateForm()) return;
134
+
135
+ // try {
136
+ // if (isEditMode) {
137
+ // await updateTaxonomyApi(id, type, Number(code), value);
138
+ // alert("Taxonomy updated successfully");
139
+ // } else {
140
+ // await addTaxonomyApi(type, Number(code), value);
141
+ // alert("Taxonomy added successfully");
142
+ // }
143
+ // navigate("/admin/taxonomy");
144
+ // } catch (error) {
145
+ // console.error("Error adding/updating Taxonomy:", error);
146
+ // alert("Failed to add/update Taxonomy");
147
+ // }
148
+ // };
149
+
150
+ // useEffect(() => {
151
+ // const fetchIsMultiple = async () => {
152
+ // try {
153
+ // const result = await isMultipleApi(type);
154
+ // setIsMultiple(typeof result === "boolean");
155
+ // } catch (error) {
156
+ // console.error("Error checking if taxonomy is multiple:", error);
157
+ // }
158
+ // };
159
+
160
+ // fetchIsMultiple();
161
+ // }, [location.pathname, type]);
162
+
163
+ // Extract the id from the URL query parameters
164
+ const queryParams = new URLSearchParams(window.location.search);
165
+ const id = queryParams.get("id");
166
+
167
+ // Fetch taxonomy data if id exists
68
168
  useEffect(() => {
69
169
  if (id) {
70
170
  const fetchTaxonomyData = async () => {
@@ -89,11 +189,11 @@ const TaxonomyForm = () => {
89
189
  }
90
190
  }, [id]);
91
191
 
192
+ // Fetch similar taxonomies based on the type
92
193
  useEffect(() => {
93
194
  const handleFetchSimilarTaxonomies = async () => {
94
195
  try {
95
196
  const response = await fetchTaxonomiessApi();
96
- // const filteredTaxonomies = response.filter(
97
197
  const filteredTaxonomies = (response as { type: string }[]).filter(
98
198
  (taxonomy: { type: string }) => taxonomy.type === type
99
199
  );
@@ -108,12 +208,14 @@ const TaxonomyForm = () => {
108
208
  }
109
209
  }, [type]);
110
210
 
211
+ // Check if the current pathname matches "/taxonomy/taxonomyform"
111
212
  useEffect(() => {
112
- if (location.pathname === "/taxonomy/taxonomyform") {
213
+ if (window.location.pathname === "/taxonomy/taxonomyform") {
113
214
  setIsSimilarTaxonomyOpen(true);
114
215
  }
115
- }, [location.pathname]);
216
+ }, []);
116
217
 
218
+ // Handle form submission
117
219
  const handleSubmit = async (event: React.MouseEvent<HTMLButtonElement>) => {
118
220
  event.preventDefault();
119
221
  if (!validateForm()) return;
@@ -122,26 +224,19 @@ const TaxonomyForm = () => {
122
224
  if (isEditMode) {
123
225
  await addMultipleTaxonomiesApi(tempTaxonomy);
124
226
  setTempTaxonomy([]);
125
- alert("taxonomies added successfully");
227
+ alert("Taxonomies added successfully");
126
228
  } else {
127
229
  await addTaxonomyApi(type, Number(code), value);
128
230
  alert("Taxonomy added successfully");
129
231
  }
130
- // navigate("/admin/taxonomy");
131
-
132
- const link = document.createElement("a");
133
- link.href = "/admin/taxonomy";
134
- link.onclick = (e) => {
135
- e.preventDefault();
136
- window.history.pushState({}, "", "/admin/taxonomy");
137
- };
138
- link.click();
232
+ window.location.href = "/admin/taxonomy";
139
233
  } catch (error) {
140
234
  console.error("Error adding/updating Taxonomy:", error);
141
235
  alert("Failed to add/update Taxonomy");
142
236
  }
143
237
  };
144
238
 
239
+ // Handle save operation
145
240
  const handleSave = async (event: React.MouseEvent<HTMLButtonElement>) => {
146
241
  event.preventDefault();
147
242
  if (!validateForm()) return;
@@ -154,20 +249,14 @@ const TaxonomyForm = () => {
154
249
  await addTaxonomyApi(type, Number(code), value);
155
250
  alert("Taxonomy added successfully");
156
251
  }
157
- // navigate("/admin/taxonomy");
158
- const link = document.createElement("a");
159
- link.href = "/admin/taxonomy";
160
- link.onclick = (e) => {
161
- e.preventDefault();
162
- window.history.pushState({}, "", "/admin/taxonomy");
163
- };
164
- link.click();
252
+ window.location.href = "/admin/taxonomy"; // Navigate to the taxonomy page
165
253
  } catch (error) {
166
254
  console.error("Error adding/updating Taxonomy:", error);
167
255
  alert("Failed to add/update Taxonomy");
168
256
  }
169
257
  };
170
258
 
259
+ // Fetch "isMultiple" property based on the taxonomy type
171
260
  useEffect(() => {
172
261
  const fetchIsMultiple = async () => {
173
262
  try {
@@ -179,20 +268,20 @@ const TaxonomyForm = () => {
179
268
  };
180
269
 
181
270
  fetchIsMultiple();
182
- }, [location.pathname, type]);
271
+ }, [type]);
272
+
273
+ // const handleCancelClick = () => {
274
+ // setType("");
275
+ // setCode("");
276
+ // setValue("");
277
+ // navigate("/admin/taxonomy");
278
+ // };
183
279
 
184
280
  const handleCancelClick = () => {
185
281
  setType("");
186
282
  setCode("");
187
283
  setValue("");
188
- // navigate("/admin/taxonomy");
189
- const link = document.createElement("a");
190
- link.href = "/admin/taxonomy";
191
- link.onclick = (e) => {
192
- e.preventDefault(); // prevent the default behavior of the anchor tag
193
- window.history.pushState({}, "", "/admin/taxonomy");
194
- };
195
- link.click();
284
+ window.location.href = "/admin/taxonomy";
196
285
  };
197
286
 
198
287
  const handleOpenModal = () => {
@@ -375,20 +464,27 @@ const TaxonomyForm = () => {
375
464
  <div className="flex space-x-4 mt-6 justify-between">
376
465
  <div>
377
466
  {isEditMode && (
467
+ // <div>
468
+ // {similarTaxonomies.some((taxonomy) => taxonomy.isEdit) && (
469
+ // <button
470
+ // type="button"
471
+ // onClick={() => {
472
+ // handleDeleteClick(id);
473
+ // navigate("/admin/taxonomy");
474
+ // }}
475
+ // 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"
476
+ // >
477
+ // Delete
478
+ // </button>
479
+ // )}
480
+ // </div>
378
481
  <div>
379
482
  {similarTaxonomies.some((taxonomy) => taxonomy.isEdit) && (
380
483
  <button
381
484
  type="button"
382
485
  onClick={() => {
383
486
  handleDeleteClick(id);
384
- // navigate("/admin/taxonomy");
385
- const link = document.createElement("a");
386
- link.href = "/admin/taxonomy";
387
- link.onclick = (e) => {
388
- e.preventDefault();
389
- window.history.pushState({}, "", "/admin/taxonomy");
390
- };
391
- link.click();
487
+ window.location.href = "/admin/taxonomy";
392
488
  }}
393
489
  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"
394
490
  >
@@ -91,7 +91,7 @@ const UserForm = () => {
91
91
  await addUserApi(userName, email, mobile, address, roleType);
92
92
  alert("User added successfully");
93
93
  }
94
- window.location.href = "/admin/user"; // Redirect using an <a> tag behavior
94
+ window.location.href = "/admin/user";
95
95
  } catch (error) {
96
96
  console.error("Error adding/updating User:", error);
97
97
  alert("Failed to add/update User");
@@ -6,9 +6,9 @@ export { default as Privacy } from "./footer/Privacy";
6
6
  export { default as Login } from "./login/Login";
7
7
  export { default as Header } from "./login/Header";
8
8
  export { default as Users } from "./admin/Users";
9
- export { default as UserForm } from "./admin/Users";
9
+ export { default as UserForm } from "./admin/UserForm";
10
10
  export { default as Taxionomies } from "./admin/Taxionomies";
11
- export { default as TaxonomyForm } from "./admin/Taxionomies";
11
+ export { default as TaxonomyForm } from "./admin/TaxonomyForm";
12
12
  export { default as AdminSideBar } from "./admin/Sidebar";
13
13
  export { default as Dashboard } from "./admin/Dashboard";
14
14
  export { registerApi, loginApi } from "./api/api";