UNPKG

@open-tender/store

Version:

A library of hooks, reducers, utility functions, and types for use with Open Tender applications that utilize our in-store POS API

54 lines (53 loc) 3.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var utils_1 = require("@open-tender/utils"); var react_1 = require("react"); var hooks_1 = require("../app/hooks"); var slices_1 = require("../slices"); var CategoryItem = function (_a) { var item = _a.item, favorite = _a.favorite, allergenAlerts = _a.allergenAlerts, placeholder = _a.placeholder, index = _a.index, navigate = _a.navigate, children = _a.children; var dispatch = (0, hooks_1.useAppDispatch)(); var apiUrl = (0, hooks_1.useAppSelector)(slices_1.selectKioskApi); var config = (0, hooks_1.useAppSelector)(slices_1.selectKioskConfig).categoryItem; var _b = (0, hooks_1.useAppSelector)(slices_1.selectStoreSettings), display_cals = _b.display_cals, navigation_page = _b.navigation_page, display_descriptions = _b.display_descriptions; var soldOut = (0, hooks_1.useAppSelector)(slices_1.selectMenu).soldOut; var cartCounts = (0, hooks_1.useAppSelector)(slices_1.selectCartCounts); var pointsProgram = (0, hooks_1.useAppSelector)(slices_1.selectPointsProgram); var hasPoints = !!pointsProgram; var displaySettings = {}; var _c = displaySettings || {}, _d = _c.calories, showCals = _d === void 0 ? false : _d, _e = _c.tags, showTags = _e === void 0 ? false : _e, _f = _c.allergens, showAllergens = _f === void 0 ? false : _f; var showDesc = 'SHOW'; var orderItem = (0, react_1.useMemo)(function () { return favorite ? tslib_1.__assign(tslib_1.__assign({}, (0, utils_1.rehydrateOrderItem)(item, favorite.item)), { index: -1 }) : (0, utils_1.makeOrderItem)(item, undefined, soldOut, undefined, hasPoints); }, [favorite, hasPoints, item, soldOut]); var cartItem = (0, utils_1.useOrderItem)(orderItem, favorite, allergenAlerts, cartCounts, showCals, showTags, showAllergens, showDesc); var handlers = (0, react_1.useMemo)(function () { var browse = function () { dispatch((0, slices_1.setCurrentItem)(cartItem)); navigate('/menu/item'); }; return { browse: browse }; }, [navigate, dispatch, cartItem]); if (!config) return null; return children({ item: cartItem, config: config, handlers: handlers, apiUrl: apiUrl, placeholder: placeholder, index: index, displayCals: display_cals, navigationType: navigation_page, displayDescription: display_descriptions }); }; exports.default = (0, react_1.memo)(CategoryItem, areEqualProps); function areEqualProps(oldProps, newProps) { var _a, _b, _c, _d; return (oldProps.item.id === newProps.item.id && ((_a = oldProps.favorite) === null || _a === void 0 ? void 0 : _a.item.id) === ((_b = newProps.favorite) === null || _b === void 0 ? void 0 : _b.item.id) && ((_c = oldProps.allergenAlerts) === null || _c === void 0 ? void 0 : _c.length) === ((_d = newProps.allergenAlerts) === null || _d === void 0 ? void 0 : _d.length)); }