1
1
import React from 'react' ;
2
2
import { Link } from 'react-router-dom' ;
3
+ import PropTypes from 'prop-types' ;
3
4
import FarmerAvatar from '../../Images/FarmerAvatar.png' ;
4
5
import './FarmListItem.css' ;
5
6
6
7
export default function FarmListItem ( props ) {
7
- const farm = props . info ;
8
- const profile = farm . profile_image ? farm . profile_image : FarmerAvatar ;
8
+ const { info } = props ;
9
+ const {
10
+ id,
11
+ farm_name : farmName ,
12
+ products,
13
+ profile_image : profileImage ,
14
+ } = info ;
15
+ const profile = profileImage || FarmerAvatar ;
9
16
return (
10
17
< div className = "farm-list-item" >
11
18
< div className = "farm-list-item__img--container" >
12
- < Link to = { `/farms/${ farm . id } ` } >
13
- < img
14
- className = "farm-list-item__img"
15
- src = { profile }
16
- alt = "farm avatar" />
19
+ < Link to = { `/farms/${ id } ` } >
20
+ < img
21
+ className = "farm-list-item__img"
22
+ src = { profile }
23
+ alt = "farm avatar"
24
+ />
17
25
</ Link >
18
26
</ div >
19
27
< div className = "farm-list-item__info--container" >
20
28
< h4 className = "farm-list-item__title" >
21
- < Link to = { `/farms/${ farm . id } ` } >
22
- { farm . farm_name }
29
+ < Link to = { `/farms/${ id } ` } >
30
+ { farmName }
23
31
</ Link >
24
32
</ h4 >
25
33
< div className = "farm-list-item__products" >
26
- { farm . products . join ( ', ' ) }
34
+ { products . join ( ', ' ) }
27
35
</ div >
28
36
</ div >
29
37
</ div >
@@ -36,6 +44,16 @@ FarmListItem.defaultProps = {
36
44
profile_image : '' ,
37
45
farm_name : '' ,
38
46
products : [ ] ,
39
- id : '' ,
47
+ id : 0 ,
40
48
} ,
41
49
} ;
50
+
51
+ FarmListItem . propTypes = {
52
+ info : PropTypes . shape ( {
53
+ farm_description : PropTypes . string ,
54
+ profile_image : PropTypes . string ,
55
+ farm_name : PropTypes . string ,
56
+ products : PropTypes . array ,
57
+ id : PropTypes . number ,
58
+ } ) ,
59
+ } ;
0 commit comments