eleven-solutions-common-website-unique-web 22.0.1 → 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
|
@@ -102,9 +102,15 @@ const Users = ({ url }) => {
|
|
102
102
|
day: "2-digit",
|
103
103
|
month: "2-digit",
|
104
104
|
year: "numeric",
|
105
|
-
}) })] }, user.id || index))) })] }) }), _jsx("div", { className: "flex-grow ml-0 mt-4 w-0", children: _jsxs("button", { type: "button", onClick: (event) => handleNavigation(event, "/admin/users/userform"), className: "flex items-center justify-center px-6 py-2 font-medium tracking-wide text-white capitalize transition-colors duration-300 transform bg-blue-600 rounded-lg hover:bg-blue-500 focus:outline-none focus:ring focus:ring-blue-300 focus:ring-opacity-80", children: [_jsx(FaPlus, { className: "mr-2 font-medium" }), "User"] }) }), _jsxs("div", { className: "flex items-center justify-between mt-6
|
106
|
-
|
107
|
-
|
105
|
+
}) })] }, user.id || index))) })] }) }), _jsx("div", { className: "flex-grow ml-0 mt-4 w-0", children: _jsxs("button", { type: "button", onClick: (event) => handleNavigation(event, "/admin/users/userform"), className: "flex items-center justify-center px-6 py-2 font-medium tracking-wide text-white capitalize transition-colors duration-300 transform bg-blue-600 rounded-lg hover:bg-blue-500 focus:outline-none focus:ring focus:ring-blue-300 focus:ring-opacity-80", children: [_jsx(FaPlus, { className: "mr-2 font-medium" }), "User"] }) }), _jsxs("div", { className: "flex items-center justify-between mt-6", children: [_jsxs("button", { disabled: currentPage === 1, onClick: () => setCurrentPage((prev) => Math.max(prev - 1, 1)), className: "flex items-center px-5 py-2 text-sm text-gray-700 capitalize transition-colors duration-200 bg-white border rounded-md gap-x-2 hover:bg-gray-100 dark:bg-gray-900 dark:text-gray-200 dark:border-gray-700 dark:hover:bg-gray-800", 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 rtl:-scale-x-100", children: _jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M6.75 15.75L3 12m0 0l3.75-3.75M3 12h18" }) }), _jsx("span", { children: "Previous" })] }), _jsx("div", { className: "items-center hidden lg:flex gap-x-3", children: Array.from({ length: Math.min(10, totalPages) }, (_, index) => {
|
106
|
+
const startPage = Math.max(1, currentPage - 5);
|
107
|
+
const page = startPage + index;
|
108
|
+
if (page > totalPages)
|
109
|
+
return null;
|
110
|
+
return (_jsx("button", { onClick: () => setCurrentPage(page), className: `px-2 py-1 text-sm ${currentPage === page
|
111
|
+
? "text-blue-500 bg-blue-100"
|
112
|
+
: "text-gray-500 hover:bg-gray-100"} rounded-md`, children: page }, page));
|
113
|
+
}) }), _jsxs("button", { onClick: () => setCurrentPage((prev) => Math.min(prev + 1, totalPages)), disabled: currentPage === totalPages, className: "flex items-center px-5 py-2 text-sm text-gray-700 capitalize transition-colors duration-200 bg-white border rounded-md gap-x-2 hover:bg-gray-100 dark:bg-gray-900 dark:text-gray-200 dark:border-gray-700 dark:hover:bg-gray-800", children: [_jsx("span", { children: "Next" }), _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 rtl:-scale-x-100", children: _jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M17.25 8.25L21 12m0 0l-3.75 3.75M21 12H3" }) })] })] })] }), _jsx("div", { className: "inset-0 bg-gray-800 bg-opacity-50 z-50 transition-opacity duration-300", children: _jsxs("div", { className: `fixed top-0 right-0 h-full w-[300px] bg-white p-4 rounded-md shadow-lg transform transition-transform duration-500 ease-in-out
|
108
114
|
${filterModal ? "translate-x-0" : "translate-x-full"}`, children: [_jsx("h1", { className: "text-2xl md:text-3xl font-bold text-blue-600 mb-4 md:mb-6", children: "Filter" }), _jsx("button", { onClick: () => setFilterModal(false), className: "absolute top-1 right-3 text-gray-400 hover:text-gray-600 text-2xl", children: "\u00D7" }), _jsxs("div", { className: "flex flex-col", children: [_jsxs("div", { className: "mb-4 flex flex-col", children: [_jsx("label", { className: "block text-gray-700 mb-2", children: "Role Type" }), _jsx("div", { className: "w-full", children: _jsxs("select", { value: Number(selectedRoleType), onChange: handleRoleTypeChange, required: true, className: "w-full px-4 py-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", children: [_jsx("option", { value: "", children: "All" }), _jsx("option", { value: "1", children: "Guest" }), _jsx("option", { value: "2", children: "Admin" })] }) })] }), _jsx("div", { className: "flex flex-row gap-3", children: _jsx("button", { onClick: resetFilter, className: "mt-2 px-4 py-2 bg-blue-500 text-white rounded-md w-32", children: "Reset" }) })] })] }) })] }));
|
109
115
|
};
|
110
116
|
export default Users;
|