({ pack, currentUserId, deletePack })
| 15 | } |
| 16 | |
| 17 | const PackItem: React.FC<Props & RouteComponentProps> = ({ pack, currentUserId, deletePack }) => { |
| 18 | const { id, title } = pack; |
| 19 | |
| 20 | const metadata = () => { |
| 21 | const { duration, duration_unit, season, itemCount } = pack; |
| 22 | const durationDisplay = !!duration && <div>{duration} {duration_unit}</div>; |
| 23 | const seasonDisplay = !!season && <div>{season}</div>; |
| 24 | return ( |
| 25 | <Metadata> |
| 26 | <div>{itemCount} Items</div> |
| 27 | {durationDisplay} |
| 28 | {seasonDisplay} |
| 29 | </Metadata> |
| 30 | ) |
| 31 | }; |
| 32 | |
| 33 | const handleDelete = () => { |
| 34 | if (deletePack) { |
| 35 | deletePack(pack.id); |
| 36 | } |
| 37 | }; |
| 38 | |
| 39 | const userOptions = () => { |
| 40 | if (pack.user.id !== currentUserId) { |
| 41 | return null; |
| 42 | } |
| 43 | |
| 44 | return ( |
| 45 | <UserOptions> |
| 46 | <Link to={getPackPath(id, title)}>view</Link> |
| 47 | <Link to={`/pack/${id}`}>edit</Link> |
| 48 | <Popconfirm title="Are you sure you want to delete this pack?" |
| 49 | okText="Delete" |
| 50 | placement="bottom" |
| 51 | onConfirm={handleDelete}> |
| 52 | <a href="#" className="remove-link">delete</a> |
| 53 | </Popconfirm> |
| 54 | </UserOptions> |
| 55 | ) |
| 56 | }; |
| 57 | |
| 58 | return ( |
| 59 | <PackWrapper> |
| 60 | <Link to={getPackPath(id, title)} className="pack-link"> |
| 61 | {title} |
| 62 | </Link> |
| 63 | {metadata()} |
| 64 | {userOptions()} |
| 65 | </PackWrapper> |
| 66 | ) |
| 67 | }; |
| 68 | |
| 69 | export default withRouter(PackItem); |
nothing calls this directly
no test coverage detected