import React, { Component } from "react"; import { CategoryNavBar } from "../category/categoryNavBar/CategoryNavBar"; import { SearchBar } from "../search/searchBar/SearchBar"; import "../../common/hero/hero.css"; import { PurchasedProductRow } from "./PurchasedProductRow"; import { Auth, API } from "aws-amplify"; import bestSellers from "../../images/bestSellers.png"; import yourshoppingcart from "../../images/yourshoppingcart.png"; import { Order } from "../cart/CartProductRow"; interface PastPurchasesProps {} interface Purchases { orderDate: number; orderId: string; books: Order[]; } interface PastPurchasesState { userInfo: any; // FIXME isLoading: boolean; orders: Purchases[]; } export default class PastPurchases extends Component { constructor(props: PastPurchasesProps) { super(props); this.state = { userInfo: null, isLoading: true, orders: [] }; } async componentDidMount() { const userInfo = await Auth.currentUserInfo(); this.setState({ userInfo }) try { const orders = await this.listOrders(); this.setState({ orders: orders, isLoading: false }); } catch (e) { alert(e); } } listOrders() { return API.get("orders", "/orders", null); } getPrettyDate = (orderDate: number) => { const date = new Date(orderDate); return `${date.getMonth()}/${date.getDate()}/${date.getFullYear()} ${date.getHours()}:${date.getMinutes() < 10 ? '0' : ''}${date.getMinutes()}` } render() { return (
{this.state.userInfo &&

{`Hello ${this.state.userInfo.attributes.email}!`}

}

Past purchases

{!this.state.isLoading && this.state.orders && this.state.orders .sort((order1, order2) => order2.orderDate - order1.orderDate) .map(order =>

{`Order date: ${this.getPrettyDate(order.orderDate)}`}

{order.books.map((book) => )}
) }
Best sellers Shopping cart
); } }