eleven-solutions-common-website-unique-web 4.0.31 → 4.0.32

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("");
@@ -193,7 +193,7 @@ const TaxonomyForm = () => {
193
193
  setNewValue(item.value);
194
194
  setIsModalOpen(true);
195
195
  };
196
- const handleAddSubTypeClick = (index, id) => {
196
+ const handleAddSubType = (index, id) => {
197
197
  const item = similarTaxonomies[index];
198
198
  setSelectedTaxonomyId(id);
199
199
  setNewCode(item.code);
@@ -201,6 +201,16 @@ const TaxonomyForm = () => {
201
201
  setIsModalOpen(true);
202
202
  setIsAddingSubType(true);
203
203
  };
204
+ const handleSubTypeClick = () => __awaiter(void 0, void 0, void 0, function* () {
205
+ try {
206
+ yield addSubTypeApi(selectedTaxonomyId, subType, Number(subCode), subValue);
207
+ alert("Taxonomy updated successfully");
208
+ }
209
+ catch (error) {
210
+ console.error("Error updating Taxonomy:", error);
211
+ }
212
+ setIsModalOpen(false);
213
+ });
204
214
  const handleEditTaxClick = () => __awaiter(void 0, void 0, void 0, function* () {
205
215
  try {
206
216
  yield updateTaxonomyApi(selectedTaxonomyId, type, Number(newCode), newValue);
@@ -249,7 +259,7 @@ const TaxonomyForm = () => {
249
259
  !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
260
  handleEditClick(index, taxonomy.id);
251
261
  }, 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
- handleAddSubTypeClick(index, taxonomy.id);
262
+ handleAddSubType(index, taxonomy.id);
253
263
  }, 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
264
  const newTempTaxonomy = [...tempTaxonomy];
255
265
  newTempTaxonomy.splice(index, 1);
@@ -260,6 +270,16 @@ const TaxonomyForm = () => {
260
270
  ? "Add SubType"
261
271
  : editTaxonomyItem || editTempTaxonomyItem
262
272
  ? "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", { onClick: editTaxonomyItem ? handleEditTaxClick : 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: editTaxonomyItem || editTempTaxonomyItem ? "Edit" : "Add" })] })] }) })] }));
273
+ : "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", {
274
+ // onClick={editTaxonomyItem ? handleEditTaxClick : handleAddClick}
275
+ onClick: isAddingSubType
276
+ ? handleSubTypeClick
277
+ : editTaxonomyItem
278
+ ? handleEditTaxClick
279
+ : 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
280
+ ? "Add SubType"
281
+ : editTaxonomyItem || editTempTaxonomyItem
282
+ ? "Edit"
283
+ : "Add" })] })] }) })] }));
264
284
  };
265
285
  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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eleven-solutions-common-website-unique-web",
3
- "version": "4.0.31",
3
+ "version": "4.0.32",
4
4
  "main": "./dist/index.js",
5
5
  "scripts": {
6
6
  "build": "tsc",
@@ -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
 
@@ -238,7 +239,7 @@ const TaxonomyForm = () => {
238
239
  setIsModalOpen(true);
239
240
  };
240
241
 
241
- const handleAddSubTypeClick = (index: number, id: string) => {
242
+ const handleAddSubType = (index: number, id: string) => {
242
243
  const item = similarTaxonomies[index];
243
244
  setSelectedTaxonomyId(id);
244
245
 
@@ -248,6 +249,21 @@ const TaxonomyForm = () => {
248
249
  setIsAddingSubType(true);
249
250
  };
250
251
 
252
+ const handleSubTypeClick = async () => {
253
+ try {
254
+ await addSubTypeApi(
255
+ selectedTaxonomyId,
256
+ subType,
257
+ Number(subCode),
258
+ subValue
259
+ );
260
+ alert("Taxonomy updated successfully");
261
+ } catch (error) {
262
+ console.error("Error updating Taxonomy:", error);
263
+ }
264
+ setIsModalOpen(false);
265
+ };
266
+
251
267
  const handleEditTaxClick = async () => {
252
268
  try {
253
269
  await updateTaxonomyApi(
@@ -497,7 +513,7 @@ const TaxonomyForm = () => {
497
513
  <button
498
514
  type="button"
499
515
  onClick={() => {
500
- handleAddSubTypeClick(index, taxonomy.id);
516
+ handleAddSubType(index, taxonomy.id);
501
517
  }}
502
518
  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
519
  >
@@ -788,10 +804,22 @@ const TaxonomyForm = () => {
788
804
  Cancel
789
805
  </button>
790
806
  <button
791
- onClick={editTaxonomyItem ? handleEditTaxClick : handleAddClick}
807
+ // onClick={editTaxonomyItem ? handleEditTaxClick : handleAddClick}
808
+ onClick={
809
+ isAddingSubType
810
+ ? handleSubTypeClick
811
+ : editTaxonomyItem
812
+ ? handleEditTaxClick
813
+ : handleAddClick
814
+ }
792
815
  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
816
  >
794
- {editTaxonomyItem || editTempTaxonomyItem ? "Edit" : "Add"}
817
+ {/* {editTaxonomyItem || editTempTaxonomyItem ? "Edit" : "Add"} */}
818
+ {isAddingSubType
819
+ ? "Add SubType"
820
+ : editTaxonomyItem || editTempTaxonomyItem
821
+ ? "Edit"
822
+ : "Add"}
795
823
  </button>
796
824
  </div>
797
825
  </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
+ };