-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Componentes para historial de productos
- Loading branch information
Showing
5 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import React, { useEffect, useContext, useState } from "react"; | ||
import { usePagination } from "../../hooks/index"; | ||
import { ProductsContext } from "../../providers/index"; | ||
import RedeemedProduct from "./RedeemedProduct"; | ||
import FilterPanel from "./FilterPanel"; | ||
import { priceFilter } from "../../utils/index"; | ||
import "./products.scss"; | ||
|
||
const ITEMS_PER_PAGE = 16; | ||
|
||
const ListHistory = () => { | ||
const { products, setProductResponse } = useContext(ProductsContext); | ||
|
||
const [filteredProducts, setProducts] = useState([]); | ||
|
||
useEffect(() => { | ||
if (!products) return; | ||
setProducts(products); | ||
}, [products]); | ||
|
||
const { next, prev, currentData, currentAmount, jump } = usePagination( | ||
filteredProducts, | ||
ITEMS_PER_PAGE | ||
); | ||
|
||
const handleFilter = (event) => { | ||
setProducts(products.filter(priceFilter(event.target.value))); | ||
jump(1); | ||
}; | ||
|
||
if (filteredProducts.length) { | ||
return ( | ||
<> | ||
<FilterPanel | ||
currentAmount={currentAmount()} | ||
totalAmount={filteredProducts.length} | ||
onFilter={handleFilter} | ||
/> | ||
<div className="cards"> | ||
{currentData().map((item, key) => { | ||
return ( | ||
<RedeemedProduct item={item} key={key} /> | ||
); | ||
})} | ||
</div> | ||
<div className="container-pagination"> | ||
<div className="pagination"> | ||
<ul> | ||
<button onClick={() => prev()}>Previous</button> | ||
<button onClick={() => next()}>Next</button> | ||
</ul> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
} | ||
return ( | ||
<div className="empty"> | ||
<h1>No hay productos canjeados</h1> | ||
</div> | ||
); | ||
}; | ||
export default ListHistory; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React from "react"; | ||
|
||
import "./products.scss"; | ||
|
||
const Product = ({ | ||
item: { | ||
name, | ||
category, | ||
cost, | ||
img: { url }, | ||
}, | ||
}) => { | ||
return ( | ||
<div className="card"> | ||
<div className="img" style={{ backgroundImage: `url("${url}")` }}></div> | ||
<div className="info"> | ||
<span className="category">{category}</span> | ||
<h3 className="title">{name}</h3> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
export default Product; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
export const routes = [ | ||
{ | ||
path: "/home", | ||
path: "/", | ||
linkname: "Home", | ||
}, | ||
{ | ||
|