@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
40 lines (39 loc) • 1.78 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = require("react");
var hooks_1 = require("../app/hooks");
var slices_1 = require("../slices");
var endpoints = [
'ACCOUNT',
'DEALS',
'FAVORITES',
'ORDERS',
'GIFT_CARDS',
'LOYALTY',
'REWARDS'
];
var SignIn = function (_a) {
var setSignInType = _a.setSignInType, _b = _a.greeting, greeting = _b === void 0 ? 'Hi there' : _b, _c = _a.punctuation, punctuation = _c === void 0 ? '!' : _c, navigate = _a.navigate, children = _a.children;
var dispatch = (0, hooks_1.useAppDispatch)();
var _d = (0, hooks_1.useAppSelector)(slices_1.selectKioskConfig), config = _d.signIn, buttonLinkConfig = _d.buttonLink;
var customer = ((0, hooks_1.useAppSelector)(slices_1.selectCustomerIdentified) || {}).customer;
var _e = customer || {}, customerId = _e.customer_id, first_name = _e.first_name;
var msg = customer ? "".concat(greeting, ", ").concat(first_name).concat(punctuation) : null;
var signOut = function () {
dispatch((0, slices_1.resetCustomerIdentify)());
dispatch((0, slices_1.resetCustomer)());
dispatch((0, slices_1.resetMenu)());
setSignInType(null);
};
var goToAccount = function () { return navigate('/account'); };
var handlers = { goToAccount: goToAccount, setSignInType: setSignInType, signOut: signOut };
(0, react_1.useEffect)(function () {
if (customerId) {
dispatch((0, slices_1.fetchCustomer)({ customerId: customerId, endpoints: endpoints }));
}
}, [dispatch, customerId]);
if (!config)
return null;
return children({ config: config, handlers: handlers, msg: msg, buttonLinkConfig: buttonLinkConfig });
};
exports.default = SignIn;