eleven-solutions-common-website-unique-web 4.0.31 → 4.0.33
Sign up to get free protection for your applications and to get access to all the features.
@@ -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, Fragment as _Fragment } from "react/jsx-runtime";
|
11
11
|
import { useState, useEffect } from "react";
|
12
|
-
import { addTaxonomyApi, fetchTaxonomyByIdApi, updateTaxonomyApi, fetchTaxonomiessApi, addMultipleTaxonomiesApi, deleteTaxonomyApi, isMultipleApi, } from "../api/taxonomy";
|
12
|
+
import { addTaxonomyApi, fetchTaxonomyByIdApi, updateTaxonomyApi, fetchTaxonomiessApi, addMultipleTaxonomiesApi, deleteTaxonomyApi, isMultipleApi, addSubTypeApi, } from "../api/taxonomy";
|
13
13
|
import { FaPlus } from "react-icons/fa";
|
14
14
|
const TaxonomyForm = () => {
|
15
15
|
const [type, setType] = useState("");
|
@@ -161,6 +161,7 @@ const TaxonomyForm = () => {
|
|
161
161
|
setSubValue("");
|
162
162
|
};
|
163
163
|
const handleAddClick = () => {
|
164
|
+
setIsAddingSubType(false);
|
164
165
|
if (newCode === "" || newValue === "") {
|
165
166
|
alert("Please fill in all required fields: Code, and Value.");
|
166
167
|
return;
|
@@ -193,7 +194,7 @@ const TaxonomyForm = () => {
|
|
193
194
|
setNewValue(item.value);
|
194
195
|
setIsModalOpen(true);
|
195
196
|
};
|
196
|
-
const
|
197
|
+
const handleAddSubType = (index, id) => {
|
197
198
|
const item = similarTaxonomies[index];
|
198
199
|
setSelectedTaxonomyId(id);
|
199
200
|
setNewCode(item.code);
|
@@ -201,7 +202,18 @@ const TaxonomyForm = () => {
|
|
201
202
|
setIsModalOpen(true);
|
202
203
|
setIsAddingSubType(true);
|
203
204
|
};
|
205
|
+
const handleSubTypeClick = () => __awaiter(void 0, void 0, void 0, function* () {
|
206
|
+
try {
|
207
|
+
yield addSubTypeApi(selectedTaxonomyId, subType, Number(subCode), subValue);
|
208
|
+
alert("Taxonomy updated successfully");
|
209
|
+
}
|
210
|
+
catch (error) {
|
211
|
+
console.error("Error updating Taxonomy:", error);
|
212
|
+
}
|
213
|
+
setIsModalOpen(false);
|
214
|
+
});
|
204
215
|
const handleEditTaxClick = () => __awaiter(void 0, void 0, void 0, function* () {
|
216
|
+
setIsAddingSubType(false);
|
205
217
|
try {
|
206
218
|
yield updateTaxonomyApi(selectedTaxonomyId, type, Number(newCode), newValue);
|
207
219
|
alert("Taxonomy updated successfully");
|
@@ -249,7 +261,7 @@ const TaxonomyForm = () => {
|
|
249
261
|
!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: () => {
|
250
262
|
handleEditClick(index, taxonomy.id);
|
251
263
|
}, 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", "stroke-width": "1.5", stroke: "currentColor", className: "w-5 h-5", children: _jsx("path", { "stroke-linecap": "round", "stroke-linejoin": "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: () => {
|
252
|
-
|
264
|
+
handleAddSubType(index, taxonomy.id);
|
253
265
|
}, 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", "stroke-width": "1.5", stroke: "currentColor", className: "w-5 h-5", children: _jsx("path", { "stroke-linecap": "round", "stroke-linejoin": "round", d: "M12 4.5v15m7.5-7.5h-15" }) }) })] }) })), _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: taxonomy.value })] }, index))) })] }) }), similarTaxonomies.some((taxonomy) => taxonomy.isEdit) && (_jsx("div", { className: "flex space-x-4 mt-6 justify-start", children: _jsxs("button", { type: "button", onClick: handleOpenModal, 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" }), "Add Multiple Values"] }) }))] })), isEditMode && (_jsx(_Fragment, { children: tempTaxonomy.length > 0 && (_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", children: "Edit/Delete" }), _jsx("th", { scope: "col", className: "px-4 py-3.5 text-md font-normal text-left text-gray-500 dark:text-gray-400", children: "Code" }), _jsx("th", { scope: "col", className: "px-4 py-3.5 text-md font-normal text-left text-gray-500 dark:text-gray-400", children: "Value" })] }) }), _jsx("tbody", { className: "bg-white divide-y divide-gray-200 dark:bg-gray-800 dark:divide-gray-700", children: [...tempTaxonomy].map((item, index) => (_jsxs("tr", { children: [_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: () => {
|
254
266
|
const newTempTaxonomy = [...tempTaxonomy];
|
255
267
|
newTempTaxonomy.splice(index, 1);
|
@@ -260,6 +272,16 @@ const TaxonomyForm = () => {
|
|
260
272
|
? "Add SubType"
|
261
273
|
: editTaxonomyItem || editTempTaxonomyItem
|
262
274
|
? "Edit Values"
|
263
|
-
: "Add Values" }), _jsx("button", { onClick: handleCloseModal, className: "text-xl text-gray-600 dark:text-gray-400 h-6 w-6", children: "\u00D7" })] }), isAddingSubType ? (_jsxs(_Fragment, { children: [_jsx("label", { className: "text-gray-900 dark:text-gray-200 font-semibold", children: "Type" }), _jsx("input", { type: "text", value: subType, onChange: (e) => setSubType(e.target.value), placeholder: "Enter Type", className: "w-full px-4 py-2 mt-2 mb-4 border border-gray-300 rounded-md" }), _jsx("label", { className: "text-gray-900 dark:text-gray-200 font-semibold", children: "Code" }), _jsx("input", { type: "number", value: subCode, onChange: (e) => setSubCode(e.target.value), placeholder: "Enter Code", className: "w-full px-4 py-2 mt-2 mb-4 border border-gray-300 rounded-md" }), _jsx("label", { className: "text-gray-900 dark:text-gray-200 font-semibold", children: "Value" }), _jsx("input", { type: "text", value: subValue, onChange: (e) => setSubValue(e.target.value), placeholder: "Enter Value", className: "w-full px-4 py-2 mt-2 mb-4 border border-gray-300 rounded-md" })] })) : (_jsxs(_Fragment, { children: [_jsx("label", { className: "text-gray-900 dark:text-gray-200 font-semibold", children: "Code" }), _jsx("input", { type: "number", value: newCode, onChange: (e) => setNewCode(e.target.value), placeholder: "Enter Code", className: "w-full px-4 py-2 mt-2 mb-4 border border-gray-300 rounded-md" }), _jsx("label", { className: "text-gray-900 dark:text-gray-200 font-semibold", children: "Value" }), _jsx("input", { type: "text", value: newValue, onChange: (e) => setNewValue(e.target.value), placeholder: "Enter Value", className: "w-full px-4 py-2 mt-2 mb-4 border border-gray-300 rounded-md" })] })), _jsxs("div", { className: "flex space-x-4 justify-end", children: [_jsx("button", { onClick: handleCloseModal, className: "px-8 py-2.5 leading-5 bg-gray-300 rounded-md", children: "Cancel" }), _jsx("button", {
|
275
|
+
: "Add Values" }), _jsx("button", { onClick: handleCloseModal, className: "text-xl text-gray-600 dark:text-gray-400 h-6 w-6", children: "\u00D7" })] }), isAddingSubType ? (_jsxs(_Fragment, { children: [_jsx("label", { className: "text-gray-900 dark:text-gray-200 font-semibold", children: "Type" }), _jsx("input", { type: "text", value: subType, onChange: (e) => setSubType(e.target.value), placeholder: "Enter Type", className: "w-full px-4 py-2 mt-2 mb-4 border border-gray-300 rounded-md" }), _jsx("label", { className: "text-gray-900 dark:text-gray-200 font-semibold", children: "Code" }), _jsx("input", { type: "number", value: subCode, onChange: (e) => setSubCode(e.target.value), placeholder: "Enter Code", className: "w-full px-4 py-2 mt-2 mb-4 border border-gray-300 rounded-md" }), _jsx("label", { className: "text-gray-900 dark:text-gray-200 font-semibold", children: "Value" }), _jsx("input", { type: "text", value: subValue, onChange: (e) => setSubValue(e.target.value), placeholder: "Enter Value", className: "w-full px-4 py-2 mt-2 mb-4 border border-gray-300 rounded-md" })] })) : (_jsxs(_Fragment, { children: [_jsx("label", { className: "text-gray-900 dark:text-gray-200 font-semibold", children: "Code" }), _jsx("input", { type: "number", value: newCode, onChange: (e) => setNewCode(e.target.value), placeholder: "Enter Code", className: "w-full px-4 py-2 mt-2 mb-4 border border-gray-300 rounded-md" }), _jsx("label", { className: "text-gray-900 dark:text-gray-200 font-semibold", children: "Value" }), _jsx("input", { type: "text", value: newValue, onChange: (e) => setNewValue(e.target.value), placeholder: "Enter Value", className: "w-full px-4 py-2 mt-2 mb-4 border border-gray-300 rounded-md" })] })), _jsxs("div", { className: "flex space-x-4 justify-end", children: [_jsx("button", { onClick: handleCloseModal, className: "px-8 py-2.5 leading-5 bg-gray-300 rounded-md", children: "Cancel" }), _jsx("button", {
|
276
|
+
// onClick={editTaxonomyItem ? handleEditTaxClick : handleAddClick}
|
277
|
+
onClick: isAddingSubType
|
278
|
+
? handleSubTypeClick
|
279
|
+
: editTaxonomyItem
|
280
|
+
? handleEditTaxClick
|
281
|
+
: 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: isAddingSubType
|
282
|
+
? "Add SubType"
|
283
|
+
: editTaxonomyItem || editTempTaxonomyItem
|
284
|
+
? "Edit"
|
285
|
+
: "Add" })] })] }) })] }));
|
264
286
|
};
|
265
287
|
export default TaxonomyForm;
|
@@ -11,3 +11,4 @@ export declare const addMultipleTaxonomiesApi: (taxonomies: {
|
|
11
11
|
value: string;
|
12
12
|
}[]) => Promise<Axios.AxiosXHR<unknown>>;
|
13
13
|
export declare const isMultipleApi: (type: string) => Promise<unknown>;
|
14
|
+
export declare const addSubTypeApi: (parentid: string, type: string, code: number, value: string) => Promise<Axios.AxiosXHR<unknown>>;
|
@@ -133,3 +133,23 @@ export const isMultipleApi = (type) => __awaiter(void 0, void 0, void 0, functio
|
|
133
133
|
throw error;
|
134
134
|
}
|
135
135
|
});
|
136
|
+
export const addSubTypeApi = (parentid, type, code, value) => __awaiter(void 0, void 0, void 0, function* () {
|
137
|
+
const token = cookies.get("token");
|
138
|
+
try {
|
139
|
+
const response = yield axios.post(`${apiUrl}/taxonomy/add`, {
|
140
|
+
ParentId: parentid,
|
141
|
+
Type: type,
|
142
|
+
Code: code,
|
143
|
+
Value: value,
|
144
|
+
}, {
|
145
|
+
headers: {
|
146
|
+
Authorization: `Bearer ${token}`,
|
147
|
+
},
|
148
|
+
});
|
149
|
+
return response;
|
150
|
+
}
|
151
|
+
catch (error) {
|
152
|
+
console.error(error);
|
153
|
+
throw error;
|
154
|
+
}
|
155
|
+
});
|
package/package.json
CHANGED
@@ -8,6 +8,7 @@ import {
|
|
8
8
|
addMultipleTaxonomiesApi,
|
9
9
|
deleteTaxonomyApi,
|
10
10
|
isMultipleApi,
|
11
|
+
addSubTypeApi,
|
11
12
|
} from "../api/taxonomy";
|
12
13
|
import { FaPlus } from "react-icons/fa";
|
13
14
|
|
@@ -198,6 +199,7 @@ const TaxonomyForm = () => {
|
|
198
199
|
};
|
199
200
|
|
200
201
|
const handleAddClick = () => {
|
202
|
+
setIsAddingSubType(false);
|
201
203
|
if (newCode === "" || newValue === "") {
|
202
204
|
alert("Please fill in all required fields: Code, and Value.");
|
203
205
|
return;
|
@@ -238,7 +240,7 @@ const TaxonomyForm = () => {
|
|
238
240
|
setIsModalOpen(true);
|
239
241
|
};
|
240
242
|
|
241
|
-
const
|
243
|
+
const handleAddSubType = (index: number, id: string) => {
|
242
244
|
const item = similarTaxonomies[index];
|
243
245
|
setSelectedTaxonomyId(id);
|
244
246
|
|
@@ -248,7 +250,23 @@ const TaxonomyForm = () => {
|
|
248
250
|
setIsAddingSubType(true);
|
249
251
|
};
|
250
252
|
|
253
|
+
const handleSubTypeClick = async () => {
|
254
|
+
try {
|
255
|
+
await addSubTypeApi(
|
256
|
+
selectedTaxonomyId,
|
257
|
+
subType,
|
258
|
+
Number(subCode),
|
259
|
+
subValue
|
260
|
+
);
|
261
|
+
alert("Taxonomy updated successfully");
|
262
|
+
} catch (error) {
|
263
|
+
console.error("Error updating Taxonomy:", error);
|
264
|
+
}
|
265
|
+
setIsModalOpen(false);
|
266
|
+
};
|
267
|
+
|
251
268
|
const handleEditTaxClick = async () => {
|
269
|
+
setIsAddingSubType(false);
|
252
270
|
try {
|
253
271
|
await updateTaxonomyApi(
|
254
272
|
selectedTaxonomyId,
|
@@ -497,7 +515,7 @@ const TaxonomyForm = () => {
|
|
497
515
|
<button
|
498
516
|
type="button"
|
499
517
|
onClick={() => {
|
500
|
-
|
518
|
+
handleAddSubType(index, taxonomy.id);
|
501
519
|
}}
|
502
520
|
className="text-gray-500 transition-colors duration-200 dark:hover:text-blue-500 dark:text-gray-300 hover:text-blue-500 focus:outline-none"
|
503
521
|
>
|
@@ -788,10 +806,22 @@ const TaxonomyForm = () => {
|
|
788
806
|
Cancel
|
789
807
|
</button>
|
790
808
|
<button
|
791
|
-
onClick={editTaxonomyItem ? handleEditTaxClick : handleAddClick}
|
809
|
+
// onClick={editTaxonomyItem ? handleEditTaxClick : handleAddClick}
|
810
|
+
onClick={
|
811
|
+
isAddingSubType
|
812
|
+
? handleSubTypeClick
|
813
|
+
: editTaxonomyItem
|
814
|
+
? handleEditTaxClick
|
815
|
+
: handleAddClick
|
816
|
+
}
|
792
817
|
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"
|
793
818
|
>
|
794
|
-
{editTaxonomyItem || editTempTaxonomyItem ? "Edit" : "Add"}
|
819
|
+
{/* {editTaxonomyItem || editTempTaxonomyItem ? "Edit" : "Add"} */}
|
820
|
+
{isAddingSubType
|
821
|
+
? "Add SubType"
|
822
|
+
: editTaxonomyItem || editTempTaxonomyItem
|
823
|
+
? "Edit"
|
824
|
+
: "Add"}
|
795
825
|
</button>
|
796
826
|
</div>
|
797
827
|
</div>
|
@@ -164,3 +164,34 @@ export const isMultipleApi = async (type: string) => {
|
|
164
164
|
throw error;
|
165
165
|
}
|
166
166
|
};
|
167
|
+
|
168
|
+
export const addSubTypeApi = async (
|
169
|
+
parentid: string,
|
170
|
+
type: string,
|
171
|
+
code: number,
|
172
|
+
value: string
|
173
|
+
) => {
|
174
|
+
const token = cookies.get("token");
|
175
|
+
|
176
|
+
try {
|
177
|
+
const response = await axios.post(
|
178
|
+
`${apiUrl}/taxonomy/add`,
|
179
|
+
{
|
180
|
+
ParentId: parentid,
|
181
|
+
Type: type,
|
182
|
+
Code: code,
|
183
|
+
Value: value,
|
184
|
+
},
|
185
|
+
{
|
186
|
+
headers: {
|
187
|
+
Authorization: `Bearer ${token}`,
|
188
|
+
},
|
189
|
+
}
|
190
|
+
);
|
191
|
+
return response;
|
192
|
+
} catch (error) {
|
193
|
+
console.error(error);
|
194
|
+
|
195
|
+
throw error;
|
196
|
+
}
|
197
|
+
};
|