import React from "react"; import "../../common/styles/productRow.css"; import { API } from "aws-amplify"; import StarRating from "../../common/starRating/StarRating"; import FriendRecommendations from "../../common/friendRecommendations/FriendRecommendations"; // import { Glyphicon } from "react-bootstrap"; import { Book } from "../bestSellers/BestSellerProductRow"; export interface Order { bookId: string; quantity: number; price: number } interface CartProductRowProps { order: Order; calculateTotal: () => void; } interface CartProductRowState { book: Book | undefined; removeLoading: boolean; } export class CartProductRow extends React.Component { constructor(props: CartProductRowProps) { super(props); this.state = { book: undefined, removeLoading: false }; } async componentDidMount() { try { const book = await this.getBook(this.props.order); this.setState({ book }); } catch (e) { alert(e); } } getBook(order: Order) { return API.get("books", `/books/${order.bookId}`, null); } onRemove = async () => { this.setState({ removeLoading: true }); await API.del("cart", "/cart", { body: { bookId: this.props.order.bookId, } }); this.props.calculateTotal(); } onQuantityUpdated = async (event: any) => { await API.put("cart", "/cart", { body: { bookId: this.props.order.bookId, quantity: parseInt(event.target.value, 10) } }); } render() { if (!this.state.book) return null; return (
{`${this.state.book.name}

{this.state.book.name}
${this.state.book.price}

{this.state.book.category}

Rating

); } } export default CartProductRow;