Commit 70e03924 authored by Mai Thanh Cong's avatar Mai Thanh Cong

create pagination

parent b61ee5dd
...@@ -78,7 +78,17 @@ const SearchProfile = (props) => { ...@@ -78,7 +78,17 @@ const SearchProfile = (props) => {
</Container> </Container>
</section> </section>
<section className="section"> <section className="section">
<ProfileTable dummyData={props.listProfile} /> <ProfileTable
listProfile={props.listProfile}
currentPage={props.currentPage}
limit={props.limit}
nextPage={props.nextPage}
previosPage={props.previosPage}
total={props.total}
onLoadListProfile={props.onLoadListProfile}
onLoadPreviousPage={props.onLoadPreviousPage}
onLoadNextPage={props.onLoadNextPage}
/>
</section> </section>
<Sologan /> <Sologan />
</main> </main>
......
...@@ -6,14 +6,14 @@ import { profileFormatDateTime } from "constans"; ...@@ -6,14 +6,14 @@ import { profileFormatDateTime } from "constans";
export const ProfileTable = (props) => { export const ProfileTable = (props) => {
const history = useHistory(); const history = useHistory();
// const dispatch = useDispatch(); const dispatch = useDispatch();
const onHandleClickAdd = () => { const onHandleClickAdd = () => {
history.push("/profile/add"); history.push("/profile/add");
}; };
const onHandleClickEdit = (profileId) => { const onHandleClickEdit = (profileId) => {
let detailProfile = props.dummyData.filter(item => item.id === profileId); let detailProfile = props.listProfile.filter(item => item.id === profileId);
history.push({ history.push({
pathname: "/profile/add", pathname: "/profile/add",
state: { profileId, detailProfile } state: { profileId, detailProfile }
...@@ -21,7 +21,7 @@ export const ProfileTable = (props) => { ...@@ -21,7 +21,7 @@ export const ProfileTable = (props) => {
} }
const onHandleClickDelete = (profileId) => { const onHandleClickDelete = (profileId) => {
return props.dummyData.filter(item => item.id !== profileId); return props.listProfile.filter(item => item.id !== profileId);
// dispatch(props.onDeleteProfile(profileId)); // dispatch(props.onDeleteProfile(profileId));
} }
...@@ -30,8 +30,8 @@ export const ProfileTable = (props) => { ...@@ -30,8 +30,8 @@ export const ProfileTable = (props) => {
}, []); }, []);
const items = []; const items = [];
const totalItem = "15"; const totalItem = props.total;
let pageSize = totalItem / 10; let pageSize = totalItem / props.limit;
const getPageItem = () => { const getPageItem = () => {
let number = 1; let number = 1;
...@@ -44,18 +44,30 @@ export const ProfileTable = (props) => { ...@@ -44,18 +44,30 @@ export const ProfileTable = (props) => {
} }
for(let number=1; number <= getPageItem(); number++){ for(let number=1; number <= getPageItem(); number++){
// const isItemActive = props.currentPage === number; const isItemActive = props.currentPage === number;
const handlePaginationChange = () => { const handlePaginationChange = () => {
// dispatch(props.onLoadListProfile( { currentPage: number, limit: props.limit } )); dispatch(props.onLoadListProfile( { currentPage: number, limit: props.limit } ));
// dispatch(props.onLoadPreviousPage(number)); dispatch(props.onLoadPreviousPage(number));
}; };
items.push( items.push(
<PaginationItem key={number} onClick={handlePaginationChange}> <PaginationItem active={isItemActive} key={number} onClick={handlePaginationChange}>
<PaginationLink>{number}</PaginationLink> <PaginationLink>{number}</PaginationLink>
</PaginationItem> </PaginationItem>
); );
} }
const onPrevItem = () => {
const prevActiveItem = props.currentPage === 1 ? props.currentPage : props.currentPage - 1;
dispatch(props.onLoadListProfile({ currentPage: props.previosPage, limit: props.limit }));
dispatch(props.onLoadPreviousPage(prevActiveItem));
};
const onNextItem = () => {
const nextActiveItem = props.currentPage === Math.ceil(pageSize) ? props.currentPage : props.currentPage + 1;
dispatch(props.onLoadListProfile({ currentPage: props.nextPage, limit: props.limit }));
dispatch(props.onLoadNextPage(nextActiveItem));
};
const TableRow = (props) => { const TableRow = (props) => {
const { id, address, logo, name, phone_number, profile_product, created_at, qr_code } = props; const { id, address, logo, name, phone_number, profile_product, created_at, qr_code } = props;
const productName = profile_product ? profile_product.map(item => item.name) : ""; const productName = profile_product ? profile_product.map(item => item.name) : "";
...@@ -90,7 +102,7 @@ export const ProfileTable = (props) => { ...@@ -90,7 +102,7 @@ export const ProfileTable = (props) => {
}; };
return ( return (
props.dummyData && props.dummyData.length > 0 ? props.listProfile && props.listProfile.length > 0 ?
<Card className="mx-5"> <Card className="mx-5">
<CardHeader> <CardHeader>
<Row className="align-items-center"> <Row className="align-items-center">
...@@ -117,7 +129,7 @@ export const ProfileTable = (props) => { ...@@ -117,7 +129,7 @@ export const ProfileTable = (props) => {
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{props.dummyData ? props.dummyData.map(profile => <TableRow key={`page-visit-${profile.id}`} {...profile} />) : []} {props.listProfile ? props.listProfile.map(profile => <TableRow key={`page-visit-${profile.id}`} {...profile} />) : []}
</tbody> </tbody>
</Table> </Table>
<Row className="mx-3 my-2"> <Row className="mx-3 my-2">
...@@ -127,11 +139,11 @@ export const ProfileTable = (props) => { ...@@ -127,11 +139,11 @@ export const ProfileTable = (props) => {
<PaginationItem> <PaginationItem>
<PaginationLink first href="#" /> <PaginationLink first href="#" />
</PaginationItem> </PaginationItem>
<PaginationItem> <PaginationItem disabled={props.currentPage === 1} onClick={onPrevItem}>
<PaginationLink previous href="#" /> <PaginationLink previous href="#" />
</PaginationItem> </PaginationItem>
{items} {items}
<PaginationItem> <PaginationItem disabled={props.currentPage === Math.ceil(pageSize)} onClick={onNextItem}>
<PaginationLink next href="#" /> <PaginationLink next href="#" />
</PaginationItem> </PaginationItem>
<PaginationItem> <PaginationItem>
...@@ -142,7 +154,7 @@ export const ProfileTable = (props) => { ...@@ -142,7 +154,7 @@ export const ProfileTable = (props) => {
</Col> </Col>
<Col className="text-right"> <Col className="text-right">
<h6 className="font-weight-bold"> <h6 className="font-weight-bold">
{('Hiển thị ' + props.dummyData.length + "/" + totalItem)} {('Hiển thị ' + props.listProfile.length + "/" + totalItem)}
</h6> </h6>
</Col> </Col>
</Row> </Row>
......
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