blob: 2a0fc69168f4e7ecae00eac88aff03a8001f0680 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
import React from 'react';
import styled from 'styled-components';
import slugify from 'slugify';
import { compose } from 'react-apollo';
import { Link } from '../routes';
import AddToCart from './AddToCart';
import makeImage from '../lib/image';
import TakeMyMoney from './TakeMyMoney';
import formatMoney from '../lib/formatMoney';
import { removeItemMutation } from '../enhancers/enhancers';
const Item = styled.div`
background: #f3f3f3;
padding: 5px;
img {
width: 100%;
}
`;
class ItemComponent extends React.Component {
removeItem = () => {
this.props.removeItem({ variables: { id: this.props.item.id } });
};
render() {
const item = this.props.item;
return (
<Item key={item.id}>
{item.image ? <img key={item.image.secret} src={makeImage(item.image)} alt={item.title} /> : null}
<h3>
<Link
route="item"
params={{
slug: slugify(item.title),
itemId: item.id,
}}
>
<a>{item.title}</a>
</Link>
</h3>
<p>{item.description}</p>
<Link
href={{
pathname: '/admin/update',
query: { id: item.id },
}}
>
<a>Edit ✏️</a>
</Link>
<TakeMyMoney
id={item.id}
amount={item.price}
name={item.title} // the pop-in header title
description={item.description} // the pop-in header subtitle
image={makeImage(item.image)}
>
<button>Buy for {formatMoney(item.price)}</button>
</TakeMyMoney>
<AddToCart id={item.id} />
<button onClick={this.removeItem}>× Delete item</button>
</Item>
);
}
}
export default compose(removeItemMutation)(ItemComponent);
|