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

25 lines (24 loc) 1.07 kB
import { useAppDispatch, useAppSelector } from '../app/hooks'; import { removeDiscount, selectKioskConfig, selectPosCheckout } from '../slices'; var CheckoutPromoCode = function (_a) { var showModal = _a.showModal, children = _a.children; var dispatch = useAppDispatch(); var config = useAppSelector(selectKioskConfig).checkoutPromoCode; var check = useAppSelector(selectPosCheckout).check; var discounts = (check || {}).discounts; var discount = discounts === null || discounts === void 0 ? void 0 : discounts.find(function (i) { return i.is_promo_code; }); var _b = discount || {}, id = _b.id, _c = _b.name, promoCode = _c === void 0 ? null : _c; var add = function () { return showModal(true); }; var remove = function () { if (id) dispatch(removeDiscount({ id: id })); }; var handlers = { add: add, remove: remove }; if (!config || !check) return null; return children({ config: config, handlers: handlers, promoCode: promoCode }); }; export default CheckoutPromoCode;