@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
38 lines (37 loc) • 1.7 kB
JavaScript
import { useEffect } from 'react';
import { useAppDispatch, useAppSelector } from '../app/hooks';
import { fetchCustomer, resetCustomer, resetCustomerIdentify, resetMenu, selectCustomerIdentified, selectKioskConfig } from '../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 = useAppDispatch();
var _d = useAppSelector(selectKioskConfig), config = _d.signIn, buttonLinkConfig = _d.buttonLink;
var customer = (useAppSelector(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(resetCustomerIdentify());
dispatch(resetCustomer());
dispatch(resetMenu());
setSignInType(null);
};
var goToAccount = function () { return navigate('/account'); };
var handlers = { goToAccount: goToAccount, setSignInType: setSignInType, signOut: signOut };
useEffect(function () {
if (customerId) {
dispatch(fetchCustomer({ customerId: customerId, endpoints: endpoints }));
}
}, [dispatch, customerId]);
if (!config)
return null;
return children({ config: config, handlers: handlers, msg: msg, buttonLinkConfig: buttonLinkConfig });
};
export default SignIn;