eleven-solutions-common-website-unique-web 22.0.2 → 22.0.3
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.
@@ -12,6 +12,7 @@ import React from "react";
|
|
12
12
|
import { useState, useEffect } from "react";
|
13
13
|
import { addTaxonomyApi, fetchTaxonomyByIdApi, updateTaxonomyApi, fetchTaxonomiessApi, deleteTaxonomyApi, addSubTypeApi, } from "../api/taxonomy";
|
14
14
|
import { FaPlus } from "react-icons/fa";
|
15
|
+
import toast from "react-hot-toast";
|
15
16
|
const TaxonomyForm = ({ url }) => {
|
16
17
|
const [type, setType] = useState("");
|
17
18
|
const [code, setCode] = useState("");
|
@@ -51,7 +52,7 @@ const TaxonomyForm = ({ url }) => {
|
|
51
52
|
const handleDeleteSubTypeClick = (id) => __awaiter(void 0, void 0, void 0, function* () {
|
52
53
|
try {
|
53
54
|
yield deleteTaxonomyApi(url, id);
|
54
|
-
|
55
|
+
toast.success("Taxonomy deleted successfully");
|
55
56
|
const fetchedTaxonomies = yield fetchTaxonomiessApi(url);
|
56
57
|
if (fetchedTaxonomies && Array.isArray(fetchedTaxonomies)) {
|
57
58
|
setAllTaxonomies(fetchedTaxonomies);
|
@@ -59,7 +60,7 @@ const TaxonomyForm = ({ url }) => {
|
|
59
60
|
}
|
60
61
|
catch (error) {
|
61
62
|
console.error("Error deleting Taxonomy:", error);
|
62
|
-
|
63
|
+
toast.error("Error deleting Taxonomy: " + error.message);
|
63
64
|
}
|
64
65
|
});
|
65
66
|
const [editTaxonomyItem, setEditTaxonomyItem] = useState(null);
|
@@ -152,17 +153,17 @@ const TaxonomyForm = ({ url }) => {
|
|
152
153
|
const handleSubTypeSubmitClick = () => __awaiter(void 0, void 0, void 0, function* () {
|
153
154
|
var _a, _b;
|
154
155
|
if (!subCode || !subValue) {
|
155
|
-
|
156
|
+
toast.error("Please fill out both Code and Value fields before proceeding.");
|
156
157
|
return;
|
157
158
|
}
|
158
159
|
try {
|
159
160
|
if (editTaxonomyItem) {
|
160
161
|
yield updateTaxonomyApi(url, selectedTaxonomyId, type, Number(subCode), subValue);
|
161
|
-
|
162
|
+
toast.success("SubType edited successfully");
|
162
163
|
}
|
163
164
|
else {
|
164
165
|
yield addSubTypeApi(url, selectedTaxonomyId, type, Number(subCode), subValue);
|
165
|
-
|
166
|
+
toast.success("SubType added successfully");
|
166
167
|
}
|
167
168
|
const fetchedTaxonomies = yield fetchTaxonomiessApi(url);
|
168
169
|
if (fetchedTaxonomies && Array.isArray(fetchedTaxonomies)) {
|
@@ -172,7 +173,7 @@ const TaxonomyForm = ({ url }) => {
|
|
172
173
|
catch (error) {
|
173
174
|
console.error(`Error ${editTaxonomyItem ? "editing" : "adding"} SubType:`, error);
|
174
175
|
const errorMessage = ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) || ((_b = error.response) === null || _b === void 0 ? void 0 : _b.statusText) || error.message;
|
175
|
-
|
176
|
+
toast.error(`Error while ${editTaxonomyItem ? "editing" : "adding"} SubType: ${errorMessage}`);
|
176
177
|
setNewCode("");
|
177
178
|
setNewValue("");
|
178
179
|
}
|
@@ -191,17 +192,17 @@ const TaxonomyForm = ({ url }) => {
|
|
191
192
|
const handleSubmitClick = () => __awaiter(void 0, void 0, void 0, function* () {
|
192
193
|
var _a, _b;
|
193
194
|
if (!newCode || !newValue) {
|
194
|
-
|
195
|
+
toast.error("Please fill out both Code and Value fields before submitting.");
|
195
196
|
return;
|
196
197
|
}
|
197
198
|
try {
|
198
199
|
if (editTaxonomyItem) {
|
199
200
|
yield updateTaxonomyApi(url, selectedTaxonomyId, type, Number(newCode), newValue);
|
200
|
-
|
201
|
+
toast.success("Taxonomy updated successfully");
|
201
202
|
}
|
202
203
|
else {
|
203
204
|
yield addTaxonomyApi(url, type, Number(newCode), newValue);
|
204
|
-
|
205
|
+
toast.success("Value added successfully");
|
205
206
|
}
|
206
207
|
const response = yield fetchTaxonomiessApi(url);
|
207
208
|
const filteredTaxonomies = response.filter((taxonomy) => taxonomy.type === type);
|
@@ -210,7 +211,7 @@ const TaxonomyForm = ({ url }) => {
|
|
210
211
|
catch (error) {
|
211
212
|
console.error(editTaxonomyItem ? "Error updating Taxonomy:" : "Error adding value:", error);
|
212
213
|
const errorMessage = ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) || ((_b = error.response) === null || _b === void 0 ? void 0 : _b.statusText) || error.message;
|
213
|
-
|
214
|
+
toast.error(`Error while ${editTaxonomyItem ? "editing" : "adding"} SubType: ${errorMessage}`);
|
214
215
|
setNewCode("");
|
215
216
|
setNewValue("");
|
216
217
|
}
|
@@ -221,7 +222,7 @@ const TaxonomyForm = ({ url }) => {
|
|
221
222
|
const handleDeleteClick = (id) => __awaiter(void 0, void 0, void 0, function* () {
|
222
223
|
try {
|
223
224
|
yield deleteTaxonomyApi(url, id);
|
224
|
-
|
225
|
+
toast.success("Taxonomy deleted successfully");
|
225
226
|
setSimilarTaxonomies((prevTaxonomies) => prevTaxonomies.filter((taxonomy) => taxonomy.id !== id));
|
226
227
|
}
|
227
228
|
catch (error) {
|
@@ -229,7 +230,7 @@ const TaxonomyForm = ({ url }) => {
|
|
229
230
|
}
|
230
231
|
});
|
231
232
|
const parentTaxonomies = similarTaxonomies.filter((taxonomy) => !taxonomy.parentId);
|
232
|
-
return (_jsxs("div", { className: `${isEditMode ? "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-
|
233
|
+
return (_jsxs("div", { className: `${isEditMode ? "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-blue-600 capitalize dark:text-white mb-4", children: isEditMode ? "Edit Taxonomy" : "Add Taxonomy" }), _jsx("h4", { className: "text-gray-900 dark:text-gray-200 font-semibold", children: isEditMode ? `Taxonomy Type: ${type}` : "" }), isSimilarTaxonomyOpen && 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: [_jsx("th", { scope: "col", className: "px-4 py-3.5 text-md font-normal text-left rtl:text-right text-gray-500 dark:text-gray-400", style: { width: "200px" }, 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: parentTaxonomies.map((taxonomy, index) => {
|
233
234
|
const hasChildren = allTaxonomies.some((item) => item.parentId === taxonomy.id);
|
234
235
|
return (_jsxs(React.Fragment, { children: [_jsxs("tr", { children: [_jsx("td", { className: "px-4 py-4 text-sm whitespace-nowrap", children: taxonomy.isEdit && (_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", strokeWidth: "1.5", stroke: "currentColor", className: "w-5 h-5", children: _jsx("path", { strokeLinecap: "round", strokeLinejoin: "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: () => handleEditClick(index, taxonomy.id), className: "text-gray-500 transition-colors duration-200 dark:hover:text-yellow-500 dark:text-gray-300 hover:text-yellow-500 focus:outline-none", children: _jsx("svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", strokeWidth: "1.5", stroke: "currentColor", className: "w-5 h-5", children: _jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M16.862 4.487l1.687-1.688a1.875 1.875 0 112.652 2.652L10.582 16.07a4.5 4.5 0 01-1.897 1.13L6 18l.8-2.685a4.5 4.5 0 011.13-1.897l8.932-8.931zm0 0L19.5 7.125M18 14v4.75A2.25 2.25 0 0115.75 21H5.25A2.25 2.25 0 013 18.75V8.25A2.25 2.25 0 015.25 6H10" }) }) }), _jsx("button", { type: "button", onClick: () => handleAddSubType(index, taxonomy.id), className: "text-gray-500 transition-colors duration-200 dark:hover:text-blue-500 dark:text-gray-300 hover:text-blue-500 focus:outline-none", children: _jsx("svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", strokeWidth: "1.5", stroke: "currentColor", className: "w-5 h-5", children: _jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M12 4.5v15m7.5-7.5h-15" }) }) }), hasChildren && (_jsx("button", { type: "button", onClick: () => toggleRowExpansion(taxonomy.id), className: "text-gray-500 transition-colors duration-200 dark:hover:text-blue-600 dark:text-gray-300 hover:text-blue-500 focus:outline-none", children: expandedRows.indexOf(taxonomy.id) !==
|
235
236
|
-1 ? (_jsx("svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", strokeWidth: "1.5", stroke: "currentColor", className: "w-5 h-5", children: _jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M19.5 15.75l-7.5-7.5-7.5 7.5" }) })) : (_jsx("svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", strokeWidth: "1.5", stroke: "currentColor", className: "w-5 h-5", children: _jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M19.5 8.25l-7.5 7.5-7.5-7.5" }) })) }))] })) }), _jsx("td", { className: "px-4 py-4 text-sm text-gray-500 dark:text-gray-400", children: taxonomy.code }), _jsx("td", { className: "px-4 py-4 text-sm font-medium text-gray-900 dark:text-white", children: _jsx("div", { className: "flex justify-between items-center", children: _jsx("span", { children: taxonomy.value }) }) })] }, index), expandedRows.indexOf(taxonomy.id) !== -1 && (_jsx("tr", { children: _jsx("td", { colSpan: 3, children: _jsxs("table", { className: "min-w-full divide-y ", children: [_jsx("thead", { className: "bg-gray-50 dark:bg-gray-800", children: _jsxs("tr", { children: [similarTaxonomies.some((taxonomy) => taxonomy.isEdit) && (_jsx("th", { scope: "col", className: "px-4 py-3.5 text-md font-normal text-left rtl:text-right text-gray-500 dark:text-gray-400", style: { width: "200px" }, children: "Actions" })), _jsx("th", { scope: "col", style: { width: "350px" }, className: "px-4 py-3.5 text-md font-normal text-left rtl:text-right text-gray-500 dark:text-gray-400 w-[23%]", 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", { children: allTaxonomies
|