From 9876e7dfca6fa2bbf6ac383eeb8e2c82e05c2164 Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Wed, 22 Aug 2018 16:47:49 -0400 Subject: orders --- stepped-solutions/50/frontend/components/Cart.js | 64 ++++++++++++++++++++++ .../50/frontend/components/TakeMyMoney.js | 43 +++++++++++++++ 2 files changed, 107 insertions(+) create mode 100755 stepped-solutions/50/frontend/components/Cart.js create mode 100755 stepped-solutions/50/frontend/components/TakeMyMoney.js (limited to 'stepped-solutions/50/frontend/components') diff --git a/stepped-solutions/50/frontend/components/Cart.js b/stepped-solutions/50/frontend/components/Cart.js new file mode 100755 index 0000000..7dafeef --- /dev/null +++ b/stepped-solutions/50/frontend/components/Cart.js @@ -0,0 +1,64 @@ +import React from 'react'; +import { Query, Mutation } from 'react-apollo'; +import gql from 'graphql-tag'; +import { adopt } from 'react-adopt'; +import User from './User'; +import CartStyles from './styles/CartStyles'; +import Supreme from './styles/Supreme'; +import CloseButton from './styles/CloseButton'; +import SickButton from './styles/SickButton'; +import CartItem from './CartItem'; +import calcTotalPrice from '../lib/calcTotalPrice'; +import formatMoney from '../lib/formatMoney'; +import TakeMyMoney from './TakeMyMoney'; + +const LOCAL_STATE_QUERY = gql` + query { + cartOpen @client + } +`; + +const TOGGLE_CART_MUTATION = gql` + mutation { + toggleCart @client + } +`; +/* eslint-disable */ +const Composed = adopt({ + user: ({ render }) => {render}, + toggleCart: ({ render }) => {render}, + localState: ({ render }) => {render}, +}); +/* eslint-enable */ + +const Cart = () => ( + + {({ user, toggleCart, localState }) => { + const me = user.data.me; + if (!me) return null; + return ( + +
+ + × + + {me.name}'s Cart +

+ You Have {me.cart.length} Item{me.cart.length === 1 ? '' : 's'} in your cart. +

+
+
    {me.cart.map(cartItem => )}
+
+

{formatMoney(calcTotalPrice(me.cart))}

+ + Checkout + +
+
+ ); + }} +
+); + +export default Cart; +export { LOCAL_STATE_QUERY, TOGGLE_CART_MUTATION }; diff --git a/stepped-solutions/50/frontend/components/TakeMyMoney.js b/stepped-solutions/50/frontend/components/TakeMyMoney.js new file mode 100755 index 0000000..424b024 --- /dev/null +++ b/stepped-solutions/50/frontend/components/TakeMyMoney.js @@ -0,0 +1,43 @@ +import React from 'react'; +import StripeCheckout from 'react-stripe-checkout'; +import { Mutation } from 'react-apollo'; +import Router from 'next/router'; +import NProgress from 'nprogress'; +import PropTypes from 'prop-types'; +import gql from 'graphql-tag'; +import calcTotalPrice from '../lib/calcTotalPrice'; +import Error from './ErrorMessage'; +import User, { CURRENT_USER_QUERY } from './User'; + +function totalItems(cart) { + return cart.reduce((tally, cartItem) => tally + cartItem.quantity, 0); +} + +class TakeMyMoney extends React.Component { + onToken = res => { + console.log('On Token Called!'); + console.log(res.id); + }; + render() { + return ( + + {({ data: { me } }) => ( + this.onToken(res)} + > + {this.props.children} + + )} + + ); + } +} + +export default TakeMyMoney; -- cgit v1.3