summaryrefslogtreecommitdiffstats
path: root/frontend/components/Item.js
blob: eb19918592bb1fa6af3fa4cbc358e4812bdb2aab (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
70
71
72
73
import styled from "styled-components";
import slugify from "slugify";
import { Link } from "../routes";
import AddToCart from "./AddToCart";
import makeImage from "../lib/image";
import TakeMyMoney from "./TakeMyMoney";
import formatMoney from "../lib/formatMoney";

const Item = styled.div`
  background: #f3f3f3;
  padding: 5px;
  img {
    width: 100%;
  }
`;

const ItemComponent = ({ item }) => (
  <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.props.removeItemMutation({ variables: { id: item.id } })
      }
    >
      &times; Delete item
    </button>
  </Item>
);

export default ItemComponent;