Commit 6afce932 authored by Shiva Komirishetti's avatar Shiva Komirishetti

Added pagination to my reportees

parent 4a050bfa
import React, { useState } from "react"; import React, { useState } from "react";
import Table from "../table"; import Table from "../table";
import moment from "moment";
import ModalButton from "../modal/modalButton"; import ModalButton from "../modal/modalButton";
import { useSelector ,useDispatch} from "react-redux"; import { useSelector ,useDispatch} from "react-redux";
import { useEffect } from "react"; import { useEffect } from "react";
...@@ -8,6 +7,7 @@ import {useParams} from 'react-router' ...@@ -8,6 +7,7 @@ import {useParams} from 'react-router'
import { fetchReportees } from "../../redux/reducers/reporteesSlice"; import { fetchReportees } from "../../redux/reducers/reporteesSlice";
import { calculateDefaultScore,calculateInitiativeScore } from "../../redux/reducers/viewreporteeSlice"; import { calculateDefaultScore,calculateInitiativeScore } from "../../redux/reducers/viewreporteeSlice";
import Loading from "../loading Component/Loading"; import Loading from "../loading Component/Loading";
import {convertUTCToLocal} from '../../utils/commonFunctions';
function Accordion({ title, data ,handleAddActivity,open,handleAccordian}) { function Accordion({ title, data ,handleAddActivity,open,handleAccordian}) {
...@@ -41,7 +41,7 @@ function Accordion({ title, data ,handleAddActivity,open,handleAccordian}) { ...@@ -41,7 +41,7 @@ function Accordion({ title, data ,handleAddActivity,open,handleAccordian}) {
} }
const headers = [ const headers = [
{ title: "Activity Name", id: "aName"}, { title: "Activity Name", id: "aName"},
{ title: "Date", id: "recorded_date", render: (value) => moment(value).format('DD-MM-YYYY') }, { title: "Date", id: "recorded_date", render: (value) => convertUTCToLocal(value) },
{title: "Rated By", id: "ratedBy"}, {title: "Rated By", id: "ratedBy"},
{ title: "Score", id: "score", render: (value) => <div className="w-[35px] px-3 bg-blue-400 rounded-full text-white font-bold text-center p-[4px]">{value}</div> }, { title: "Score", id: "score", render: (value) => <div className="w-[35px] px-3 bg-blue-400 rounded-full text-white font-bold text-center p-[4px]">{value}</div> },
{ title: "Comments", id: "comments", render:(value)=><span className="listData" title={value}>{value}</span>}, { title: "Comments", id: "comments", render:(value)=><span className="listData" title={value}>{value}</span>},
......
...@@ -42,7 +42,7 @@ function Header({ isOpen }) { ...@@ -42,7 +42,7 @@ function Header({ isOpen }) {
<div className="flex items-center relative"> <div className="flex items-center relative">
<button ref={logoutRef} className=" -mt-1 text-2xl flex" onClick={() => setOpen(!open)}> <button ref={logoutRef} className=" -mt-1 text-2xl flex" onClick={() => setOpen(!open)}>
<img src="/user.png" width="35px" height="35px" className="mt-2 pr-2" /> <img src="/user.png" width="35px" height="35px" className="mt-2 pr-2" />
<div className="flex flex-col"> <div className="flex flex-col items-start">
<p className="text-lg font-semibold">{user?.empName}</p> <p className="text-lg font-semibold">{user?.empName}</p>
<p className="text-xs">{user?.designation}</p> <p className="text-xs">{user?.designation}</p>
</div> </div>
......
...@@ -5,12 +5,14 @@ import { useSelector, useDispatch } from "react-redux"; ...@@ -5,12 +5,14 @@ import { useSelector, useDispatch } from "react-redux";
import { useParams } from "react-router-dom"; import { useParams } from "react-router-dom";
import { scoreColor } from '../../utils/commonFunctions'; import { scoreColor } from '../../utils/commonFunctions';
import Loading from "../loading Component/Loading"; import Loading from "../loading Component/Loading";
import PaginationComponent from "../Pagenation/Pagenation";
function LeftSidebar() { function LeftSidebar() {
const dispatch = useDispatch(); const dispatch = useDispatch();
const [currPage, setCurrPage] = useState(1); const [currPage, setCurrPage] = useState(1);
const [pagesCount, setPagesCount] = useState(1);
const [inputValue, setInputValue] = useState(null); const [inputValue, setInputValue] = useState(null);
const { reportees, loading, viewReportee } = useSelector((state) => state.reportees); const { reportees, loading, viewReportee, totalCount } = useSelector((state) => state.reportees);
const userDetails = useSelector((state) => state.userDetails); const userDetails = useSelector((state) => state.userDetails);
...@@ -35,6 +37,20 @@ function LeftSidebar() { ...@@ -35,6 +37,20 @@ function LeftSidebar() {
setInputValue(event.target.value); setInputValue(event.target.value);
}; };
useEffect(() => {
setPagesCount(Math.ceil((totalCount) / (10)))
}, [totalCount])
const handlePageChange = (currPage) => {
let data = {
reportees: userDetails.user.reportees,
page: currPage,
perPage: 10
}
setCurrPage(currPage)
dispatch(fetchReportees(data))
}
return ( return (
<div className=" w-[33%] flex flex-col px-[5px]"> <div className=" w-[33%] flex flex-col px-[5px]">
...@@ -56,7 +72,7 @@ function LeftSidebar() { ...@@ -56,7 +72,7 @@ function LeftSidebar() {
{reportees?.map(({ empName, score, empId }) => ( {reportees?.map(({ empName, score, empId }) => (
<button onClick={() => dispatch(setViewReportee(empId))} <button onClick={() => dispatch(setViewReportee(empId))}
// to={`/viewreportee`} // to={`/viewreportee`}
className={`flex items-center hover:bg-blue-400 hover:text-white bg-${viewReportee.empId == empId ? "blue-400 text-white" : "white" className={`flex items-center hover:bg-blue-400 hover:text-white bg-${viewReportee?.empId == empId ? "blue-400 text-white" : "white"
} p-2 justify-between mb-1 w-full`} } p-2 justify-between mb-1 w-full`}
key={empId} key={empId}
> >
...@@ -70,7 +86,13 @@ function LeftSidebar() { ...@@ -70,7 +86,13 @@ function LeftSidebar() {
))} ))}
</div> </div>
} }
<div>
<PaginationComponent
currentPage={currPage}
totalPages={pagesCount}
onPageChange={handlePageChange}
/>
</div>
</div> </div>
); );
} }
......
...@@ -76,15 +76,15 @@ function Viewreportee() { ...@@ -76,15 +76,15 @@ function Viewreportee() {
} }
useEffect(()=>{ useEffect(()=>{
if(reportees.length>0 && viewReportee) if(reportees.length>0 && viewReportee !== null)
dispatch(fetchReporteeActivities({empId:viewReportee.empId})) dispatch(fetchReporteeActivities({empId:viewReportee?.empId}))
},[reportees,viewReportee]) },[reportees,viewReportee])
useEffect(()=>{ // useEffect(()=>{
if(reportees.length){ // if(reportees.length){
dispatch(setViewReportee(viewReportee.empId)) // dispatch(setViewReportee(viewReportee?.empId))
} // }
},[reportees]) // },[reportees])
......
import moment from 'moment';
export const scoreColor = (value) => { export const scoreColor = (value) => {
if (value < 1) { if (value < 1) {
return 'bg-red-400'; return 'bg-red-400';
...@@ -18,7 +20,7 @@ export const scoreColor = (value) => { ...@@ -18,7 +20,7 @@ export const scoreColor = (value) => {
export const debounce = (func, delay) => { export const debounce = (func, delay) => {
let timeoutId; let timeoutId;
return function(...args) { return function(...args) {
clearTimeout(timeoutId); clearTimeout(timeoutId);
timeoutId = setTimeout(() => { timeoutId = setTimeout(() => {
...@@ -26,3 +28,10 @@ export const debounce = (func, delay) => { ...@@ -26,3 +28,10 @@ export const debounce = (func, delay) => {
}, delay); }, delay);
}; };
} }
export const convertUTCToLocal = (utcDate) => {
const utcDateObj = new Date(utcDate);
const localTimeMillis = utcDateObj.getTime() + utcDateObj.getTimezoneOffset() * 60 * 1000;
const localDateObj = new Date(localTimeMillis);
return moment(localDateObj).format('DD-MM-YYYY')
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment