@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
48 lines (47 loc) • 2.18 kB
JavaScript
import { makeImageUrl } from '@open-tender/ui';
import { useCallback } from 'react';
import { useAppDispatch, useAppSelector } from '../app/hooks';
import { selectCurrentSection, selectKioskApi, selectKioskConfig, selectMenu, setCurrentCategory } from '../slices';
var CategoryNavOther = function (_a) {
var title = _a.title, path = _a.path, displayImage = _a.displayImage, navigationType = _a.navigationType, navigate = _a.navigate, children = _a.children;
var dispatch = useAppDispatch();
var apiUrl = useAppSelector(selectKioskApi);
var _b = useAppSelector(selectKioskConfig), categoryNavItem = _b.categoryNavItem, categoryNavItemSelected = _b.categoryNavItemSelected;
var currentSection = useAppSelector(selectCurrentSection);
var isCurrent = path === currentSection;
var config = isCurrent ? categoryNavItemSelected : categoryNavItem;
var _c = useAppSelector(selectMenu), _d = _c.featured, featured = _d === void 0 ? [] : _d, _e = _c.favorites, favorites = _e === void 0 ? [] : _e, _f = _c.recents, recents = _f === void 0 ? [] : _f;
var getCategoryItemImage = useCallback(function () {
switch (title.toLowerCase()) {
case 'featured':
return featured.length && featured.length > 0
? makeImageUrl(featured[0])
: null;
case 'favorites':
return favorites.length && favorites.length > 0
? makeImageUrl(favorites[0])
: null;
default:
return recents.length && recents.length > 0
? makeImageUrl(recents[0])
: null;
}
}, [favorites, featured, title, recents]);
var browse = function () {
dispatch(setCurrentCategory(null));
navigate(path);
};
var handlers = { browse: browse };
if (!config)
return null;
return children({
config: config,
handlers: handlers,
title: title,
imageUrl: getCategoryItemImage(),
apiUrl: apiUrl,
displayImage: displayImage,
navigationType: navigationType
});
};
export default CategoryNavOther;