@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
52 lines (51 loc) • 2.89 kB
JavaScript
import { __assign } from "tslib";
import { makeOrderItem, rehydrateOrderItem, useOrderItem } from '@open-tender/utils';
import { memo, useMemo } from 'react';
import { useAppDispatch, useAppSelector } from '../app/hooks';
import { selectCartCounts, selectKioskApi, selectKioskConfig, selectMenu, selectPointsProgram, selectStoreSettings, setCurrentItem } from '../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 = useAppDispatch();
var apiUrl = useAppSelector(selectKioskApi);
var config = useAppSelector(selectKioskConfig).categoryItem;
var _b = useAppSelector(selectStoreSettings), display_cals = _b.display_cals, navigation_page = _b.navigation_page, display_descriptions = _b.display_descriptions;
var soldOut = useAppSelector(selectMenu).soldOut;
var cartCounts = useAppSelector(selectCartCounts);
var pointsProgram = useAppSelector(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 = useMemo(function () {
return favorite
? __assign(__assign({}, rehydrateOrderItem(item, favorite.item)), { index: -1 }) : makeOrderItem(item, undefined, soldOut, undefined, hasPoints);
}, [favorite, hasPoints, item, soldOut]);
var cartItem = useOrderItem(orderItem, favorite, allergenAlerts, cartCounts, showCals, showTags, showAllergens, showDesc);
var handlers = useMemo(function () {
var browse = function () {
dispatch(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
});
};
export default 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));
}