@@ -2,7 +2,9 @@ import React, { useEffect } from 'react';
22import { connect , ConnectedProps } from 'react-redux' ;
33import { getProduct } from './Product.thunks' ;
44import { 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
79const mapStateToProps = ( state : AppState ) => ( {
810 product : state . products . product ,
@@ -18,23 +20,51 @@ interface Props extends ConnectedProps<typeof connector> {}
1820
1921export 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} ;
4070export const ProductItem = connector ( _ProductItem ) ;
0 commit comments