@riosst100/pwa-marketplace 1.2.7 → 1.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/Utilities/graphQL.js +76 -76
- package/src/componentOverrideMapping.js +17 -17
- package/src/components/BecomeSeller/becomeSeller.js +335 -335
- package/src/components/BecomeSeller/becomeSeller.module.css +46 -46
- package/src/components/BecomeSellerLink/becomeSellerLink.js +52 -52
- package/src/components/BecomeSellerLink/becomeSellerLink.module.css +12 -12
- package/src/components/BecomeSellerPage/becomeSellerPage.js +45 -45
- package/src/components/BecomeSellerPage/becomeSellerPage.module.css +21 -21
- package/src/components/Filter/index.js +53 -53
- package/src/components/Header/becomeSellerLink.js +28 -28
- package/src/components/Header/becomeSellerLink.module.css +12 -12
- package/src/components/Header/websiteSwitcher.js +109 -109
- package/src/components/OperatingHours/index.js +1 -0
- package/src/components/OperatingHours/operatingHours.js +35 -0
- package/src/components/Pagination/index.js +49 -49
- package/src/components/PhoneTextInput/phoneTextInput.module.css +21 -21
- package/src/components/ProductItem/index.js +50 -50
- package/src/components/Search/index.js +16 -16
- package/src/components/Seller/index.js +1 -1
- package/src/components/Seller/seller.js +42 -249
- package/src/components/Seller/sellerAddressCard.js +48 -0
- package/src/components/SellerAccountPage/sellerAccountPage.js +110 -110
- package/src/components/SellerAccountPage/sellerAccountPage.module.css +55 -55
- package/src/components/SellerCountry/sellerCountry.gql.js +11 -11
- package/src/components/SellerDetail/index.js +1 -0
- package/src/components/SellerDetail/sellerDetail.js +166 -0
- package/src/components/SellerInformation/index.js +1 -1
- package/src/components/SellerInformation/sellerInformation.js +86 -90
- package/src/components/SellerLocation/index.js +1 -1
- package/src/components/SellerLocation/sellerLocation.js +19 -19
- package/src/components/SellerLocation/sellerLocationItem.js +27 -27
- package/src/components/SellerPage/sellerPage.js +9 -9
- package/src/components/SellerProducts/sellerProducts.js +46 -46
- package/src/components/SellerReview/index.js +1 -1
- package/src/components/SellerReview/sellerReview.js +143 -143
- package/src/components/SellerReviewItem/sellerReviewItem.js +60 -60
- package/src/components/SellerVerification/sellerVerification.js +198 -198
- package/src/components/SellerVerification/sellerVerification.module.css +47 -47
- package/src/components/SellerVerificationPage/sellerVerificationPage.js +43 -43
- package/src/components/SellerVerificationPage/sellerVerificationPage.module.css +21 -21
- package/src/components/SortBy/index.js +24 -24
- package/src/components/WebsiteSwitcher/websiteSwitcher.js +109 -109
- package/src/components/commons/Slider/index.js +13 -13
- package/src/components/commons/Tabs/index.js +64 -64
- package/src/index.js +6 -6
- package/src/intercept.js +113 -113
- package/src/moduleOverrideWebpackPlugin.js +70 -70
- package/src/overwrites/peregrine/lib/store/actions/user/asyncActions.js +96 -96
- package/src/overwrites/peregrine/lib/talons/AccountMenu/useAccountMenuItems.js +74 -74
- package/src/overwrites/peregrine/lib/talons/Adapter/useAdapter.js +208 -208
- package/src/overwrites/peregrine/lib/talons/Header/storeSwitcher.gql.js +45 -45
- package/src/overwrites/peregrine/lib/talons/Header/useStoreSwitcher.js +204 -204
- package/src/overwrites/peregrine/lib/talons/Region/useRegion.js +102 -102
- package/src/overwrites/peregrine/lib/talons/SignIn/signIn.gql.js +56 -56
- package/src/overwrites/peregrine/lib/talons/SignIn/useSignIn.js +226 -226
- package/src/overwrites/peregrine/lib/util/deriveErrorMessage.js +34 -34
- package/src/overwrites/pwa-buildpack/lib/queries/getAvailableStoresConfigData.graphql +11 -11
- package/src/overwrites/venia-ui/lib/components/Adapter/adapter.js +112 -112
- package/src/overwrites/venia-ui/lib/components/Header/header.js +130 -130
- package/src/overwrites/venia-ui/lib/components/Header/storeSwitcher.js +105 -105
- package/src/overwrites/venia-ui/lib/components/Header/switcherItem.js +47 -47
- package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/MegaMenu.spec.js +91 -91
- package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/MegaMenuItem.spec.js +123 -123
- package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/Submenu.spec.js +61 -61
- package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/SubmenuColumn.spec.js +50 -50
- package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/__snapshots__/MegaMenu.spec.js.snap +114 -114
- package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/__snapshots__/MegaMenuItem.spec.js.snap +71 -71
- package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/__snapshots__/Submenu.spec.js.snap +59 -59
- package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/__snapshots__/SubmenuColumn.spec.js.snap +34 -34
- package/src/overwrites/venia-ui/lib/components/MegaMenu/index.js +1 -1
- package/src/overwrites/venia-ui/lib/components/MegaMenu/megaMenu.js +90 -90
- package/src/overwrites/venia-ui/lib/components/MegaMenu/megaMenu.module.css +12 -12
- package/src/overwrites/venia-ui/lib/components/MegaMenu/megaMenuItem.js +156 -156
- package/src/overwrites/venia-ui/lib/components/MegaMenu/megaMenuItem.module.css +30 -30
- package/src/overwrites/venia-ui/lib/components/MegaMenu/submenu.js +89 -89
- package/src/overwrites/venia-ui/lib/components/MegaMenu/submenu.module.css +42 -42
- package/src/overwrites/venia-ui/lib/components/MegaMenu/submenuColumn.js +99 -99
- package/src/overwrites/venia-ui/lib/components/MegaMenu/submenuColumn.module.css +28 -28
- package/src/overwrites/venia-ui/lib/components/SearchBar/__stories__/searchBar.js +11 -11
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/__snapshots__/searchField.spec.js.snap +72 -72
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/__snapshots__/suggestedCategories.spec.js.snap +30 -30
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/__snapshots__/suggestedProduct.spec.js.snap +69 -69
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/__snapshots__/suggestedProducts.spec.js.snap +7 -7
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/__snapshots__/suggestions.spec.js.snap +12 -12
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/autocomplete.spec.js +52 -52
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/searchBar.spec.js +82 -82
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/searchField.spec.js +87 -87
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/suggestedCategories.spec.js +45 -45
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/suggestedProduct.spec.js +43 -43
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/suggestedProducts.spec.js +45 -45
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/suggestions.spec.js +110 -110
- package/src/overwrites/venia-ui/lib/components/SearchBar/autocomplete.js +172 -172
- package/src/overwrites/venia-ui/lib/components/SearchBar/autocomplete.module.css +62 -62
- package/src/overwrites/venia-ui/lib/components/SearchBar/index.js +1 -1
- package/src/overwrites/venia-ui/lib/components/SearchBar/searchBar.js +74 -74
- package/src/overwrites/venia-ui/lib/components/SearchBar/searchBar.module.css +49 -49
- package/src/overwrites/venia-ui/lib/components/SearchBar/searchField.js +40 -40
- package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedCategories.js +48 -48
- package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedCategories.module.css +13 -13
- package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedCategory.js +49 -49
- package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedProduct.js +97 -97
- package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedProduct.module.css +24 -24
- package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedProducts.js +43 -43
- package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedProducts.module.css +13 -13
- package/src/overwrites/venia-ui/lib/components/SearchBar/suggestions.js +75 -75
- package/src/overwrites/venia-ui/lib/components/SearchBar/suggestions.module.css +6 -6
- package/src/overwrites/venia-ui/lib/components/StoreCodeRoute/storeCodeRoute.js +75 -75
- package/src/overwrites/venia-ui/lib/targets/venia-ui-intercept.js +70 -70
- package/src/queries/getAvailableWebsitesConfigData.graphql +14 -14
- package/src/queries/index.js +30 -30
- package/src/talons/BecomeSeller/becomeSeller.gql.js +45 -45
- package/src/talons/BecomeSeller/useBecomeSeller.js +145 -145
- package/src/talons/BecomeSellerLink/useBecomeSellerLink.js +11 -11
- package/src/talons/BecomeSellerPage/useBecomeSellerPage.js +76 -76
- package/src/talons/Header/useBecomeSellerLink.js +13 -13
- package/src/talons/Header/useWebsiteSwitcher.js +218 -218
- package/src/talons/Seller/seller.gql.js +204 -139
- package/src/talons/Seller/useSeller.js +71 -66
- package/src/talons/SellerAccountPage/useSellerAccountPage.js +174 -174
- package/src/talons/SellerCountry/useSellerCountry.js +25 -25
- package/src/talons/WebsiteByIp/getWebsiteByIp.gql.js +13 -13
- package/src/talons/WebsiteByIp/useWebsiteByIp.js +34 -34
- package/src/talons/WebsiteSwitcher/useWebsiteSwitcher.js +218 -218
- package/src/theme/vars.js +6 -6
- package/src/util/mapSeller.js +7 -7
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import { gql } from '@apollo/client';
|
|
2
|
-
import { CheckoutPageFragment } from '@magento/peregrine/lib/talons/CheckoutPage/checkoutPageFragments.gql';
|
|
3
|
-
|
|
4
|
-
export const GET_CUSTOMER = gql`
|
|
5
|
-
query GetCustomerAfterSignIn {
|
|
6
|
-
# eslint-disable-next-line @graphql-eslint/require-id-when-available
|
|
7
|
-
customer {
|
|
8
|
-
email
|
|
9
|
-
firstname
|
|
10
|
-
lastname
|
|
11
|
-
is_subscribed
|
|
12
|
-
is_seller
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
`;
|
|
16
|
-
|
|
17
|
-
export const SIGN_IN = gql`
|
|
18
|
-
mutation SignIn($email: String!, $password: String!) {
|
|
19
|
-
generateCustomerToken(email: $email, password: $password) {
|
|
20
|
-
token
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
`;
|
|
24
|
-
|
|
25
|
-
export const CREATE_CART = gql`
|
|
26
|
-
mutation CreateCartAfterSignIn {
|
|
27
|
-
cartId: createEmptyCart
|
|
28
|
-
}
|
|
29
|
-
`;
|
|
30
|
-
|
|
31
|
-
export const MERGE_CARTS = gql`
|
|
32
|
-
mutation MergeCartsAfterSignIn(
|
|
33
|
-
$sourceCartId: String!
|
|
34
|
-
$destinationCartId: String!
|
|
35
|
-
) {
|
|
36
|
-
mergeCarts(
|
|
37
|
-
source_cart_id: $sourceCartId
|
|
38
|
-
destination_cart_id: $destinationCartId
|
|
39
|
-
) {
|
|
40
|
-
id
|
|
41
|
-
# eslint-disable-next-line @graphql-eslint/require-id-when-available
|
|
42
|
-
items {
|
|
43
|
-
uid
|
|
44
|
-
}
|
|
45
|
-
...CheckoutPageFragment
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
${CheckoutPageFragment}
|
|
49
|
-
`;
|
|
50
|
-
|
|
51
|
-
export default {
|
|
52
|
-
createCartMutation: CREATE_CART,
|
|
53
|
-
getCustomerQuery: GET_CUSTOMER,
|
|
54
|
-
mergeCartsMutation: MERGE_CARTS,
|
|
55
|
-
signInMutation: SIGN_IN
|
|
56
|
-
};
|
|
1
|
+
import { gql } from '@apollo/client';
|
|
2
|
+
import { CheckoutPageFragment } from '@magento/peregrine/lib/talons/CheckoutPage/checkoutPageFragments.gql';
|
|
3
|
+
|
|
4
|
+
export const GET_CUSTOMER = gql`
|
|
5
|
+
query GetCustomerAfterSignIn {
|
|
6
|
+
# eslint-disable-next-line @graphql-eslint/require-id-when-available
|
|
7
|
+
customer {
|
|
8
|
+
email
|
|
9
|
+
firstname
|
|
10
|
+
lastname
|
|
11
|
+
is_subscribed
|
|
12
|
+
is_seller
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
export const SIGN_IN = gql`
|
|
18
|
+
mutation SignIn($email: String!, $password: String!) {
|
|
19
|
+
generateCustomerToken(email: $email, password: $password) {
|
|
20
|
+
token
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
`;
|
|
24
|
+
|
|
25
|
+
export const CREATE_CART = gql`
|
|
26
|
+
mutation CreateCartAfterSignIn {
|
|
27
|
+
cartId: createEmptyCart
|
|
28
|
+
}
|
|
29
|
+
`;
|
|
30
|
+
|
|
31
|
+
export const MERGE_CARTS = gql`
|
|
32
|
+
mutation MergeCartsAfterSignIn(
|
|
33
|
+
$sourceCartId: String!
|
|
34
|
+
$destinationCartId: String!
|
|
35
|
+
) {
|
|
36
|
+
mergeCarts(
|
|
37
|
+
source_cart_id: $sourceCartId
|
|
38
|
+
destination_cart_id: $destinationCartId
|
|
39
|
+
) {
|
|
40
|
+
id
|
|
41
|
+
# eslint-disable-next-line @graphql-eslint/require-id-when-available
|
|
42
|
+
items {
|
|
43
|
+
uid
|
|
44
|
+
}
|
|
45
|
+
...CheckoutPageFragment
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
${CheckoutPageFragment}
|
|
49
|
+
`;
|
|
50
|
+
|
|
51
|
+
export default {
|
|
52
|
+
createCartMutation: CREATE_CART,
|
|
53
|
+
getCustomerQuery: GET_CUSTOMER,
|
|
54
|
+
mergeCartsMutation: MERGE_CARTS,
|
|
55
|
+
signInMutation: SIGN_IN
|
|
56
|
+
};
|
|
@@ -1,226 +1,226 @@
|
|
|
1
|
-
import { useCallback, useRef, useState, useMemo } from 'react';
|
|
2
|
-
import { useApolloClient, useMutation } from '@apollo/client';
|
|
3
|
-
|
|
4
|
-
import { useGoogleReCaptcha } from '@magento/peregrine/lib/hooks/useGoogleReCaptcha/useGoogleReCaptcha';
|
|
5
|
-
import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
|
|
6
|
-
import { useCartContext } from '@magento/peregrine/lib/context/cart';
|
|
7
|
-
import { useUserContext } from '@magento/peregrine/lib/context/user';
|
|
8
|
-
import { useAwaitQuery } from '@magento/peregrine/lib/hooks/useAwaitQuery';
|
|
9
|
-
import { retrieveCartId } from '@magento/peregrine/lib/store/actions/cart';
|
|
10
|
-
|
|
11
|
-
import DEFAULT_OPERATIONS from '@magento/peregrine/lib/talons/SignIn/signIn.gql';
|
|
12
|
-
import { useEventingContext } from '@magento/peregrine/lib/context/eventing';
|
|
13
|
-
import { BrowserPersistence } from '@magento/peregrine/lib/util';
|
|
14
|
-
|
|
15
|
-
const storage = new BrowserPersistence();
|
|
16
|
-
|
|
17
|
-
export const useSignIn = props => {
|
|
18
|
-
const {
|
|
19
|
-
handleTriggerClick,
|
|
20
|
-
getCartDetailsQuery,
|
|
21
|
-
setDefaultUsername,
|
|
22
|
-
showCreateAccount,
|
|
23
|
-
showForgotPassword
|
|
24
|
-
} = props;
|
|
25
|
-
|
|
26
|
-
const operations = mergeOperations(DEFAULT_OPERATIONS, props.operations);
|
|
27
|
-
const {
|
|
28
|
-
createCartMutation,
|
|
29
|
-
getCustomerQuery,
|
|
30
|
-
mergeCartsMutation,
|
|
31
|
-
signInMutation
|
|
32
|
-
} = operations;
|
|
33
|
-
|
|
34
|
-
const apolloClient = useApolloClient();
|
|
35
|
-
const [isSigningIn, setIsSigningIn] = useState(false);
|
|
36
|
-
|
|
37
|
-
const [
|
|
38
|
-
{ cartId },
|
|
39
|
-
{ createCart, removeCart, getCartDetails }
|
|
40
|
-
] = useCartContext();
|
|
41
|
-
|
|
42
|
-
const [
|
|
43
|
-
{ isGettingDetails, getDetailsError },
|
|
44
|
-
{ getUserDetails, setToken }
|
|
45
|
-
] = useUserContext();
|
|
46
|
-
|
|
47
|
-
const [, { dispatch }] = useEventingContext();
|
|
48
|
-
|
|
49
|
-
const [signIn, { error: signInError }] = useMutation(signInMutation, {
|
|
50
|
-
fetchPolicy: 'no-cache'
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
const {
|
|
54
|
-
generateReCaptchaData,
|
|
55
|
-
recaptchaLoading,
|
|
56
|
-
recaptchaWidgetProps
|
|
57
|
-
} = useGoogleReCaptcha({
|
|
58
|
-
currentForm: 'CUSTOMER_LOGIN',
|
|
59
|
-
formAction: 'signIn'
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
const [fetchCartId] = useMutation(createCartMutation);
|
|
63
|
-
const [mergeCarts] = useMutation(mergeCartsMutation);
|
|
64
|
-
const fetchUserDetails = useAwaitQuery(getCustomerQuery);
|
|
65
|
-
const fetchCartDetails = useAwaitQuery(getCartDetailsQuery);
|
|
66
|
-
|
|
67
|
-
const formApiRef = useRef(null);
|
|
68
|
-
const setFormApi = useCallback(api => (formApiRef.current = api), []);
|
|
69
|
-
|
|
70
|
-
const handleSubmit = useCallback(
|
|
71
|
-
async ({ email, password }) => {
|
|
72
|
-
setIsSigningIn(true);
|
|
73
|
-
// handleTriggerClick();
|
|
74
|
-
try {
|
|
75
|
-
// Get source cart id (guest cart id).
|
|
76
|
-
const sourceCartId = cartId;
|
|
77
|
-
|
|
78
|
-
// Get recaptchaV3 data for login
|
|
79
|
-
const recaptchaData = await generateReCaptchaData();
|
|
80
|
-
|
|
81
|
-
// Sign in and set the token.
|
|
82
|
-
const signInResponse = await signIn({
|
|
83
|
-
variables: {
|
|
84
|
-
email,
|
|
85
|
-
password
|
|
86
|
-
},
|
|
87
|
-
...recaptchaData
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
const token = signInResponse.data.generateCustomerToken.token;
|
|
91
|
-
await setToken(token);
|
|
92
|
-
|
|
93
|
-
await getUserDetails({ fetchUserDetails });
|
|
94
|
-
|
|
95
|
-
// Clear all cart/customer data from cache and redux.
|
|
96
|
-
await apolloClient.clearCacheData(apolloClient, 'cart');
|
|
97
|
-
await apolloClient.clearCacheData(apolloClient, 'customer');
|
|
98
|
-
await removeCart();
|
|
99
|
-
|
|
100
|
-
// Create and get the customer's cart id.
|
|
101
|
-
await createCart({
|
|
102
|
-
fetchCartId
|
|
103
|
-
});
|
|
104
|
-
const destinationCartId = await retrieveCartId();
|
|
105
|
-
|
|
106
|
-
// Merge the guest cart into the customer cart.
|
|
107
|
-
await mergeCarts({
|
|
108
|
-
variables: {
|
|
109
|
-
destinationCartId,
|
|
110
|
-
sourceCartId
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
// Ensure old stores are updated with any new data.
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const { data } = await fetchUserDetails({
|
|
119
|
-
fetchPolicy: 'cache-only'
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
if (data.customer.is_seller) {
|
|
123
|
-
storage.setItem('is_seller', true);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
dispatch({
|
|
127
|
-
type: 'USER_SIGN_IN',
|
|
128
|
-
payload: {
|
|
129
|
-
...data.customer
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
getCartDetails({ fetchCartId, fetchCartDetails });
|
|
134
|
-
} catch (error) {
|
|
135
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
136
|
-
console.error(error);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
setIsSigningIn(false);
|
|
140
|
-
}
|
|
141
|
-
},
|
|
142
|
-
[
|
|
143
|
-
cartId,
|
|
144
|
-
generateReCaptchaData,
|
|
145
|
-
signIn,
|
|
146
|
-
setToken,
|
|
147
|
-
apolloClient,
|
|
148
|
-
removeCart,
|
|
149
|
-
createCart,
|
|
150
|
-
fetchCartId,
|
|
151
|
-
mergeCarts,
|
|
152
|
-
getUserDetails,
|
|
153
|
-
fetchUserDetails,
|
|
154
|
-
getCartDetails,
|
|
155
|
-
fetchCartDetails,
|
|
156
|
-
dispatch,
|
|
157
|
-
handleTriggerClick
|
|
158
|
-
]
|
|
159
|
-
);
|
|
160
|
-
|
|
161
|
-
const handleForgotPassword = useCallback(() => {
|
|
162
|
-
const { current: formApi } = formApiRef;
|
|
163
|
-
|
|
164
|
-
if (formApi) {
|
|
165
|
-
setDefaultUsername(formApi.getValue('email'));
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
showForgotPassword();
|
|
169
|
-
}, [setDefaultUsername, showForgotPassword]);
|
|
170
|
-
|
|
171
|
-
const forgotPasswordHandleEnterKeyPress = useCallback(() => {
|
|
172
|
-
event => {
|
|
173
|
-
if (event.key === 'Enter') {
|
|
174
|
-
handleForgotPassword();
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
}, [handleForgotPassword]);
|
|
178
|
-
|
|
179
|
-
const handleCreateAccount = useCallback(() => {
|
|
180
|
-
const { current: formApi } = formApiRef;
|
|
181
|
-
|
|
182
|
-
if (formApi) {
|
|
183
|
-
setDefaultUsername(formApi.getValue('email'));
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
showCreateAccount();
|
|
187
|
-
}, [setDefaultUsername, showCreateAccount]);
|
|
188
|
-
|
|
189
|
-
const handleEnterKeyPress = useCallback(() => {
|
|
190
|
-
event => {
|
|
191
|
-
if (event.key === 'Enter') {
|
|
192
|
-
handleCreateAccount();
|
|
193
|
-
}
|
|
194
|
-
};
|
|
195
|
-
}, [handleCreateAccount]);
|
|
196
|
-
|
|
197
|
-
const signinHandleEnterKeyPress = useCallback(() => {
|
|
198
|
-
event => {
|
|
199
|
-
if (event.key === 'Enter') {
|
|
200
|
-
handleSubmit();
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
}, [handleSubmit]);
|
|
204
|
-
|
|
205
|
-
const errors = useMemo(
|
|
206
|
-
() =>
|
|
207
|
-
new Map([
|
|
208
|
-
['getUserDetailsQuery', getDetailsError],
|
|
209
|
-
['signInMutation', signInError]
|
|
210
|
-
]),
|
|
211
|
-
[getDetailsError, signInError]
|
|
212
|
-
);
|
|
213
|
-
|
|
214
|
-
return {
|
|
215
|
-
errors,
|
|
216
|
-
handleCreateAccount,
|
|
217
|
-
handleEnterKeyPress,
|
|
218
|
-
signinHandleEnterKeyPress,
|
|
219
|
-
handleForgotPassword,
|
|
220
|
-
forgotPasswordHandleEnterKeyPress,
|
|
221
|
-
handleSubmit,
|
|
222
|
-
isBusy: isGettingDetails || isSigningIn || recaptchaLoading,
|
|
223
|
-
setFormApi,
|
|
224
|
-
recaptchaWidgetProps
|
|
225
|
-
};
|
|
226
|
-
};
|
|
1
|
+
import { useCallback, useRef, useState, useMemo } from 'react';
|
|
2
|
+
import { useApolloClient, useMutation } from '@apollo/client';
|
|
3
|
+
|
|
4
|
+
import { useGoogleReCaptcha } from '@magento/peregrine/lib/hooks/useGoogleReCaptcha/useGoogleReCaptcha';
|
|
5
|
+
import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
|
|
6
|
+
import { useCartContext } from '@magento/peregrine/lib/context/cart';
|
|
7
|
+
import { useUserContext } from '@magento/peregrine/lib/context/user';
|
|
8
|
+
import { useAwaitQuery } from '@magento/peregrine/lib/hooks/useAwaitQuery';
|
|
9
|
+
import { retrieveCartId } from '@magento/peregrine/lib/store/actions/cart';
|
|
10
|
+
|
|
11
|
+
import DEFAULT_OPERATIONS from '@magento/peregrine/lib/talons/SignIn/signIn.gql';
|
|
12
|
+
import { useEventingContext } from '@magento/peregrine/lib/context/eventing';
|
|
13
|
+
import { BrowserPersistence } from '@magento/peregrine/lib/util';
|
|
14
|
+
|
|
15
|
+
const storage = new BrowserPersistence();
|
|
16
|
+
|
|
17
|
+
export const useSignIn = props => {
|
|
18
|
+
const {
|
|
19
|
+
handleTriggerClick,
|
|
20
|
+
getCartDetailsQuery,
|
|
21
|
+
setDefaultUsername,
|
|
22
|
+
showCreateAccount,
|
|
23
|
+
showForgotPassword
|
|
24
|
+
} = props;
|
|
25
|
+
|
|
26
|
+
const operations = mergeOperations(DEFAULT_OPERATIONS, props.operations);
|
|
27
|
+
const {
|
|
28
|
+
createCartMutation,
|
|
29
|
+
getCustomerQuery,
|
|
30
|
+
mergeCartsMutation,
|
|
31
|
+
signInMutation
|
|
32
|
+
} = operations;
|
|
33
|
+
|
|
34
|
+
const apolloClient = useApolloClient();
|
|
35
|
+
const [isSigningIn, setIsSigningIn] = useState(false);
|
|
36
|
+
|
|
37
|
+
const [
|
|
38
|
+
{ cartId },
|
|
39
|
+
{ createCart, removeCart, getCartDetails }
|
|
40
|
+
] = useCartContext();
|
|
41
|
+
|
|
42
|
+
const [
|
|
43
|
+
{ isGettingDetails, getDetailsError },
|
|
44
|
+
{ getUserDetails, setToken }
|
|
45
|
+
] = useUserContext();
|
|
46
|
+
|
|
47
|
+
const [, { dispatch }] = useEventingContext();
|
|
48
|
+
|
|
49
|
+
const [signIn, { error: signInError }] = useMutation(signInMutation, {
|
|
50
|
+
fetchPolicy: 'no-cache'
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const {
|
|
54
|
+
generateReCaptchaData,
|
|
55
|
+
recaptchaLoading,
|
|
56
|
+
recaptchaWidgetProps
|
|
57
|
+
} = useGoogleReCaptcha({
|
|
58
|
+
currentForm: 'CUSTOMER_LOGIN',
|
|
59
|
+
formAction: 'signIn'
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const [fetchCartId] = useMutation(createCartMutation);
|
|
63
|
+
const [mergeCarts] = useMutation(mergeCartsMutation);
|
|
64
|
+
const fetchUserDetails = useAwaitQuery(getCustomerQuery);
|
|
65
|
+
const fetchCartDetails = useAwaitQuery(getCartDetailsQuery);
|
|
66
|
+
|
|
67
|
+
const formApiRef = useRef(null);
|
|
68
|
+
const setFormApi = useCallback(api => (formApiRef.current = api), []);
|
|
69
|
+
|
|
70
|
+
const handleSubmit = useCallback(
|
|
71
|
+
async ({ email, password }) => {
|
|
72
|
+
setIsSigningIn(true);
|
|
73
|
+
// handleTriggerClick();
|
|
74
|
+
try {
|
|
75
|
+
// Get source cart id (guest cart id).
|
|
76
|
+
const sourceCartId = cartId;
|
|
77
|
+
|
|
78
|
+
// Get recaptchaV3 data for login
|
|
79
|
+
const recaptchaData = await generateReCaptchaData();
|
|
80
|
+
|
|
81
|
+
// Sign in and set the token.
|
|
82
|
+
const signInResponse = await signIn({
|
|
83
|
+
variables: {
|
|
84
|
+
email,
|
|
85
|
+
password
|
|
86
|
+
},
|
|
87
|
+
...recaptchaData
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const token = signInResponse.data.generateCustomerToken.token;
|
|
91
|
+
await setToken(token);
|
|
92
|
+
|
|
93
|
+
await getUserDetails({ fetchUserDetails });
|
|
94
|
+
|
|
95
|
+
// Clear all cart/customer data from cache and redux.
|
|
96
|
+
await apolloClient.clearCacheData(apolloClient, 'cart');
|
|
97
|
+
await apolloClient.clearCacheData(apolloClient, 'customer');
|
|
98
|
+
await removeCart();
|
|
99
|
+
|
|
100
|
+
// Create and get the customer's cart id.
|
|
101
|
+
await createCart({
|
|
102
|
+
fetchCartId
|
|
103
|
+
});
|
|
104
|
+
const destinationCartId = await retrieveCartId();
|
|
105
|
+
|
|
106
|
+
// Merge the guest cart into the customer cart.
|
|
107
|
+
await mergeCarts({
|
|
108
|
+
variables: {
|
|
109
|
+
destinationCartId,
|
|
110
|
+
sourceCartId
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// Ensure old stores are updated with any new data.
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
const { data } = await fetchUserDetails({
|
|
119
|
+
fetchPolicy: 'cache-only'
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
if (data.customer.is_seller) {
|
|
123
|
+
storage.setItem('is_seller', true);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
dispatch({
|
|
127
|
+
type: 'USER_SIGN_IN',
|
|
128
|
+
payload: {
|
|
129
|
+
...data.customer
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
getCartDetails({ fetchCartId, fetchCartDetails });
|
|
134
|
+
} catch (error) {
|
|
135
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
136
|
+
console.error(error);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
setIsSigningIn(false);
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
[
|
|
143
|
+
cartId,
|
|
144
|
+
generateReCaptchaData,
|
|
145
|
+
signIn,
|
|
146
|
+
setToken,
|
|
147
|
+
apolloClient,
|
|
148
|
+
removeCart,
|
|
149
|
+
createCart,
|
|
150
|
+
fetchCartId,
|
|
151
|
+
mergeCarts,
|
|
152
|
+
getUserDetails,
|
|
153
|
+
fetchUserDetails,
|
|
154
|
+
getCartDetails,
|
|
155
|
+
fetchCartDetails,
|
|
156
|
+
dispatch,
|
|
157
|
+
handleTriggerClick
|
|
158
|
+
]
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
const handleForgotPassword = useCallback(() => {
|
|
162
|
+
const { current: formApi } = formApiRef;
|
|
163
|
+
|
|
164
|
+
if (formApi) {
|
|
165
|
+
setDefaultUsername(formApi.getValue('email'));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
showForgotPassword();
|
|
169
|
+
}, [setDefaultUsername, showForgotPassword]);
|
|
170
|
+
|
|
171
|
+
const forgotPasswordHandleEnterKeyPress = useCallback(() => {
|
|
172
|
+
event => {
|
|
173
|
+
if (event.key === 'Enter') {
|
|
174
|
+
handleForgotPassword();
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
}, [handleForgotPassword]);
|
|
178
|
+
|
|
179
|
+
const handleCreateAccount = useCallback(() => {
|
|
180
|
+
const { current: formApi } = formApiRef;
|
|
181
|
+
|
|
182
|
+
if (formApi) {
|
|
183
|
+
setDefaultUsername(formApi.getValue('email'));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
showCreateAccount();
|
|
187
|
+
}, [setDefaultUsername, showCreateAccount]);
|
|
188
|
+
|
|
189
|
+
const handleEnterKeyPress = useCallback(() => {
|
|
190
|
+
event => {
|
|
191
|
+
if (event.key === 'Enter') {
|
|
192
|
+
handleCreateAccount();
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
}, [handleCreateAccount]);
|
|
196
|
+
|
|
197
|
+
const signinHandleEnterKeyPress = useCallback(() => {
|
|
198
|
+
event => {
|
|
199
|
+
if (event.key === 'Enter') {
|
|
200
|
+
handleSubmit();
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
}, [handleSubmit]);
|
|
204
|
+
|
|
205
|
+
const errors = useMemo(
|
|
206
|
+
() =>
|
|
207
|
+
new Map([
|
|
208
|
+
['getUserDetailsQuery', getDetailsError],
|
|
209
|
+
['signInMutation', signInError]
|
|
210
|
+
]),
|
|
211
|
+
[getDetailsError, signInError]
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
return {
|
|
215
|
+
errors,
|
|
216
|
+
handleCreateAccount,
|
|
217
|
+
handleEnterKeyPress,
|
|
218
|
+
signinHandleEnterKeyPress,
|
|
219
|
+
handleForgotPassword,
|
|
220
|
+
forgotPasswordHandleEnterKeyPress,
|
|
221
|
+
handleSubmit,
|
|
222
|
+
isBusy: isGettingDetails || isSigningIn || recaptchaLoading,
|
|
223
|
+
setFormApi,
|
|
224
|
+
recaptchaWidgetProps
|
|
225
|
+
};
|
|
226
|
+
};
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Maps an error to a string message
|
|
3
|
-
*
|
|
4
|
-
* @param {Error} error the error to map
|
|
5
|
-
* @return {String} error message
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
const toString = (error, defaultErrorMessage) => {
|
|
9
|
-
const { graphQLErrors, message } = error;
|
|
10
|
-
|
|
11
|
-
if (graphQLErrors && graphQLErrors.length) {
|
|
12
|
-
return graphQLErrors.map(({ message }) => message).join(', ');
|
|
13
|
-
} else {
|
|
14
|
-
if (defaultErrorMessage) {
|
|
15
|
-
return defaultErrorMessage;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return message;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* A function to derive an error string from an array of errors.
|
|
24
|
-
*/
|
|
25
|
-
export const deriveErrorMessage = (errors, defaultErrorMessage = '') => {
|
|
26
|
-
const errorCollection = [];
|
|
27
|
-
for (const error of errors) {
|
|
28
|
-
if (error) {
|
|
29
|
-
errorCollection.push(toString(error, defaultErrorMessage));
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return errorCollection.join(', ');
|
|
34
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* Maps an error to a string message
|
|
3
|
+
*
|
|
4
|
+
* @param {Error} error the error to map
|
|
5
|
+
* @return {String} error message
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const toString = (error, defaultErrorMessage) => {
|
|
9
|
+
const { graphQLErrors, message } = error;
|
|
10
|
+
|
|
11
|
+
if (graphQLErrors && graphQLErrors.length) {
|
|
12
|
+
return graphQLErrors.map(({ message }) => message).join(', ');
|
|
13
|
+
} else {
|
|
14
|
+
if (defaultErrorMessage) {
|
|
15
|
+
return defaultErrorMessage;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return message;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* A function to derive an error string from an array of errors.
|
|
24
|
+
*/
|
|
25
|
+
export const deriveErrorMessage = (errors, defaultErrorMessage = '') => {
|
|
26
|
+
const errorCollection = [];
|
|
27
|
+
for (const error of errors) {
|
|
28
|
+
if (error) {
|
|
29
|
+
errorCollection.push(toString(error, defaultErrorMessage));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return errorCollection.join(', ');
|
|
34
|
+
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
query availableStoresConfigData {
|
|
2
|
-
availableStores {
|
|
3
|
-
store_code
|
|
4
|
-
id
|
|
5
|
-
secure_base_media_url
|
|
6
|
-
store_name
|
|
7
|
-
default_display_currency_code
|
|
8
|
-
website_code
|
|
9
|
-
is_default_store
|
|
10
|
-
}
|
|
11
|
-
}
|
|
1
|
+
query availableStoresConfigData {
|
|
2
|
+
availableStores {
|
|
3
|
+
store_code
|
|
4
|
+
id
|
|
5
|
+
secure_base_media_url
|
|
6
|
+
store_name
|
|
7
|
+
default_display_currency_code
|
|
8
|
+
website_code
|
|
9
|
+
is_default_store
|
|
10
|
+
}
|
|
11
|
+
}
|