Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3230 Sign-in broken following 13.3.0 #4221

Merged
merged 9 commits into from
Mar 12, 2024
13 changes: 13 additions & 0 deletions packages/peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,19 @@ test('handleForgotPassword triggers callbacks', () => {
expect(initialProps.showForgotPassword).toHaveBeenCalled();
});

test('forgotPasswordHandleEnterKeyPress triggers callbacks on click', () => {
const mockUsername = 'fry@planetexpress.com';
const mockApi = {
getValue: jest.fn().mockReturnValue(mockUsername)
};
var event = new KeyboardEvent('keydown', { keyCode: 13 });
document.dispatchEvent(event);

const { result } = renderHookWithProviders();
act(() => result.current.setFormApi(mockApi));
act(() => result.current.forgotPasswordHandleEnterKeyPress());
});

test('handleCreateAccount triggers callbacks', () => {
const mockUsername = 'fry@planetexpress.com';
const mockApi = {
Expand Down
29 changes: 19 additions & 10 deletions packages/peregrine/lib/talons/SignIn/useSignIn.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { useCartContext } from '../../context/cart';
import { useUserContext } from '../../context/user';
import { useAwaitQuery } from '../../hooks/useAwaitQuery';
import { retrieveCartId } from '../../store/actions/cart';
import { useDropdown } from '@magento/peregrine/lib/hooks/useDropdown';

import DEFAULT_OPERATIONS from './signIn.gql';
import { useEventingContext } from '../../context/eventing';

export const useSignIn = props => {
const {
handleTriggerClick,
getCartDetailsQuery,
setDefaultUsername,
showCreateAccount,
Expand Down Expand Up @@ -64,10 +64,17 @@ export const useSignIn = props => {
const formApiRef = useRef(null);
const setFormApi = useCallback(api => (formApiRef.current = api), []);

const { setExpanded: setCurrencyMenuIsOpen } = useDropdown();

const handleTrigger = useCallback(() => {
// Toggle Stores Menu.
setCurrencyMenuIsOpen(isOpen => !isOpen);
}, [setCurrencyMenuIsOpen]);

const handleSubmit = useCallback(
async ({ email, password }) => {
setIsSigningIn(true);
handleTriggerClick();
handleTrigger();
try {
// Get source cart id (guest cart id).
const sourceCartId = cartId;
Expand Down Expand Up @@ -98,13 +105,15 @@ export const useSignIn = props => {
});
const destinationCartId = await retrieveCartId();

// Merge the guest cart into the customer cart.
await mergeCarts({
variables: {
destinationCartId,
sourceCartId
}
});
if (destinationCartId != sourceCartId) {
// Merge the guest cart into the customer cart.
await mergeCarts({
variables: {
destinationCartId,
sourceCartId
}
});
}

// Ensure old stores are updated with any new data.

Expand Down Expand Up @@ -145,7 +154,7 @@ export const useSignIn = props => {
getCartDetails,
fetchCartDetails,
dispatch,
handleTriggerClick
handleTrigger
]
);

Expand Down