Skip to content

Commit

Permalink
include best and worst scoring items tiles
Browse files Browse the repository at this point in the history
  • Loading branch information
JessNah committed May 23, 2021
1 parent 7924cd5 commit 8c8e684
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Extension/src/components/CheckoutDialog/CheckoutDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getCartAverageRating, getCart } from "../../stores/storesCommon"
import CheckoutCart from "./CheckoutCart/CheckoutCart"
import { productItem } from "../../utils/types"
import ItemDialogContent from "../ItemDialog/ItemDialogContent/ItemDialogContent"
import CheckoutDialogContent from "./CheckoutDialogContent/CheckoutDialogContent"

interface CheckoutDialogProps {
closeCheckoutDialog: () => void;
Expand Down Expand Up @@ -66,6 +67,8 @@ class CheckoutDialog extends Component<CheckoutDialogProps, CheckoutDialogState>
selectItem={(item) => {this.setState({openComparison: true, currentComparisonItem: item})}}
/>}
>
<CheckoutDialogContent
cart={this.state.cart}/>
</Tearsheet>
<TearsheetNarrow
open={this.state.openComparison}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.bx--tile {
background-color: white;
margin: 24px;
}

.take2--checkout-dialog-content-tile-header-wrapper {
display: inline-flex;
padding-bottom: 8px;
}

.take2--checkout-dialog-content-tile-header {
font-size: 1.25rem;
padding-left: 16px;
}

.take2--checkout-dialog-content-tile-score-wrapper {
display: flex;
}

.take2--checkout-dialog-content-tile-score {
padding-left: 24px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import React, { Component } from 'react'
import "./CheckoutDialogContent.scss"
import { Tile } from "carbon-components-react"
import { productItem } from "../../../utils/types"
import { Badge32, WarningAlt32 } from "@carbon/icons-react"

interface CheckoutDialogContentProps {
cart: productItem[],
}

interface CheckoutDialogContentState {
}


class CheckoutDialogContent extends Component<CheckoutDialogContentProps, CheckoutDialogContentState> {

getBestItem = (cart) => {
let bestItem: productItem = cart.length > 0 ? cart[0] : {score: 0, name:""};
for(let item of cart){
if(item.score > bestItem.score){
bestItem = item;
}
}
return bestItem;
}

getWorstItem = (cart) => {
let worstItem: productItem = cart.length > 0 ? cart[0] : {score: 0, name:""};
for(let item of cart){
if(item.score < worstItem.score){
worstItem = item;
}
}
return worstItem;
}

render() {
return (
<>
<Tile>
<div className={"take2--checkout-dialog-content-tile-header-wrapper"}>
<Badge32 />
<div className={"take2--checkout-dialog-content-tile-header"}>
{"Best scoring item"}
</div>
</div>
<div className={"take2--checkout-dialog-content-tile-score-wrapper "}>
<div>{this.getBestItem(this.props.cart).name}</div>
<div className={"take2--checkout-dialog-content-tile-score"}>
{this.getBestItem(this.props.cart).score}
</div>
</div>
</Tile>
<Tile>
<div className={"take2--checkout-dialog-content-tile-header-wrapper"}>
<WarningAlt32 />
<div className={"take2--checkout-dialog-content-tile-header"}>
{"Lowest scoring item"}
</div>
</div>
<div className={"take2--checkout-dialog-content-tile-score-wrapper "}>
<div>{this.getWorstItem(this.props.cart).name}</div>
<div className={"take2--checkout-dialog-content-tile-score"}>
{this.getWorstItem(this.props.cart).score}
</div>
</div>
</Tile>
</>
)
}
}

export default CheckoutDialogContent

0 comments on commit 8c8e684

Please sign in to comment.