Skip to content

Commit 52d59c1

Browse files
committed
feat: pagination in userList(with dummy values)
1 parent d33e216 commit 52d59c1

File tree

2 files changed

+45
-43
lines changed

2 files changed

+45
-43
lines changed

src/ui/views/RepoList/Components/RepoOverview.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ export default function Repositories(props) {
578578
const itemsPerPage = 5;
579579

580580

581-
// Dummy repository data
581+
// Dummy repository data```````````
582582
const dummyRepositories = [
583583
{ project: 'Org1', name: 'Repo1', description: 'Description for Repo 1' },
584584
{ project: 'Org2', name: 'Repo2', description: 'Description for Repo 2' },
Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import React, { useState, useEffect } from 'react';
1+
import React, { useState } from 'react';
22
import { makeStyles } from '@material-ui/core/styles';
33
import GridItem from '../../../components/Grid/GridItem';
44
import GridContainer from '../../../components/Grid/GridContainer';
5-
import { useNavigate } from 'react-router-dom';
65
import Button from '@material-ui/core/Button';
76
import Table from '@material-ui/core/Table';
87
import TableBody from '@material-ui/core/TableBody';
@@ -11,35 +10,43 @@ import TableContainer from '@material-ui/core/TableContainer';
1110
import TableHead from '@material-ui/core/TableHead';
1211
import TableRow from '@material-ui/core/TableRow';
1312
import Paper from '@material-ui/core/Paper';
14-
import styles from '../../../assets/jss/material-dashboard-react/views/dashboardStyle';
15-
import { getUsers } from '../../../services/user';
16-
1713
import { CloseRounded, Check, KeyboardArrowRight } from '@material-ui/icons';
18-
// import Pagination from '../../../components/Pagination/Pagination';
14+
import Pagination from '../../../components/Pagination/Pagination';
15+
16+
const useStyles = makeStyles({
17+
table: {
18+
minWidth: 650,
19+
},
20+
});
1921

20-
export default function UserList(props) {
21-
const useStyles = makeStyles(styles);
22+
export default function UserList() {
2223
const classes = useStyles();
23-
const [data, setData] = useState([]);
24-
const [, setAuth] = useState(true);
25-
const [isLoading, setIsLoading] = useState(false);
26-
const [isError, setIsError] = useState(false);
27-
const navigate = useNavigate();
2824

29-
const openUser = (username) => navigate(`/admin/user/${username}`, { replace: true });
25+
// Dummy user data
26+
const dummyUsers = [
27+
{ username: 'johnDoe', displayName: 'John Doe', title: 'Developer', email: '[email protected]', gitAccount: 'johnDoeGit', admin: true },
28+
{ username: 'janeDoe', displayName: 'Jane Doe', title: 'Designer', email: '[email protected]', gitAccount: 'janeDoeGit', admin: false },
29+
{ username: 'markSmith', displayName: 'Mark Smith', title: 'Project Manager', email: '[email protected]', gitAccount: 'markSmithGit', admin: true },
30+
{ username: 'lucasBrown', displayName: 'Lucas Brown', title: 'Data Scientist', email: '[email protected]', gitAccount: 'lucasBrownGit', admin: false },
31+
{ username: 'emilyWhite', displayName: 'Emily White', title: 'Backend Engineer', email: '[email protected]', gitAccount: 'emilyWhiteGit', admin: true },
32+
{ username: 'oliviaGreen', displayName: 'Olivia Green', title: 'Frontend Developer', email: '[email protected]', gitAccount: 'oliviaGreenGit', admin: false },
33+
{ username: 'noahBlue', displayName: 'Noah Blue', title: 'DevOps Engineer', email: '[email protected]', gitAccount: 'noahBlueGit', admin: true },
34+
{ username: 'miaBlack', displayName: 'Mia Black', title: 'Quality Analyst', email: '[email protected]', gitAccount: 'miaBlackGit', admin: false },
35+
{ username: 'willGray', displayName: 'Will Gray', title: 'HR Manager', email: '[email protected]', gitAccount: 'willGrayGit', admin: false },
36+
{ username: 'avaYellow', displayName: 'Ava Yellow', title: 'UX Designer', email: '[email protected]', gitAccount: 'avaYellowGit', admin: true },
37+
];
3038

31-
useEffect(() => {
32-
const query = {};
39+
// Pagination states
40+
const [currentPage, setCurrentPage] = useState(1);
41+
const itemsPerPage = 5; // Set the number of items per page
3342

34-
for (const k in props) {
35-
if (!k) continue;
36-
query[k] = props[k];
37-
}
38-
getUsers(setIsLoading, setData, setAuth, setIsError, query);
39-
}, [props]);
43+
// Calculate the items for the current page
44+
const indexOfLastItem = currentPage * itemsPerPage;
45+
const indexOfFirstItem = indexOfLastItem - itemsPerPage;
46+
const currentItems = dummyUsers.slice(indexOfFirstItem, indexOfLastItem);
47+
const totalItems = dummyUsers.length;
4048

41-
if (isLoading) return <div>Loading...</div>;
42-
if (isError) return <div>Something went wrong...</div>;
49+
const handlePageChange = (page) => setCurrentPage(page);
4350

4451
return (
4552
<GridContainer>
@@ -57,37 +64,23 @@ export default function UserList(props) {
5764
</TableRow>
5865
</TableHead>
5966
<TableBody>
60-
{data.map((row) => (
67+
{currentItems.map((row) => (
6168
<TableRow key={row.username}>
6269
<TableCell align='left'>{row.displayName}</TableCell>
6370
<TableCell align='left'>{row.title}</TableCell>
6471
<TableCell align='left'>
6572
<a href={`mailto:${row.email}`}>{row.email}</a>
6673
</TableCell>
6774
<TableCell align='left'>
68-
<a
69-
href={`https://github.com/${row.gitAccount}`}
70-
rel='noreferrer'
71-
target='_blank'
72-
>
75+
<a href={`https://github.com/${row.gitAccount}`} target='_blank' rel='noreferrer'>
7376
{row.gitAccount}
7477
</a>
7578
</TableCell>
7679
<TableCell align='left'>
77-
{row.admin ? (
78-
<span style={{ color: 'green' }}>
79-
<Check fontSize='small' />
80-
</span>
81-
) : (
82-
<CloseRounded color='error' />
83-
)}
80+
{row.admin ? <Check fontSize='small' color='primary' /> : <CloseRounded color='error' />}
8481
</TableCell>
8582
<TableCell component='th' scope='row'>
86-
<Button
87-
variant='contained'
88-
color='primary'
89-
onClick={() => openUser(row.username)}
90-
>
83+
<Button variant='contained' color='primary'>
9184
<KeyboardArrowRight />
9285
</Button>
9386
</TableCell>
@@ -96,7 +89,16 @@ export default function UserList(props) {
9689
</TableBody>
9790
</Table>
9891
</TableContainer>
92+
93+
{/* Pagination Component */}
94+
<Pagination
95+
currentPage={currentPage}
96+
totalItems={totalItems}
97+
itemsPerPage={itemsPerPage}
98+
onPageChange={handlePageChange}
99+
/>
99100
</GridItem>
100101
</GridContainer>
101102
);
102103
}
104+

0 commit comments

Comments
 (0)