-
Notifications
You must be signed in to change notification settings - Fork 417
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…
…duct - update UI
- Loading branch information
Chinh Duong
committed
Oct 10, 2024
1 parent
f7259c8
commit ff5d081
Showing
6 changed files
with
116 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
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,52 @@ | ||
import clsx from 'clsx'; | ||
import Link from 'next/link'; | ||
import { useLayoutEffect, useState } from 'react'; | ||
|
||
import { getMediaById } from '@/modules/media/services/MediaService'; | ||
import { ProductThumbnail } from 'modules/catalog/models/ProductThumbnail'; | ||
import { formatPrice } from 'utils/formatPrice'; | ||
import ImageWithFallBack from './ImageWithFallback'; | ||
|
||
import styles from 'styles/ProductCard.module.css'; | ||
|
||
export interface Props { | ||
product: ProductThumbnail; | ||
thumbnailUrl?: string; | ||
className?: string[]; | ||
} | ||
|
||
export default function SimilarProductCard({ product, className, thumbnailUrl }: Props) { | ||
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> | ||
); | ||
} |
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,47 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { Col, Row } from 'react-bootstrap'; | ||
|
||
import SimilarProductCard from '@/common/components/SimilarProductCard'; | ||
import { ProductThumbnail } from '../models/ProductThumbnail'; | ||
import { getSimilarProductsByProductId } from '../services/ProductService'; | ||
|
||
type SimilarProductProps = { | ||
productId: number; | ||
}; | ||
|
||
const SimilarProduct = ({ productId }: SimilarProductProps) => { | ||
const [products, setProducts] = useState<ProductThumbnail[]>([]); | ||
|
||
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"> | ||
<h4 className="mb-2 text-black">Similar Products</h4> | ||
{products.length > 0 && ( | ||
<Row md={5}> | ||
{products.map((product) => ( | ||
<Col key={product.id}> | ||
<SimilarProductCard | ||
product={product} | ||
thumbnailUrl={product && product.thumbnail && product.thumbnail.url ? product.thumbnail.url : ''} | ||
/> | ||
</Col> | ||
))} | ||
</Row> | ||
)} | ||
|
||
{products.length === 0 && <p className="mt-4">No product</p>} | ||
</div> | ||
); | ||
}; | ||
|
||
export default SimilarProduct; |
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 SimilarProduct from './SimilarProduct'; | ||
|
||
export { DetailHeader, ProductDetails, RelatedProduct }; | ||
export { DetailHeader, ProductDetails, RelatedProduct, SimilarProduct}; |
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