-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUsers.js
65 lines (58 loc) · 2.23 KB
/
Users.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import React, { useEffect, useState } from 'react';
import { Header, Footer, H2 } from '../components';
import styled from 'styled-components';
import { useNavigate } from 'react-router-dom';
import {
useGetUsersQuery,
} from '../services/UserServices';
import { api } from '../services/api';
import ReactPaginate from 'react-paginate';
const Users = () => {
const [page, setPage] = useState(0);
const navigate = useNavigate();
const { data, isFetching } = useGetUsersQuery(page + 1);
console.log('data', page);
// const getUsers = () => {
// dispatch(api.endpoints.getUsers.initiate());
// };
// useEffect(() => {
// getUsers();
// }, []);
return (
<>
<ScrollView>
<Header />
<Container>
<H2>Users</H2>
{isFetching ? <div style={{ margin: '0 auto', width: '500px' }}><p>Loading...</p></div> :
<>
{data?.data?.docs.map((item, index) => {
return <div key={index} onClick={() => navigate(`/users/${item._id}`)} style={{ padding: '10px', border: '2px solid gray', width: '500px', margin: '0 auto', marginBottom: '20px' }}>
<p><b>Name:</b> {item.name}</p>
<p><b>Email:</b> {item.email}</p>
</div>;
})}
<div style={{ margin: '0 auto', width: '500px' }}>
<ReactPaginate
initialPage={page}
onPageChange={(page) => setPage(page.selected)}
pageRangeDisplayed={5}
pageCount={data?.data?.totalPages}
activeClassName="active"
/>
</div>
</>
}
</Container>
</ScrollView>
<Footer />
</>
);
};
export default Users;
const ScrollView = styled.div`
min-height: calc(100vh - 80px);
`;
const Container = styled.div`
padding-top: 50px;
`;