-
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.
- Loading branch information
Facundo Martinez
authored and
Facundo Martinez
committed
Feb 15, 2021
1 parent
4ae9fbd
commit 542dddc
Showing
15 changed files
with
415 additions
and
152 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
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
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,34 @@ | ||
import React from "react"; | ||
import Button from "../../forms/Button"; | ||
|
||
const Product = ({ productThumbnail, productName, productPrice }) => { | ||
if (!productThumbnail || !productName || typeof productPrice === "undefined") | ||
return null; | ||
const configAddToCartBtn = { | ||
type: "button", | ||
}; | ||
return ( | ||
<div className="product"> | ||
<div className="thumb"> | ||
<img src={productThumbnail} alt="Product Thumbnail" /> | ||
</div> | ||
<div className="details"> | ||
<ul> | ||
<li> | ||
<span className="name">{productName}</span> | ||
</li> | ||
<li> | ||
<span className="price">${productPrice}</span> | ||
</li> | ||
<li> | ||
<div className="addToCart"> | ||
<Button {...configAddToCartBtn}>Add To Cart</Button> | ||
</div> | ||
</li> | ||
</ul> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Product; |
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,72 @@ | ||
import React, { useEffect } from "react"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
import { useHistory, useParams } from "react-router-dom"; | ||
import { fetchProductsStart } from "../../redux/Product/products.action"; | ||
import FormSelect from "../forms/FormSelect"; | ||
import Product from "./Product"; | ||
import "./styles.scss"; | ||
|
||
const ProductsResults = ({}) => { | ||
const dispatch = useDispatch(); | ||
const history = useHistory(); | ||
const { filterType } = useParams(); | ||
const products = useSelector((state) => state.productsData.products); | ||
|
||
useEffect(() => { | ||
dispatch(fetchProductsStart({ filterType })); | ||
}, [filterType]); | ||
|
||
const handleFilters = (e) => { | ||
const pickedFilter = e.target.value; | ||
history.push(`/search/${pickedFilter}`); | ||
}; | ||
|
||
if (!Array.isArray(products)) return null; | ||
|
||
if (products.length < 1) { | ||
return ( | ||
<div className="products"> | ||
<p>No search results.</p> | ||
</div> | ||
); | ||
} | ||
const configFilters = { | ||
defaultValue: filterType, | ||
options: [ | ||
{ | ||
name: "Show all", | ||
value: "", | ||
}, | ||
{ | ||
name: "Mens", | ||
value: "mens", | ||
}, | ||
{ | ||
name: "Womens", | ||
value: "womens", | ||
}, | ||
], | ||
handleChange: handleFilters, | ||
}; | ||
return ( | ||
<div className="products"> | ||
<h1>Browse Products</h1> | ||
<FormSelect {...configFilters} /> | ||
<div className="productResults"> | ||
{products.map((product, index) => { | ||
const { productThumbnail, productName, productPrice } = product; | ||
if ( | ||
!productThumbnail || | ||
!productName || | ||
typeof productPrice === "undefined" | ||
) | ||
return null; | ||
const configProduct = { productThumbnail, productName, productPrice }; | ||
return <Product key={index} {...configProduct} />; | ||
})} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ProductsResults; |
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,68 @@ | ||
.products { | ||
display: block; | ||
width: 100%; | ||
padding: 0; | ||
margin: 2rem 0; | ||
|
||
.productResults { | ||
display: flex; | ||
flex-wrap: wrap; | ||
margin: 3rem -10px 0; | ||
} | ||
} | ||
|
||
.product { | ||
width: 33.333333333333333%; | ||
margin: 0 auto 2rem; | ||
padding: 0 10px; | ||
|
||
.thumb { | ||
display: block; | ||
width: 100%; | ||
|
||
img { | ||
display: block; | ||
width: 100%; | ||
margin: 0; | ||
} | ||
} | ||
|
||
.details { | ||
display: block; | ||
width: 100%; | ||
padding: 1rem 0; | ||
margin: 0 auto; | ||
|
||
ul, | ||
ul li { | ||
padding: 0; | ||
margin: 0; | ||
} | ||
|
||
ul { | ||
li { | ||
display: block; | ||
width: 100%; | ||
list-style-type: none; | ||
text-align: left; | ||
margin: 0 0 0.5rem; | ||
|
||
.name { | ||
font-size: 2.2rem; | ||
line-height: 1.2; | ||
font-weight: 400; | ||
} | ||
|
||
.price { | ||
font-size: 1.6rem; | ||
line-height: 1; | ||
font-weight: 400; | ||
} | ||
|
||
.addToCart { | ||
margin: 2rem 0 0 0; | ||
} | ||
} | ||
} | ||
} | ||
} |
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,31 +1,40 @@ | ||
.userProfile { | ||
display: block; | ||
width: 100%; | ||
margin: 3rem auto 1rem; | ||
display: block; | ||
width: 100%; | ||
margin: 3rem auto 1rem; | ||
|
||
ul, li { | ||
margin: 0; | ||
padding: 0; | ||
list-style-type: none; | ||
} | ||
ul { | ||
li{ | ||
display: block; | ||
width: 100%; | ||
.img{ | ||
display: block; | ||
width: 5.0rem; | ||
margin: 0 auto; | ||
} | ||
} | ||
.displayName { | ||
display: block; | ||
width: 100%; | ||
text-align: center; | ||
margin: 1rem auto; | ||
font-size: 1.8rem; | ||
line-height: 1; | ||
text-transform: uppercase; | ||
ul, | ||
li { | ||
margin: 0; | ||
padding: 0; | ||
list-style-type: none; | ||
} | ||
|
||
ul { | ||
li { | ||
display: block; | ||
width: 100%; | ||
|
||
.img { | ||
display: block; | ||
width: 5rem; | ||
margin: 0 auto; | ||
|
||
img { | ||
display: block; | ||
width: 100%; | ||
} | ||
} | ||
|
||
.displayName { | ||
display: block; | ||
width: 100%; | ||
text-align: center; | ||
margin: 1rem auto; | ||
font-size: 1.8rem; | ||
line-height: 1; | ||
text-transform: uppercase; | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.