Skip to content

Commit cfc9633

Browse files
committed
Update product item page
1 parent 4868573 commit cfc9633

File tree

5 files changed

+55
-25
lines changed

5 files changed

+55
-25
lines changed

server/db/db.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,49 +27,49 @@
2727
"products": [{
2828
"id": "iphone-8-plus",
2929
"name": "Iphone 8 Plus",
30-
"image_url": "./images/iphone-8-plus.jpg",
30+
"image_url": "/images/iphone-8-plus.jpg",
3131
"brand": "APPLE"
3232
},
3333
{
3434
"id": "iphone-11-pro-max",
3535
"name": "Iphone 11 Pro Max",
36-
"image_url": "./images/iphone-11-pro-max.jpg",
36+
"image_url": "/images/iphone-11-pro-max.jpg",
3737
"brand": "APPLE"
3838
},
3939
{
4040
"id": "iphone-11-pro",
4141
"name": "Iphone 11 Pro",
42-
"image_url": "./images/iphone-11-pro.jpg",
42+
"image_url": "/images/iphone-11-pro.jpg",
4343
"brand": "APPLE"
4444
},
4545
{
4646
"id": "iphone-11",
4747
"name": "Iphone 11",
48-
"image_url": "./images/iphone-11.jpg",
48+
"image_url": "/images/iphone-11.jpg",
4949
"brand": "APPLE"
5050
},
5151
{
5252
"id": "iphone-se",
5353
"name": "Iphone SE",
54-
"image_url": "./images/iphone-se.jpg",
54+
"image_url": "/images/iphone-se.jpg",
5555
"brand": "APPLE"
5656
},
5757
{
5858
"id": "iphone-x",
5959
"name": "Iphone X",
60-
"image_url": "./images/iphone-x.jpg",
60+
"image_url": "/images/iphone-x.jpg",
6161
"brand": "APPLE"
6262
},
6363
{
6464
"id": "iphone-xr",
6565
"name": "Iphone XR",
66-
"image_url": "./images/iphone-xr.jpg",
66+
"image_url": "/images/iphone-xr.jpg",
6767
"brand": "APPLE"
6868
},
6969
{
7070
"id": "iphone-xs-max",
7171
"name": "Iphone XS Max",
72-
"image_url": "./images/iphone-xs-max.jpg",
72+
"image_url": "/images/iphone-xs-max.jpg",
7373
"brand": "APPLE"
7474
}
7575
]

src/components/Error/404.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export const NotFound = () => {
1111
return (
1212
<div className="static-pages-section">
1313
<div className="container">
14-
<div className="block-title">
15-
<h2>
14+
<div className="block-title" style={{ color: '#fa8c16' }}>
15+
<h2 style={{ color: '#fa8c16' }}>
1616
<ExclamationOutlined />
1717
Page Not Found
1818
</h2>

src/components/Products/Product.thunks.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export const getProducts = () => async dispatch => {
1919

2020
export const getProduct = id => async dispatch => {
2121
try {
22-
console.log('Get Product triggered');
2322
const res = await axios.get(`${URL.baseAPIUrl}/api/products/${id}`);
2423
const product = res.data as Product;
2524
dispatch(actions.getProductSuccess(product));

src/components/Products/ProductItem.tsx

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import React, { useEffect } from 'react';
22
import { connect, ConnectedProps } from 'react-redux';
33
import { getProduct } from './Product.thunks';
44
import { useParams } from 'react-router-dom';
5-
import { Row, Col, Image } from 'antd';
5+
import { Row, Col, Image, Button } from 'antd';
6+
import { NotFound } from 'src/components/Error/404';
7+
import { useHistory } from 'react-router-dom';
68

79
const mapStateToProps = (state: AppState) => ({
810
product: state.products.product,
@@ -18,23 +20,51 @@ interface Props extends ConnectedProps<typeof connector> {}
1820

1921
export const _ProductItem = (props: Props) => {
2022
const { product, getProduct } = props;
23+
const history = useHistory();
24+
const goBack = () => {
25+
history.goBack();
26+
};
27+
28+
let productComponent = (item: Product) => {
29+
if (item) {
30+
return (
31+
<div className="product-item-section mt-2">
32+
<div className="container">
33+
<Row>
34+
<Col span={12}>
35+
<Image src={item.image_url} />
36+
</Col>
37+
<Col span={12}>
38+
<p>
39+
Name:{' '}
40+
<strong style={{ fontSize: '1.4rem' }}> {item.name}</strong>
41+
</p>
42+
<p>
43+
Brand: <strong>{item.brand}</strong>
44+
</p>
45+
</Col>
46+
</Row>
47+
<Row className="mt-2">
48+
<Col offset={12}>
49+
<Button type="primary" onClick={goBack}>
50+
Go Back
51+
</Button>
52+
</Col>
53+
</Row>
54+
</div>
55+
</div>
56+
);
57+
} else {
58+
return <NotFound />;
59+
}
60+
};
61+
2162
const params: Params = useParams();
2263
useEffect(() => {
2364
const { id } = params;
2465
getProduct(id);
2566
}, [params, getProduct]);
26-
return (
27-
<div className="container">
28-
<Row>
29-
<Col span={12}>
30-
<Image src={product.image_url} />
31-
</Col>
32-
<Col span={8} offset={4}>
33-
<h2>Name: {product.name}</h2>
34-
<p>Brand: {product.brand}</p>
35-
</Col>
36-
</Row>
37-
</div>
38-
);
67+
68+
return productComponent(product);
3969
};
4070
export const ProductItem = connector(_ProductItem);

src/pages/ErrorPages/404Pages.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ const _NotFoundPage = () => {
1010
);
1111
};
1212
const NotFoundPage = React.memo(_NotFoundPage);
13+
export { NotFoundPage };
1314
export default NotFoundPage;

0 commit comments

Comments
 (0)