@riosst100/pwa-marketplace 3.2.5 → 3.2.6

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.
Files changed (29) hide show
  1. package/package.json +1 -1
  2. package/src/components/AgeVerification/ageVerificationModal.js +2 -2
  3. package/src/components/AgeVerification/index.js +1 -1
  4. package/src/components/BecomeSeller/becomeSeller.js +13 -10
  5. package/src/components/BecomeSellerPage/becomeSellerPage.js +29 -10
  6. package/src/components/BecomeSellerPage/becomeSellerPage.module.css +21 -0
  7. package/src/components/RFQ/index.js +3 -2
  8. package/src/components/RFQ/modalRfq.js +186 -68
  9. package/src/components/RFQPage/orderRow.js +84 -249
  10. package/src/components/RFQPage/orderRow.module.css +146 -0
  11. package/src/components/RFQPage/quoteDetail.js +173 -86
  12. package/src/components/RFQPage/quoteList.js +87 -65
  13. package/src/components/SocialLogin/googleSignInButton.js +50 -0
  14. package/src/components/SocialLogin/index.js +1 -10
  15. package/src/components/SocialLogin/socialLogin.js +28 -23
  16. package/src/components/WebsiteSwitcher/websiteSwitcherItem.js +0 -7
  17. package/src/overwrites/venia-ui/lib/components/Adapter/adapter.js +3 -1
  18. package/src/overwrites/venia-ui/lib/components/CreateAccount/createAccount.js +4 -4
  19. package/src/overwrites/venia-ui/lib/components/CreateAccountPage/createAccountPage.js +28 -9
  20. package/src/overwrites/venia-ui/lib/components/CreateAccountPage/createAccountPage.module.css +12 -2
  21. package/src/overwrites/venia-ui/lib/components/OrderHistoryPage/orderRow.js +1 -1
  22. package/src/overwrites/venia-ui/lib/components/ProductFullDetail/productFullDetail.js +1 -0
  23. package/src/overwrites/venia-ui/lib/components/SignIn/signIn.js +23 -30
  24. package/src/overwrites/venia-ui/lib/components/SignInPage/signInPage.js +22 -9
  25. package/src/overwrites/venia-ui/lib/components/SignInPage/signInPage.module.css +10 -0
  26. package/src/talons/RFQ/rfq.gql.js +162 -0
  27. package/src/talons/RFQ/useRFQ.js +81 -0
  28. package/src/talons/SocialLogin/socialLogin.gql.js +106 -0
  29. package/src/talons/SocialLogin/useSocialLogin.js +169 -0
@@ -0,0 +1,106 @@
1
+ import { gql } from '@apollo/client';
2
+ import { CheckoutPageFragment } from '@magento/peregrine/lib/talons/CheckoutPage/checkoutPageFragments.gql';
3
+ import { CartPageFragment } from '@magento/peregrine/lib/talons/CartPage/cartPageFragments.gql.js';
4
+
5
+ export const GET_CART_DETAILS_QUERY = gql`
6
+ query GetCartDetailsAfterSignIn($cartId: String!) {
7
+ cart(cart_id: $cartId) {
8
+ id
9
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
10
+ items {
11
+ uid
12
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
13
+ product {
14
+ uid
15
+ name
16
+ sku
17
+ small_image {
18
+ url
19
+ label
20
+ }
21
+ price {
22
+ regularPrice {
23
+ amount {
24
+ value
25
+ }
26
+ }
27
+ }
28
+ }
29
+ quantity
30
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
31
+ ... on ConfigurableCartItem {
32
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
33
+ configurable_options {
34
+ configurable_product_option_uid
35
+ option_label
36
+ configurable_product_option_value_uid
37
+ value_label
38
+ }
39
+ }
40
+ }
41
+ prices {
42
+ grand_total {
43
+ value
44
+ currency
45
+ }
46
+ }
47
+ ...CartPageFragment
48
+ }
49
+ }
50
+ ${CartPageFragment}
51
+ `;
52
+
53
+ export const GET_CUSTOMER = gql`
54
+ query GetCustomerAfterSignIn {
55
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
56
+ customer {
57
+ email
58
+ firstname
59
+ lastname
60
+ is_subscribed
61
+ is_seller
62
+ }
63
+ }
64
+ `;
65
+
66
+ export const CREATE_CART = gql`
67
+ mutation CreateCartAfterSignIn {
68
+ cartId: createEmptyCart
69
+ }
70
+ `;
71
+
72
+ export const MERGE_CARTS = gql`
73
+ mutation MergeCartsAfterSignIn(
74
+ $sourceCartId: String!
75
+ $destinationCartId: String!
76
+ ) {
77
+ mergeCarts(
78
+ source_cart_id: $sourceCartId
79
+ destination_cart_id: $destinationCartId
80
+ ) {
81
+ id
82
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
83
+ items {
84
+ uid
85
+ }
86
+ ...CheckoutPageFragment
87
+ }
88
+ }
89
+ ${CheckoutPageFragment}
90
+ `;
91
+
92
+ export const SOCIAL_GOOGLE_AUTHENTICATE = gql`
93
+ mutation SocialGoogleAuthenticate($jwt_token: String!) {
94
+ socialGoogleAuthenticate(jwt_token: $jwt_token) {
95
+ token
96
+ }
97
+ }
98
+ `;
99
+
100
+ export default {
101
+ GET_CART_DETAILS_QUERY: GET_CART_DETAILS_QUERY,
102
+ createCartMutation: CREATE_CART,
103
+ getCustomerQuery: GET_CUSTOMER,
104
+ mergeCartsMutation: MERGE_CARTS,
105
+ socialGoogleAuthenticateMutation: SOCIAL_GOOGLE_AUTHENTICATE
106
+ };
@@ -0,0 +1,169 @@
1
+ import { useCallback, useEffect, useRef, useState, useMemo } from 'react';
2
+ import { useApolloClient, useMutation } from '@apollo/client';
3
+
4
+ import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
5
+ import { useCartContext } from '@magento/peregrine/lib/context/cart';
6
+ import { useUserContext } from '@magento/peregrine/lib/context/user';
7
+ import { useAwaitQuery } from '@magento/peregrine/lib/hooks/useAwaitQuery';
8
+ import { retrieveCartId } from '@magento/peregrine/lib/store/actions/cart';
9
+ import { useToasts } from '@magento/peregrine/lib/Toasts';
10
+ import DEFAULT_OPERATIONS from './socialLogin.gql'
11
+ import { useEventingContext } from '@magento/peregrine/lib/context/eventing';
12
+ import { BrowserPersistence } from '@magento/peregrine/lib/util';
13
+
14
+ const storage = new BrowserPersistence();
15
+
16
+ export const useSocialLogin = props => {
17
+ const {
18
+ jwtToken
19
+ } = props;
20
+
21
+ const [, { addToast }] = useToasts();
22
+
23
+ const operations = mergeOperations(DEFAULT_OPERATIONS, props.operations);
24
+ const {
25
+ createCartMutation,
26
+ getCustomerQuery,
27
+ mergeCartsMutation,
28
+ getCartDetailsQuery,
29
+ socialGoogleAuthenticateMutation
30
+ } = operations;
31
+
32
+ const apolloClient = useApolloClient();
33
+ const [isSigningIn, setIsSigningIn] = useState(false);
34
+
35
+ const [
36
+ { cartId },
37
+ { createCart, removeCart, getCartDetails }
38
+ ] = useCartContext();
39
+
40
+ const [
41
+ { isGettingDetails, getDetailsError },
42
+ { getUserDetails, setToken }
43
+ ] = useUserContext();
44
+
45
+ const [, { dispatch }] = useEventingContext();
46
+
47
+ const [signIn, { error: signInError }] = useMutation(socialGoogleAuthenticateMutation, {
48
+ fetchPolicy: 'no-cache'
49
+ });
50
+
51
+ const generateReCaptchaData = null;
52
+
53
+ const [fetchCartId] = useMutation(createCartMutation);
54
+ const [mergeCarts] = useMutation(mergeCartsMutation);
55
+ const fetchUserDetails = useAwaitQuery(getCustomerQuery);
56
+ const fetchCartDetails = useAwaitQuery(getCartDetailsQuery);
57
+
58
+ const formApiRef = useRef(null);
59
+ const setFormApi = useCallback(api => (formApiRef.current = api), []);
60
+
61
+ useEffect(async () => {
62
+ if (jwtToken) {
63
+ setIsSigningIn(true);
64
+ try {
65
+ // Get source cart id (guest cart id).
66
+ const sourceCartId = cartId;
67
+
68
+ // Sign in and set the token.
69
+ const signInResponse = await signIn({
70
+ variables: {
71
+ jwt_token: jwtToken
72
+ }
73
+ });
74
+
75
+ const token = signInResponse.data.socialGoogleAuthenticate.token;
76
+ await setToken(token);
77
+
78
+ await getUserDetails({ fetchUserDetails });
79
+
80
+ // Clear all cart/customer data from cache and redux.
81
+ await apolloClient.clearCacheData(apolloClient, 'cart');
82
+ await apolloClient.clearCacheData(apolloClient, 'customer');
83
+ await removeCart();
84
+
85
+ // Create and get the customer's cart id.
86
+ await createCart({
87
+ fetchCartId
88
+ });
89
+ const destinationCartId = await retrieveCartId();
90
+
91
+ // Merge the guest cart into the customer cart.
92
+ await mergeCarts({
93
+ variables: {
94
+ destinationCartId,
95
+ sourceCartId
96
+ }
97
+ });
98
+
99
+ // Ensure old stores are updated with any new data.
100
+
101
+
102
+ const { data } = await fetchUserDetails({
103
+ fetchPolicy: 'cache-only'
104
+ });
105
+
106
+ if (data.customer.is_seller) {
107
+ storage.setItem('is_seller', true);
108
+ }
109
+
110
+ dispatch({
111
+ type: 'USER_SIGN_IN',
112
+ payload: {
113
+ ...data.customer
114
+ }
115
+ });
116
+
117
+ getCartDetails({ fetchCartId, fetchCartDetails });
118
+
119
+ addToast({
120
+ type: 'success',
121
+ message: formatMessage({
122
+ id: 'signIn.signInSuccessToast',
123
+ defaultMessage: "You have successfully signed in."
124
+ }),
125
+ timeout: 5000
126
+ });
127
+ } catch (error) {
128
+ if (process.env.NODE_ENV !== 'production') {
129
+ console.error(error);
130
+ }
131
+
132
+ setIsSigningIn(false);
133
+ }
134
+ }
135
+ }, [
136
+ jwtToken,
137
+ cartId,
138
+ generateReCaptchaData,
139
+ signIn,
140
+ setToken,
141
+ apolloClient,
142
+ removeCart,
143
+ createCart,
144
+ fetchCartId,
145
+ mergeCarts,
146
+ getUserDetails,
147
+ fetchUserDetails,
148
+ getCartDetails,
149
+ fetchCartDetails,
150
+ dispatch
151
+ ]
152
+ );
153
+
154
+ const errors = useMemo(
155
+ () =>
156
+ new Map([
157
+ ['getUserDetailsQuery', getDetailsError],
158
+ ['socialGoogleAuthenticateMutation', signInError]
159
+ ]),
160
+ [getDetailsError, signInError]
161
+ );
162
+
163
+ return {
164
+ errors,
165
+ // isBusy: isGettingDetails || isSigningIn || recaptchaLoading,
166
+ isBusy: isGettingDetails || isSigningIn,
167
+ setFormApi
168
+ };
169
+ };