@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
42 lines (41 loc) • 1.38 kB
JavaScript
import { useEffect } from 'react';
import { useAppDispatch, useAppSelector } from '../app/hooks';
import { fetchCustomer, openModal, resetCustomer, resetCustomerIdentify, resetMenu, selectCustomerIdentified, selectKioskConfig } from '../slices';
var endpoints = [
'ACCOUNT',
'DEALS',
'FAVORITES',
'ORDERS',
'GIFT_CARDS',
'LOYALTY',
'REWARDS'
];
var SignInCheckout = function (_a) {
var children = _a.children;
var dispatch = useAppDispatch();
var config = useAppSelector(selectKioskConfig).signInCheckout;
var customer = useAppSelector(selectCustomerIdentified);
var customerId = ((customer === null || customer === void 0 ? void 0 : customer.customer) || {}).customer_id;
var signIn = function () {
dispatch(openModal({ type: 'SIGN_IN' }));
};
var signOut = function () {
dispatch(resetCustomerIdentify());
dispatch(resetCustomer());
dispatch(resetMenu());
};
var handlers = { signIn: signIn, signOut: signOut };
useEffect(function () {
if (customerId) {
dispatch(fetchCustomer({ customerId: customerId, endpoints: endpoints }));
}
}, [dispatch, customerId]);
if (!config)
return null;
return children({
config: config,
handlers: handlers,
customer: customer
});
};
export default SignInCheckout;