@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
38 lines (37 loc) • 1.82 kB
JavaScript
import { makeImageUrl } from '@open-tender/ui';
import { useAppDispatch, useAppSelector } from '../app/hooks';
import { selectCurrentCategory, selectKioskApi, selectKioskConfig, selectStoreSettings, setCurrentCategory } from '../slices';
var CategoryNavItem = function (_a) {
var category = _a.category, isScrollable = _a.isScrollable, isActive = _a.isActive, displayImage = _a.displayImage, navigationType = _a.navigationType, index = _a.index, setItemLayout = _a.setItemLayout, children = _a.children, navigate = _a.navigate;
var dispatch = useAppDispatch();
var apiUrl = useAppSelector(selectKioskApi);
var display_category_nav_page = useAppSelector(selectStoreSettings).display_category_nav_page;
var current = useAppSelector(selectCurrentCategory);
var isCurrent = isActive || (current === null || current === void 0 ? void 0 : current.id) === category.id;
var _b = useAppSelector(selectKioskConfig), categoryNavItem = _b.categoryNavItem, categoryNavItemSelected = _b.categoryNavItemSelected;
var config = isCurrent ? categoryNavItemSelected : categoryNavItem;
var name = category.name;
var imageUrl = makeImageUrl(category);
var browse = function () {
dispatch(setCurrentCategory(category));
!isScrollable &&
navigate &&
navigate(display_category_nav_page ? '/menu/category' : '/menu');
};
var handlers = { browse: browse };
if (!config)
return null;
return children({
config: config,
handlers: handlers,
title: name,
imageUrl: imageUrl,
apiUrl: apiUrl,
disabled: isScrollable,
displayImage: displayImage,
navigationType: navigationType,
index: index,
setItemLayout: setItemLayout
});
};
export default CategoryNavItem;