Skip to content

Instantly share code, notes, and snippets.

@blakedietz
Created January 21, 2019 18:29
Show Gist options
  • Save blakedietz/ad26add7de3d55a126d2418faec80f52 to your computer and use it in GitHub Desktop.
Save blakedietz/ad26add7de3d55a126d2418faec80f52 to your computer and use it in GitHub Desktop.
Discussing which implementations are better and why
const selectedOrderlines = Object.entries(productQuantities)
.filter(([, value]) => value !== '')
.map(([productId, qty]) => {
const quantity = Number(qty)
return {
branchQuantities: branchId !== undefined ? [{ branchId, quantity }] : undefined,
productId: Number(productId),
qty: quantity,
}
})
const [showSelectionsToCart, hideSelectionsToCart] = useModal(() => (
<AddToCart
addType="Selections"
onCancel={hideSelectionsToCart}
orderlinesToAdd={selectedOrderlines}
resetQuantities={resetQuantities}
/>
function getOrderlines() {
return Object.entries(productQuantities).map(([productId, qty]) => {
const quantity = Number(qty)
return {
...(branchId !== undefined && { branchQuantities: [{ branchId, quantity }] }),
productId: Number(productId),
qty: quantity,
}
})
}
const [showSelectionsToCart, hideSelectionsToCart] = useModal(() => {
const orderlines = getOrderlines().filter(_ => _.qty !== 0)
return (
<AddToCart
addType="Selections"
onCancel={hideSelectionsToCart}
orderlinesToAdd={orderlines}
resetQuantities={resetQuantities}
/>
)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment