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

27 lines (26 loc) 1.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var hooks_1 = require("../app/hooks"); var slices_1 = require("../slices"); var CheckoutPromoCode = function (_a) { var showModal = _a.showModal, children = _a.children; var dispatch = (0, hooks_1.useAppDispatch)(); var config = (0, hooks_1.useAppSelector)(slices_1.selectKioskConfig).checkoutPromoCode; var check = (0, hooks_1.useAppSelector)(slices_1.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((0, slices_1.removeDiscount)({ id: id })); }; var handlers = { add: add, remove: remove }; if (!config || !check) return null; return children({ config: config, handlers: handlers, promoCode: promoCode }); }; exports.default = CheckoutPromoCode;