@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
44 lines (43 loc) • 1.75 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 SignInButton = function (_a) {
var navigate = _a.navigate, children = _a.children, pathname = _a.pathname;
var dispatch = (0, hooks_1.useAppDispatch)();
var config = (0, hooks_1.useAppSelector)(slices_1.selectKioskConfig).signInButton;
var customer = ((0, hooks_1.useAppSelector)(slices_1.selectCustomerIdentified) || {}).customer;
var account = (0, hooks_1.useAppSelector)(slices_1.selectCustomer).account;
var customerId = (customer || {}).customer_id;
var isAccount = pathname.includes('account');
var shouldFetch = !!(customerId && !account && !isAccount);
var signIn = function () {
dispatch((0, slices_1.openModal)({ type: 'SIGN_IN' }));
};
var signOut = function () {
dispatch((0, slices_1.resetCustomerIdentify)());
dispatch((0, slices_1.resetCustomer)());
dispatch((0, slices_1.resetMenu)());
};
var goToAccount = function () { return navigate('/account'); };
var handlers = { signIn: signIn, signOut: signOut, goToAccount: goToAccount };
(0, react_1.useEffect)(function () {
if (shouldFetch) {
dispatch((0, slices_1.fetchCustomer)({ customerId: customerId, endpoints: endpoints }));
}
}, [dispatch, shouldFetch, customerId]);
if (!config)
return null;
return children({ config: config, handlers: handlers, customer: customer, isAccount: isAccount });
};
exports.default = SignInButton;