Skip to content

Commit

Permalink
Componentes para historial de productos
Browse files Browse the repository at this point in the history
  • Loading branch information
hendaniel committed Sep 7, 2020
1 parent d96edde commit 34ce37c
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 2 deletions.
63 changes: 63 additions & 0 deletions src/components/ProductsHistory/ListHistory.jsx
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;
23 changes: 23 additions & 0 deletions src/components/ProductsHistory/RedeemedProduct.jsx
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.
8 changes: 7 additions & 1 deletion src/components/User/UserPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { coin } from "../../assets/index";
import { UserContext } from "../../providers/UserProvider";
import { CoinsModal } from "../Modals/index";
import { useModal } from "../../hooks/index";

import { Switch, Route } from "react-router-dom";
import ProductsList from "../Products/ProductsList";
import "./user.scss";

const UserPanel = () => {
Expand All @@ -22,6 +23,11 @@ const UserPanel = () => {
const { name, points } = user;
return (
<>
<Switch>
<Route exact path="/" component={ProductsList} />
<Route exact path="/" component={ProductsList} />

</Switch>
{coinsModal && (
<CoinsModal isShowing={coinsModal} hide={toggleCoinsModal} />
)}
Expand Down
2 changes: 1 addition & 1 deletion src/routes.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const routes = [
{
path: "/home",
path: "/",
linkname: "Home",
},
{
Expand Down

0 comments on commit 34ce37c

Please sign in to comment.