Created
January 21, 2019 18:29
-
-
Save blakedietz/ad26add7de3d55a126d2418faec80f52 to your computer and use it in GitHub Desktop.
Discussing which implementations are better and why
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | |
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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