-
Notifications
You must be signed in to change notification settings - Fork 453
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1150 [Recommendation] Adjust product detail page to show similar pro… (
#1161) * #1150 [Recommendation] Adjust product detail page to show similar product - update UI * #1150 [Recommendation] Adjust product detail page to show similar product - Fix code review * #1150 [Recommendation] Adjust product detail page to show similar product - resolve conflict * #1150 [Recommendation] Adjust product detail page to show similar product - add default comment. --------- Co-authored-by: Chinh Duong <chinh.duongthi@harveynash.vn>
- Loading branch information
1 parent
be2a354
commit bd4576e
Showing
9 changed files
with
143 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import clsx from 'clsx'; | ||
import Link from 'next/link'; | ||
import { formatPrice } from 'utils/formatPrice'; | ||
import ImageWithFallBack from './ImageWithFallback'; | ||
|
||
import styles from 'styles/ProductCard.module.css'; | ||
|
||
interface ProductCardBaseProps { | ||
product: { | ||
name: string; | ||
price: number; | ||
slug: string; | ||
}; | ||
thumbnailUrl: string; | ||
className?: string[]; | ||
} | ||
|
||
const ProductCardBase: React.FC<ProductCardBaseProps> = ({ product, thumbnailUrl, className }) => { | ||
return ( | ||
<Link | ||
className={clsx( | ||
styles['product'], | ||
className?.map((item) => styles[item]) | ||
)} | ||
href={`/products/${product.slug}`} | ||
> | ||
<div className={styles['product-card']}> | ||
<div className={styles['image-wrapper']}> | ||
<ImageWithFallBack src={thumbnailUrl} alt={product.name} /> | ||
</div> | ||
<div className={styles['info-wrapper']}> | ||
<h3 className={styles['prod-name']}>{product.name}</h3> | ||
<div className={styles['rating-sold']}> | ||
<div className={styles['star']}> | ||
0 <i className="bi bi-star-fill"></i> | ||
</div>{' '} | ||
|{' '} | ||
<div className={styles['sold']}> | ||
0 <span>sold</span> | ||
</div> | ||
</div> | ||
|
||
<div className={styles['price']}>{formatPrice(product.price)}</div> | ||
|
||
<hr /> | ||
|
||
<div className={styles['delivery']}>Fast delivery 2 hours</div> | ||
</div> | ||
</div> | ||
</Link> | ||
); | ||
}; | ||
|
||
export default ProductCardBase; |
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,18 @@ | ||
import { SimilarProduct } from 'modules/catalog/models/SimilarProduct'; | ||
import ProductCardBase from './ProductCardBase'; | ||
|
||
export interface SimilarProductCardProps { | ||
product: SimilarProduct; | ||
thumbnailUrl?: string; | ||
className?: string[]; | ||
} | ||
|
||
export default function SimilarProductCard({ | ||
product, | ||
className, | ||
thumbnailUrl, | ||
}: Readonly<SimilarProductCardProps>) { | ||
return ( | ||
<ProductCardBase product={product} thumbnailUrl={thumbnailUrl ?? ''} className={className} /> | ||
); | ||
} |
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,43 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { Col, Row } from 'react-bootstrap'; | ||
|
||
import SimilarProductCard from '@/common/components/SimilarProductCard'; | ||
import { getSimilarProductsByProductId } from '../services/ProductService'; | ||
import { SimilarProduct } from '../models/SimilarProduct'; | ||
|
||
type SimilarProductProps = { | ||
productId: number; | ||
}; | ||
|
||
const SimilarProducts = ({ productId }: SimilarProductProps) => { | ||
const [products, setProducts] = useState<SimilarProduct[]>([]); | ||
|
||
useEffect(() => { | ||
fetchSimilarProducts(); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
const fetchSimilarProducts = () => { | ||
getSimilarProductsByProductId(productId) | ||
.then((response) => setProducts(response)) | ||
.catch((error) => console.log(error)); | ||
}; | ||
|
||
return ( | ||
<div className="my-5"> | ||
{products.length > 0 && ( | ||
<> | ||
<h4 className="mb-2 text-black">Similar Products</h4> | ||
<Row md={5}> | ||
{products.map((product) => ( | ||
<Col key={product.id}> | ||
<SimilarProductCard product={product} thumbnailUrl={product.thumbnail.url} /> | ||
</Col> | ||
))} | ||
</Row> | ||
</> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default SimilarProducts; |
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,5 +1,6 @@ | ||
import DetailHeader from './DetailHeader'; | ||
import ProductDetails from './ProductDetails'; | ||
import RelatedProduct from './RelatedProducts'; | ||
import SimilarProducts from './SimilarProducts'; | ||
|
||
export { DetailHeader, ProductDetails, RelatedProduct }; | ||
export { DetailHeader, ProductDetails, RelatedProduct, SimilarProducts }; |
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,10 @@ | ||
export type SimilarProduct = { | ||
id: number; | ||
name: string; | ||
slug: string; | ||
price: number; | ||
thumbnail: { | ||
id: number; | ||
url: string; | ||
}; | ||
}; |
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