eleven-solutions-common-website-unique-web 6.0.11 → 6.0.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,6 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
11
+ import React from "react";
11
12
  import { useState, useEffect } from "react";
12
13
  import { addTaxonomyApi, fetchTaxonomyByIdApi, updateTaxonomyApi, fetchTaxonomiessApi, addMultipleTaxonomiesApi, deleteTaxonomyApi, isMultipleApi, addSubTypeApi, } from "../api/taxonomy";
13
14
  import { FaPlus } from "react-icons/fa";
@@ -27,6 +28,42 @@ const TaxonomyForm = () => {
27
28
  const [tempTaxonomy, setTempTaxonomy] = useState([]);
28
29
  const [similarTaxonomies, setSimilarTaxonomies] = useState([]);
29
30
  const [isSimilarTaxonomyOpen, setIsSimilarTaxonomyOpen] = useState(true);
31
+ //for child taxonomies
32
+ // nested table
33
+ const [allTaxonomies, setAllTaxonomies] = useState([]);
34
+ const [expandedRows, setExpandedRows] = useState([]);
35
+ useEffect(() => {
36
+ const fetchAllTaxonomies = () => __awaiter(void 0, void 0, void 0, function* () {
37
+ try {
38
+ const fetchedTaxonomies = yield fetchTaxonomiessApi();
39
+ if (fetchedTaxonomies && Array.isArray(fetchedTaxonomies)) {
40
+ setAllTaxonomies(fetchedTaxonomies);
41
+ }
42
+ }
43
+ catch (error) {
44
+ console.error("Unable to fetch all taxonomies", error);
45
+ }
46
+ });
47
+ fetchAllTaxonomies();
48
+ }, []);
49
+ // const toggleRowExpansion = (taxonomyId: number) => {
50
+ // setExpandedRows(
51
+ // (prevExpandedRows) =>
52
+ // prevExpandedRows.includes(taxonomyId)
53
+ // ? prevExpandedRows.filter((id) => id !== taxonomyId) // Collapse row
54
+ // : [...prevExpandedRows, taxonomyId] // Expand row
55
+ // );
56
+ // };
57
+ const toggleRowExpansion = (taxonomyId) => {
58
+ setExpandedRows((prevExpandedRows) => prevExpandedRows.indexOf(taxonomyId) !== -1
59
+ ? prevExpandedRows.filter((id) => id !== taxonomyId) // Collapse row
60
+ : [...prevExpandedRows, taxonomyId] // Expand row
61
+ );
62
+ };
63
+ // Fetch child taxonomies for a parentId
64
+ const getChildTaxonomies = (parentId) => {
65
+ return allTaxonomies.filter((taxonomy) => taxonomy.parentId === parentId);
66
+ };
30
67
  const [editTaxonomyItem, setEditTaxonomyItem] = useState(null);
31
68
  const [editTempTaxonomyItem, setEditTempTaxonomyItem] = useState(null);
32
69
  const [selectedTaxonomyId, setSelectedTaxonomyId] = useState("");
@@ -258,9 +295,11 @@ const TaxonomyForm = () => {
258
295
  handleDeleteClick(id);
259
296
  window.location.href = "/admin/taxinomies";
260
297
  }, 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) &&
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) => {
262
- const isParent = similarTaxonomies.some((t) => t.parentId === taxonomy.id);
263
- return (_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", 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" }) }) })] }) })), _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: _jsxs("div", { className: "flex justify-between items-center", children: [_jsx("span", { children: taxonomy.value }), isParent && (_jsx("button", { type: "button", 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: _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" }) }) }))] }) })] }, index));
298
+ !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) => {
299
+ const hasChildren = allTaxonomies.some((item) => item.parentId === taxonomy.id);
300
+ return (_jsxs(React.Fragment, { children: [_jsxs("tr", { children: [_jsx("td", { className: "px-4 py-4 text-sm whitespace-nowrap", children: _jsx("div", { className: "flex items-center gap-x-6", children: _jsx("button", { type: "button", onClick: () => console.log("Edit clicked", 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: "Edit" }) }) }), _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: _jsxs("div", { className: "flex justify-between items-center", children: [_jsx("span", { children: taxonomy.value }), 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) !== -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 8.25l-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 15.75l-7.5-7.5-7.5 7.5" }) })) }))] }) })] }), expandedRows.indexOf(taxonomy.id) !== -1 && (_jsx("tr", { children: _jsx("td", { colSpan: 3, className: "bg-gray-100 dark:bg-gray-900", children: _jsxs("table", { className: "min-w-full divide-y divide-gray-200 dark:divide-gray-700", children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { className: "px-4 py-2 text-sm font-normal text-left text-gray-500 dark:text-gray-400", children: "Child Code" }), _jsx("th", { className: "px-4 py-2 text-sm font-normal text-left text-gray-500 dark:text-gray-400", children: "Child Value" })] }) }), _jsx("tbody", { children: allTaxonomies
301
+ .filter((item) => item.parentId === taxonomy.id)
302
+ .map((child) => (_jsxs("tr", { children: [_jsx("td", { className: "px-4 py-2 text-sm text-gray-500 dark:text-gray-400", children: child.type }), _jsx("td", { className: "px-4 py-2 text-sm text-gray-500 dark:text-gray-400", children: child.code }), _jsx("td", { className: "px-4 py-2 text-sm text-gray-900 dark:text-white", children: child.value })] }, child.id))) })] }) }) }))] }, taxonomy.id));
264
303
  }) })] }) }), 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: () => {
265
304
  const newTempTaxonomy = [...tempTaxonomy];
266
305
  newTempTaxonomy.splice(index, 1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eleven-solutions-common-website-unique-web",
3
- "version": "6.0.11",
3
+ "version": "6.0.13",
4
4
  "main": "./dist/index.js",
5
5
  "scripts": {
6
6
  "build": "tsc",
@@ -36,6 +36,49 @@ const TaxonomyForm = () => {
36
36
  const [similarTaxonomies, setSimilarTaxonomies] = useState<any[]>([]);
37
37
  const [isSimilarTaxonomyOpen, setIsSimilarTaxonomyOpen] = useState(true);
38
38
 
39
+ //for child taxonomies
40
+ // nested table
41
+ const [allTaxonomies, setAllTaxonomies] = useState<any[]>([]);
42
+ const [expandedRows, setExpandedRows] = useState<number[]>([]);
43
+
44
+ useEffect(() => {
45
+ const fetchAllTaxonomies = async () => {
46
+ try {
47
+ const fetchedTaxonomies = await fetchTaxonomiessApi();
48
+ if (fetchedTaxonomies && Array.isArray(fetchedTaxonomies)) {
49
+ setAllTaxonomies(fetchedTaxonomies);
50
+ }
51
+ } catch (error) {
52
+ console.error("Unable to fetch all taxonomies", error);
53
+ }
54
+ };
55
+
56
+ fetchAllTaxonomies();
57
+ }, []);
58
+
59
+ // const toggleRowExpansion = (taxonomyId: number) => {
60
+ // setExpandedRows(
61
+ // (prevExpandedRows) =>
62
+ // prevExpandedRows.includes(taxonomyId)
63
+ // ? prevExpandedRows.filter((id) => id !== taxonomyId) // Collapse row
64
+ // : [...prevExpandedRows, taxonomyId] // Expand row
65
+ // );
66
+ // };
67
+
68
+ const toggleRowExpansion = (taxonomyId: number) => {
69
+ setExpandedRows(
70
+ (prevExpandedRows) =>
71
+ prevExpandedRows.indexOf(taxonomyId) !== -1
72
+ ? prevExpandedRows.filter((id) => id !== taxonomyId) // Collapse row
73
+ : [...prevExpandedRows, taxonomyId] // Expand row
74
+ );
75
+ };
76
+
77
+ // Fetch child taxonomies for a parentId
78
+ const getChildTaxonomies = (parentId: number) => {
79
+ return allTaxonomies.filter((taxonomy) => taxonomy.parentId === parentId);
80
+ };
81
+
39
82
  const [editTaxonomyItem, setEditTaxonomyItem] = useState<{
40
83
  id: string;
41
84
  type: string;
@@ -460,121 +503,8 @@ const TaxonomyForm = () => {
460
503
  </th>
461
504
  </tr>
462
505
  </thead>
463
- <tbody className="divide-y divide-gray-200">
464
- {/* {similarTaxonomies.map((taxonomy, index) => (
465
- <tr key={index}>
466
- {similarTaxonomies.some(
467
- (taxonomy) => taxonomy.isEdit
468
- ) && (
469
- <td className="px-4 py-4 text-sm whitespace-nowrap">
470
- <div className="flex items-center gap-x-6">
471
- <button
472
- type="button"
473
- onClick={() => handleDeleteClick(taxonomy.id)}
474
- className="text-gray-500 transition-colors duration-200 dark:hover:text-red-600 dark:text-gray-300 hover:text-red-500 focus:outline-none"
475
- >
476
- <svg
477
- xmlns="http://www.w3.org/2000/svg"
478
- fill="none"
479
- viewBox="0 0 24 24"
480
- stroke-width="1.5"
481
- stroke="currentColor"
482
- className="w-5 h-5"
483
- >
484
- <path
485
- stroke-linecap="round"
486
- stroke-linejoin="round"
487
- 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"
488
- />
489
- </svg>
490
- </button>
491
-
492
- <button
493
- type="button"
494
- onClick={() => {
495
- handleEditClick(index, taxonomy.id);
496
- }}
497
- className="text-gray-500 transition-colors duration-200 dark:hover:text-yellow-500 dark:text-gray-300 hover:text-yellow-500 focus:outline-none"
498
- >
499
- <svg
500
- xmlns="http://www.w3.org/2000/svg"
501
- fill="none"
502
- viewBox="0 0 24 24"
503
- stroke-width="1.5"
504
- stroke="currentColor"
505
- className="w-5 h-5"
506
- >
507
- <path
508
- stroke-linecap="round"
509
- stroke-linejoin="round"
510
- 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"
511
- />
512
- </svg>
513
- </button>
514
-
515
- <button
516
- type="button"
517
- onClick={() => {
518
- handleAddSubType(index, taxonomy.id);
519
- }}
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"
521
- >
522
- <svg
523
- xmlns="http://www.w3.org/2000/svg"
524
- fill="none"
525
- viewBox="0 0 24 24"
526
- stroke-width="1.5"
527
- stroke="currentColor"
528
- className="w-5 h-5"
529
- >
530
- <path
531
- stroke-linecap="round"
532
- stroke-linejoin="round"
533
- d="M12 4.5v15m7.5-7.5h-15"
534
- />
535
- </svg>
536
- </button>
537
- </div>
538
- </td>
539
- )}
540
-
541
- <td className="px-4 py-4 text-sm text-gray-500 dark:text-gray-400">
542
- {taxonomy.code}
543
- </td>
544
-
545
- <td className="px-4 py-4 text-sm font-medium text-gray-900 dark:text-white">
546
- <div className="flex justify-between items-center">
547
- <span>{taxonomy.value}</span>
548
-
549
- <button
550
- type="button"
551
- className="text-gray-500 transition-colors duration-200 dark:hover:text-blue-600 dark:text-gray-300 hover:text-blue-500 focus:outline-none"
552
- >
553
- <svg
554
- xmlns="http://www.w3.org/2000/svg"
555
- fill="none"
556
- viewBox="0 0 24 24"
557
- strokeWidth="1.5"
558
- stroke="currentColor"
559
- className="w-5 h-5"
560
- >
561
- <path
562
- strokeLinecap="round"
563
- strokeLinejoin="round"
564
- d="M19.5 8.25l-7.5 7.5-7.5-7.5"
565
- />
566
- </svg>
567
- </button>
568
- </div>
569
- </td>
570
- </tr>
571
- ))} */}
572
-
506
+ {/* <tbody className="divide-y divide-gray-200">
573
507
  {similarTaxonomies.map((taxonomy, index) => {
574
- const isParent = similarTaxonomies.some(
575
- (t) => t.parentId === taxonomy.id
576
- );
577
-
578
508
  return (
579
509
  <tr key={index}>
580
510
  {similarTaxonomies.some(
@@ -660,7 +590,9 @@ const TaxonomyForm = () => {
660
590
  <div className="flex justify-between items-center">
661
591
  <span>{taxonomy.value}</span>
662
592
 
663
- {isParent && (
593
+ {allTaxonomies.some(
594
+ (item) => item.parentId === taxonomy.id
595
+ ) && (
664
596
  <button
665
597
  type="button"
666
598
  className="text-gray-500 transition-colors duration-200 dark:hover:text-blue-600 dark:text-gray-300 hover:text-blue-500 focus:outline-none"
@@ -686,6 +618,121 @@ const TaxonomyForm = () => {
686
618
  </tr>
687
619
  );
688
620
  })}
621
+ </tbody> */}
622
+ <tbody className="divide-y divide-gray-200">
623
+ {similarTaxonomies.map((taxonomy) => {
624
+ const hasChildren = allTaxonomies.some(
625
+ (item) => item.parentId === taxonomy.id
626
+ );
627
+ return (
628
+ <React.Fragment key={taxonomy.id}>
629
+ <tr>
630
+ <td className="px-4 py-4 text-sm whitespace-nowrap">
631
+ <div className="flex items-center gap-x-6">
632
+ <button
633
+ type="button"
634
+ onClick={() =>
635
+ console.log("Edit clicked", taxonomy.id)
636
+ }
637
+ className="text-gray-500 transition-colors duration-200 dark:hover:text-yellow-500 dark:text-gray-300 hover:text-yellow-500 focus:outline-none"
638
+ >
639
+ Edit
640
+ </button>
641
+ </div>
642
+ </td>
643
+ <td className="px-4 py-4 text-sm text-gray-500 dark:text-gray-400">
644
+ {taxonomy.code}
645
+ </td>
646
+ <td className="px-4 py-4 text-sm font-medium text-gray-900 dark:text-white">
647
+ <div className="flex justify-between items-center">
648
+ <span>{taxonomy.value}</span>
649
+ {hasChildren && (
650
+ <button
651
+ type="button"
652
+ onClick={() =>
653
+ toggleRowExpansion(taxonomy.id)
654
+ }
655
+ className="text-gray-500 transition-colors duration-200 dark:hover:text-blue-600 dark:text-gray-300 hover:text-blue-500 focus:outline-none"
656
+ >
657
+ {expandedRows.indexOf(taxonomy.id) !== -1 ? (
658
+ <svg
659
+ xmlns="http://www.w3.org/2000/svg"
660
+ fill="none"
661
+ viewBox="0 0 24 24"
662
+ strokeWidth="1.5"
663
+ stroke="currentColor"
664
+ className="w-5 h-5"
665
+ >
666
+ <path
667
+ strokeLinecap="round"
668
+ strokeLinejoin="round"
669
+ d="M19.5 8.25l-7.5 7.5-7.5-7.5"
670
+ />
671
+ </svg>
672
+ ) : (
673
+ <svg
674
+ xmlns="http://www.w3.org/2000/svg"
675
+ fill="none"
676
+ viewBox="0 0 24 24"
677
+ strokeWidth="1.5"
678
+ stroke="currentColor"
679
+ className="w-5 h-5"
680
+ >
681
+ <path
682
+ strokeLinecap="round"
683
+ strokeLinejoin="round"
684
+ d="M19.5 15.75l-7.5-7.5-7.5 7.5"
685
+ />
686
+ </svg>
687
+ )}
688
+ </button>
689
+ )}
690
+ </div>
691
+ </td>
692
+ </tr>
693
+ {expandedRows.indexOf(taxonomy.id) !== -1 && (
694
+ <tr>
695
+ <td
696
+ colSpan={3}
697
+ className="bg-gray-100 dark:bg-gray-900"
698
+ >
699
+ <table className="min-w-full divide-y divide-gray-200 dark:divide-gray-700">
700
+ <thead>
701
+ <tr>
702
+ <th className="px-4 py-2 text-sm font-normal text-left text-gray-500 dark:text-gray-400">
703
+ Child Code
704
+ </th>
705
+ <th className="px-4 py-2 text-sm font-normal text-left text-gray-500 dark:text-gray-400">
706
+ Child Value
707
+ </th>
708
+ </tr>
709
+ </thead>
710
+ <tbody>
711
+ {allTaxonomies
712
+ .filter(
713
+ (item) => item.parentId === taxonomy.id
714
+ )
715
+ .map((child) => (
716
+ <tr key={child.id}>
717
+ <td className="px-4 py-2 text-sm text-gray-500 dark:text-gray-400">
718
+ {child.type}
719
+ </td>
720
+ <td className="px-4 py-2 text-sm text-gray-500 dark:text-gray-400">
721
+ {child.code}
722
+ </td>
723
+ <td className="px-4 py-2 text-sm text-gray-900 dark:text-white">
724
+ {child.value}
725
+ </td>
726
+ </tr>
727
+ ))}
728
+ </tbody>
729
+ </table>
730
+ </td>
731
+ </tr>
732
+ )}
733
+ </React.Fragment>
734
+ );
735
+ })}
689
736
  </tbody>
690
737
  </table>
691
738
  </div>
@@ -859,27 +906,6 @@ const TaxonomyForm = () => {
859
906
  </button>
860
907
  </div>
861
908
 
862
- {/* <label className="text-gray-900 dark:text-gray-200 font-semibold">
863
- Code
864
- </label>
865
- <input
866
- type="number"
867
- value={newCode}
868
- onChange={(e) => setNewCode(e.target.value)}
869
- placeholder="Enter Code"
870
- className="w-full px-4 py-2 mt-2 mb-4 border border-gray-300 rounded-md"
871
- />
872
- <label className="text-gray-900 dark:text-gray-200 font-semibold">
873
- Value
874
- </label>
875
- <input
876
- type="text"
877
- value={newValue}
878
- onChange={(e) => setNewValue(e.target.value)}
879
- placeholder="Enter Value"
880
- className="w-full px-4 py-2 mt-2 mb-4 border border-gray-300 rounded-md"
881
- /> */}
882
-
883
909
  {isAddingSubType ? (
884
910
  <>
885
911
  <label className="text-gray-900 dark:text-gray-200 font-semibold">