summaryrefslogtreecommitdiffstats
path: root/frontend/components/Item.js
diff options
context:
space:
mode:
authorWes Bos <wesbos@gmail.com>2018-02-08 10:41:16 -0500
committerWes Bos <wesbos@gmail.com>2018-02-08 10:41:16 -0500
commit19c9683e2126c68cb9d231293162c756d69c51fb (patch)
tree4679ca2dee47740aa0bf6fe623513c4242e027e6 /frontend/components/Item.js
parenteabff7cd396d1f37ceb929e666f082ce57f07919 (diff)
WIP
Diffstat (limited to 'frontend/components/Item.js')
-rw-r--r--frontend/components/Item.js114
1 files changed, 55 insertions, 59 deletions
diff --git a/frontend/components/Item.js b/frontend/components/Item.js
index eb19918..d19af0e 100644
--- a/frontend/components/Item.js
+++ b/frontend/components/Item.js
@@ -1,10 +1,13 @@
-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";
+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;
@@ -14,60 +17,53 @@ const Item = styled.div`
}
`;
-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>
+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>
- {/* {
+ <p>{item.description}</p>
- <Link
- href={{
- pathname: '/admin/update',
- query: { id: item.id },
- }}
- >
- <a>Edit ✏️</a>
- </Link>
+ <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>
- <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>
-);
+ {/* <AddToCart id={item.id} /> */}
+ <button onClick={this.removeItem}>&times; Delete item</button>
+ </Item>
+ );
+ }
+}
-export default ItemComponent;
+export default compose(removeItemMutation)(ItemComponent);