@@ -7,13 +7,13 @@ import { useCartContext } from '../../context/cart';
7
7
import { useUserContext } from '../../context/user' ;
8
8
import { useAwaitQuery } from '../../hooks/useAwaitQuery' ;
9
9
import { retrieveCartId } from '../../store/actions/cart' ;
10
+ import { useDropdown } from '@magento/peregrine/lib/hooks/useDropdown' ;
10
11
11
12
import DEFAULT_OPERATIONS from './signIn.gql' ;
12
13
import { useEventingContext } from '../../context/eventing' ;
13
14
14
15
export const useSignIn = props => {
15
16
const {
16
- handleTriggerClick,
17
17
getCartDetailsQuery,
18
18
setDefaultUsername,
19
19
showCreateAccount,
@@ -64,10 +64,17 @@ export const useSignIn = props => {
64
64
const formApiRef = useRef ( null ) ;
65
65
const setFormApi = useCallback ( api => ( formApiRef . current = api ) , [ ] ) ;
66
66
67
+ const { setExpanded : setCurrencyMenuIsOpen } = useDropdown ( ) ;
68
+
69
+ const handleTrigger = useCallback ( ( ) => {
70
+ // Toggle Stores Menu.
71
+ setCurrencyMenuIsOpen ( isOpen => ! isOpen ) ;
72
+ } , [ setCurrencyMenuIsOpen ] ) ;
73
+
67
74
const handleSubmit = useCallback (
68
75
async ( { email, password } ) => {
69
76
setIsSigningIn ( true ) ;
70
- handleTriggerClick ( ) ;
77
+ handleTrigger ( ) ;
71
78
try {
72
79
// Get source cart id (guest cart id).
73
80
const sourceCartId = cartId ;
@@ -98,13 +105,15 @@ export const useSignIn = props => {
98
105
} ) ;
99
106
const destinationCartId = await retrieveCartId ( ) ;
100
107
101
- // Merge the guest cart into the customer cart.
102
- await mergeCarts ( {
103
- variables : {
104
- destinationCartId,
105
- sourceCartId
106
- }
107
- } ) ;
108
+ if ( destinationCartId != sourceCartId ) {
109
+ // Merge the guest cart into the customer cart.
110
+ await mergeCarts ( {
111
+ variables : {
112
+ destinationCartId,
113
+ sourceCartId
114
+ }
115
+ } ) ;
116
+ }
108
117
109
118
// Ensure old stores are updated with any new data.
110
119
@@ -145,7 +154,7 @@ export const useSignIn = props => {
145
154
getCartDetails ,
146
155
fetchCartDetails ,
147
156
dispatch ,
148
- handleTriggerClick
157
+ handleTrigger
149
158
]
150
159
) ;
151
160
0 commit comments