From b1600adec47a04f60e1da07d94a3ed3906ff5aee Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Thu, 14 Jun 2018 16:44:21 -0400 Subject: starter files --- .../frontend/components/OrderList.js | 93 ++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 finished-application/frontend/components/OrderList.js (limited to 'finished-application/frontend/components/OrderList.js') diff --git a/finished-application/frontend/components/OrderList.js b/finished-application/frontend/components/OrderList.js new file mode 100644 index 0000000..5886ad7 --- /dev/null +++ b/finished-application/frontend/components/OrderList.js @@ -0,0 +1,93 @@ +import React from 'react'; +import { Query } from 'react-apollo'; +import { formatDistance } from 'date-fns'; +import Link from 'next/link'; +import styled from 'styled-components'; +import gql from 'graphql-tag'; +import formatMoney from '../lib/formatMoney'; +import OrderItemStyles from './styles/OrderItemStyles'; + +const USER_ORDERS_QUERY = gql` + query orders { + orders(orderBy: createdAt_DESC) { + id + total + createdAt + updatedAt + items { + id + title + price + description + quantity + image + } + } + } +`; + +const OrderUl = styled.ul` + display: grid; + grid-gap: 4rem; + grid-template-columns: repeat(auto-fit, minmax(40%, 1fr)); +`; + +class OrderList extends React.Component { + render() { + return ( + + {({ data: { orders }, loading, error }) => { + if (loading) return

Loading...

; + if (error) return

Error...

; + if (!orders || !orders.length) return

No Orders Yet!

; + return ( +
+

You have {orders.length} Orders

+ + {orders.map(order => ( + + + +
+

+ {order.items.reduce((a, b) => a + b.quantity, 0)} + Items +

+

+ {order.items.length} + Products +

+

+ {formatDistance(order.createdAt, new Date())} + ago +

+

+ {formatMoney(order.total)} + Total +

+
+
+ {order.items.map(item => ( + {item.title} + ))} +
+
+ +
+ ))} +
+
+ ); + }} +
+ ); + } +} + +export default OrderList; +export { USER_ORDERS_QUERY }; -- cgit v1.3