Merge branch 'pagination-familylist' of WrenchBoard/Users-Wrench into master

This commit is contained in:
2023-05-24 10:51:14 +00:00
committed by Gogs
3 changed files with 36 additions and 8 deletions
+32 -4
View File
@@ -2,19 +2,32 @@ import React, { useState } from "react";
import dataImage1 from "../../assets/images/data-table-user-1.png"; import dataImage1 from "../../assets/images/data-table-user-1.png";
import LoadingSpinner from "../Spinners/LoadingSpinner"; import LoadingSpinner from "../Spinners/LoadingSpinner";
import { useNavigate, useLocation, Link } from "react-router-dom"; import { useNavigate, useLocation, Link } from "react-router-dom";
import { handlePagingFunc } from "../Pagination/HandlePagination";
import PaginatedList from "../Pagination/PaginatedList";
export default function FamilyTable({ className, familyList, loader }) { export default function FamilyTable({ className, familyList, loader }) {
const filterCategories = ["All Categories", "Explore", "Featured"]; const filterCategories = ["All Categories", "Explore", "Featured"];
const [selectedCategory, setCategory] = useState(filterCategories[0]); const [selectedCategory, setCategory] = useState(filterCategories[0]);
const navigate = useNavigate(); const navigate = useNavigate();
// let location = useLocation(); // let location = useLocation();
const [currentPage, setCurrentPage] = useState(0);
const indexOfFirstItem = Number(currentPage);
const indexOfLastItem =
Number(indexOfFirstItem) + Number(process.env.REACT_APP_ITEM_PER_PAGE);
const currentFamilyList = familyList?.slice(indexOfFirstItem, indexOfLastItem);
const handlePagination = (e) => {
handlePagingFunc(e, setCurrentPage);
};
return ( return (
<div <div
className={`update-table w-full p-8 bg-white dark:bg-dark-white overflow-y-auto rounded-2xl section-shadow min-h-[520px] max-h-[600px] ${ className={`update-table w-full h-full p-8 bg-white dark:bg-dark-white overflow-y-auto rounded-2xl section-shadow ${
className || "" className || ""
}`} }`}
> >
<div className="relative w-full overflow-x-auto sm:rounded-lg"> <div className="relative w-full h-full overflow-x-auto sm:rounded-lg">
{loader ? ( {loader ? (
<div className="h-full min-h-[500px] w-full overflow-hidden flex justify-center items-center"> <div className="h-full min-h-[500px] w-full overflow-hidden flex justify-center items-center">
<LoadingSpinner size="16" color="sky-blue" /> <LoadingSpinner size="16" color="sky-blue" />
@@ -30,10 +43,10 @@ export default function FamilyTable({ className, familyList, loader }) {
<th className="py-4 text-right"></th> <th className="py-4 text-right"></th>
</tr> </tr>
</thead> </thead>
<tbody className="overflow-y-scroll h-auto"> <tbody className="h-full">
<> <>
{familyList?.length > 0 ? ( {familyList?.length > 0 ? (
familyList?.map((props, idx) => { currentFamilyList?.map((props, idx) => {
let { let {
firstname, firstname,
lastname, lastname,
@@ -115,6 +128,21 @@ export default function FamilyTable({ className, familyList, loader }) {
</table> </table>
)} )}
</div> </div>
{/* PAGINATION BUTTON */}
<PaginatedList
onClick={handlePagination}
prev={currentPage == 0 ? true : false}
next={
currentPage + Number(process.env.REACT_APP_ITEM_PER_PAGE) >=
familyList?.length
? true
: false
}
data={familyList}
start={indexOfFirstItem}
stop={indexOfLastItem}
/>
{/* END OF PAGINATION BUTTON */}
</div> </div>
); );
} }
+2 -2
View File
@@ -8,8 +8,8 @@ export const userSlice = createSlice({
name: "userDetails", name: "userDetails",
initialState, initialState,
reducers: { reducers: {
updateUserDetails: (state,payload) => { updateUserDetails: (state,action) => {
state.userDetails = {...payload.payload} state.userDetails = {...action.payload}
}, },
}, },
}); });
+2 -2
View File
@@ -8,8 +8,8 @@ export const jobSlice = createSlice({
name: "jobLists", name: "jobLists",
initialState, initialState,
reducers: { reducers: {
updateJobs: (state, payload) => { updateJobs: (state, action) => {
state.jobLists = { ...payload.payload }; state.jobLists = { ...action.payload };
}, },
}, },
}); });