1
- import React , { useState , useEffect } from 'react' ;
1
+ import React , { useState } from 'react' ;
2
2
import { makeStyles } from '@material-ui/core/styles' ;
3
3
import GridItem from '../../../components/Grid/GridItem' ;
4
4
import GridContainer from '../../../components/Grid/GridContainer' ;
5
- import { useNavigate } from 'react-router-dom' ;
6
5
import Button from '@material-ui/core/Button' ;
7
6
import Table from '@material-ui/core/Table' ;
8
7
import TableBody from '@material-ui/core/TableBody' ;
@@ -11,35 +10,43 @@ import TableContainer from '@material-ui/core/TableContainer';
11
10
import TableHead from '@material-ui/core/TableHead' ;
12
11
import TableRow from '@material-ui/core/TableRow' ;
13
12
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
-
17
13
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
+ } ) ;
19
21
20
- export default function UserList ( props ) {
21
- const useStyles = makeStyles ( styles ) ;
22
+ export default function UserList ( ) {
22
23
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 ( ) ;
28
24
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
+ ] ;
30
38
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
33
42
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 ;
40
48
41
- if ( isLoading ) return < div > Loading...</ div > ;
42
- if ( isError ) return < div > Something went wrong...</ div > ;
49
+ const handlePageChange = ( page ) => setCurrentPage ( page ) ;
43
50
44
51
return (
45
52
< GridContainer >
@@ -57,37 +64,23 @@ export default function UserList(props) {
57
64
</ TableRow >
58
65
</ TableHead >
59
66
< TableBody >
60
- { data . map ( ( row ) => (
67
+ { currentItems . map ( ( row ) => (
61
68
< TableRow key = { row . username } >
62
69
< TableCell align = 'left' > { row . displayName } </ TableCell >
63
70
< TableCell align = 'left' > { row . title } </ TableCell >
64
71
< TableCell align = 'left' >
65
72
< a href = { `mailto:${ row . email } ` } > { row . email } </ a >
66
73
</ TableCell >
67
74
< 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' >
73
76
{ row . gitAccount }
74
77
</ a >
75
78
</ TableCell >
76
79
< 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' /> }
84
81
</ TableCell >
85
82
< 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' >
91
84
< KeyboardArrowRight />
92
85
</ Button >
93
86
</ TableCell >
@@ -96,7 +89,16 @@ export default function UserList(props) {
96
89
</ TableBody >
97
90
</ Table >
98
91
</ TableContainer >
92
+
93
+ { /* Pagination Component */ }
94
+ < Pagination
95
+ currentPage = { currentPage }
96
+ totalItems = { totalItems }
97
+ itemsPerPage = { itemsPerPage }
98
+ onPageChange = { handlePageChange }
99
+ />
99
100
</ GridItem >
100
101
</ GridContainer >
101
102
) ;
102
103
}
104
+
0 commit comments