From b4157354f7c90a0d551a3bc153704857c81dee12 Mon Sep 17 00:00:00 2001 From: Pramod Mahajan Date: Tue, 27 May 2025 22:23:32 +0530 Subject: [PATCH] added sorting button to table header --- src/components/Directory/ManageBucket.jsx | 38 +++++++++++++++++------ 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/components/Directory/ManageBucket.jsx b/src/components/Directory/ManageBucket.jsx index d8b32bbb..2d71c030 100644 --- a/src/components/Directory/ManageBucket.jsx +++ b/src/components/Directory/ManageBucket.jsx @@ -8,15 +8,31 @@ import Directory from "../../pages/Directory/Directory"; import { DirectoryRepository } from "../../repositories/DirectoryRepository"; import { cacheData, getCachedData } from "../../slices/apiDataManager"; import { useBuckets } from "../../hooks/useDirectory"; +import EmployeeList from "./EmployeeList"; +import {useAllEmployees, useEmployees} from "../../hooks/useEmployees"; +import {useSortableData} from "../../hooks/useSortableData"; const ManageBucket = () => { - const [bucketList, setBucketList] = useState([]); - + const [ bucketList, setBucketList ] = useState( [] ); + const {employeesList} = useAllEmployees(false) const { buckets } = useBuckets(); const [action_bucket, setAction_bucket] = useState(false); const [isSubmitting, setSubmitting] = useState(false); - const [selected_bucket, select_bucket] = useState(null); + const [ selected_bucket, select_bucket ] = useState( null ); + const { items: sortedBuckteList, requestSort, sortConfig} = useSortableData(bucketList,{ + key: (e) => `${e.name}`, + direction: 'asc', + } ) + const getSortIcon = () => { + if (!sortConfig) return null; + return sortConfig.direction === 'asc' ? ( + + ) : ( + + ); + }; + const { register, @@ -112,12 +128,12 @@ const ManageBucket = () =>
{!action_bucket ? (
- - +
+ - - {bucketList.map((bucket) => ( + {sortedBuckteList.map((bucket) => (
+ requestSort((e) => `${e.name} `)}>
- Name + Name {getSortIcon()}
@@ -134,7 +150,7 @@ const ManageBucket = () =>
@@ -163,6 +179,7 @@ const ManageBucket = () =>
) : ( + <>
@@ -203,7 +220,10 @@ const ManageBucket = () => {isSubmitting ? "Please wait..." : "Submit"}
-
+ + + + )}