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

PWA-3233 : Unable to sign-In using TAB/ Mouse Click button from Sign … #4231

Merged
merged 10 commits into from
Apr 1, 2024
14 changes: 14 additions & 0 deletions packages/peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,17 @@ test('mutation error is returned by talon', async () => {
`[Error: Uh oh! There was an error signing in :(]`
);
});

it('should call handleForgotPassword when Enter key is pressed', () => {
const { result } = renderHookWithProviders();
const { forgotPasswordHandleEnterKeyPress } = result.current;
const enterKeyEvent = { key: 'Enter' };
renderHook(() => forgotPasswordHandleEnterKeyPress(enterKeyEvent));
});

it('should call handleEnterKeyPress when Enter key is pressed', () => {
const { result } = renderHookWithProviders();
const { handleEnterKeyPress } = result.current;
const enterKeyEvent = { key: 'Enter' };
renderHook(() => handleEnterKeyPress(enterKeyEvent));
});
22 changes: 13 additions & 9 deletions packages/peregrine/lib/talons/SignIn/useSignIn.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const useSignIn = props => {
async ({ email, password }) => {
setIsSigningIn(true);
handleTriggerClick();

try {
// Get source cart id (guest cart id).
const sourceCartId = cartId;
Expand Down Expand Up @@ -159,13 +160,14 @@ export const useSignIn = props => {
showForgotPassword();
}, [setDefaultUsername, showForgotPassword]);

const forgotPasswordHandleEnterKeyPress = useCallback(() => {
const forgotPasswordHandleEnterKeyPress = useCallback(
event => {
if (event.key === 'Enter') {
handleForgotPassword();
}
};
}, [handleForgotPassword]);
},
[handleForgotPassword]
);

const handleCreateAccount = useCallback(() => {
const { current: formApi } = formApiRef;
Expand All @@ -177,21 +179,23 @@ export const useSignIn = props => {
showCreateAccount();
}, [setDefaultUsername, showCreateAccount]);

const handleEnterKeyPress = useCallback(() => {
const handleEnterKeyPress = useCallback(
event => {
if (event.key === 'Enter') {
handleCreateAccount();
}
};
}, [handleCreateAccount]);
},
[handleCreateAccount]
);

const signinHandleEnterKeyPress = useCallback(() => {
const signinHandleEnterKeyPress = useCallback(
event => {
if (event.key === 'Enter') {
handleSubmit();
}
};
}, [handleSubmit]);
},
[handleSubmit]
);

const errors = useMemo(
() =>
Expand Down