You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
alanBtn({
key: '9298c5e0f50206b31f16ca738b3fb5a62e956eca572e1d8b807a3e2338fdd0dc/stage',
onCommand: (commandData) => {
// Whenever user says 'Show me the menu' we would like Alan-ai to return the menu
if(commandData.command === 'getMenu') {
setMenuItems(commandData.data);
} else if (commandData.command === 'addToCart') {
addToCart(commandData.data);
}
},
});
}, [])
<h2 className="menu_title">Menu</h2>
{menuItems.map((menuItem) => (
// key will be the 'name'
// This is the menu items that the user will see
<li key={menuItem.name} className="menu_list">
{menuItem.name} - ${menuItem.price} - {menuItem.category}
</li>
))}
5. Add items to the cart:
const addToCart = (menuItem) => {
setCart((oldCart) => {
// Return all the items from 'oldCart' + menuItems
// Spread operator: '...'
return [...oldCart, menuItem]
})
6. Mapping through cartItems (after added):
<h2 className="cart_title">Cart</h2>
{/* Mapping through 'cart items' */}
{cart.map((cartItem) => (
// This will the 'cart item' user will see
<li key={cartItem.name} className="menu_list">
{cartItem.name} - ${cartItem.price} - {cartItem.category}
</li>