@magento/peregrine 12.0.0-alpha.2 → 12.1.0-alpha.1
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/lib/Apollo/clearCartDataFromCache.js +12 -15
- package/lib/Apollo/clearCustomerDataFromCache.js +8 -20
- package/lib/Apollo/deleteCacheEntry.js +87 -0
- package/lib/Price/price.js +0 -1
- package/lib/context/cart.js +21 -1
- package/lib/store/actions/cart/asyncActions.js +1 -1
- package/lib/talons/CartPage/PriceAdjustments/CouponCode/useCouponCode.js +1 -1
- package/lib/talons/CartPage/PriceAdjustments/ShippingMethods/useShippingMethods.js +1 -1
- package/lib/talons/CartPage/PriceAdjustments/ShippingMethods/useShippingRadios.js +1 -1
- package/lib/talons/CartPage/ProductListing/EditModal/__fixtures__/configurableProduct.js +1 -0
- package/lib/talons/CartPage/ProductListing/EditModal/productForm.gql.js +7 -4
- package/lib/talons/CartPage/ProductListing/EditModal/productFormFragment.gql.js +1 -0
- package/lib/talons/CartPage/ProductListing/EditModal/useProductForm.js +2 -2
- package/lib/talons/CartPage/ProductListing/productListingFragments.gql.js +1 -0
- package/lib/talons/CartPage/ProductListing/useProduct.js +4 -4
- package/lib/talons/Gallery/useAddToCartButton.js +16 -2
- package/lib/talons/MiniCart/ProductList/productListFragments.gql.js +1 -0
- package/lib/talons/MiniCart/useItem.js +3 -3
- package/lib/talons/Newsletter/newsletter.gql.js +11 -0
- package/lib/talons/Newsletter/useNewsletter.js +51 -0
- package/lib/talons/ProductFullDetail/useProductFullDetail.js +7 -1
- package/lib/talons/RootComponents/Category/categoryFragments.gql.js +1 -0
- package/lib/talons/RootComponents/Product/product.gql.js +1 -0
- package/lib/talons/RootComponents/Product/productDetailFragment.gql.js +3 -0
- package/lib/targets/peregrine-declare.js +0 -4
- package/package.json +1 -1
|
@@ -1,22 +1,19 @@
|
|
|
1
|
+
import { deleteCacheEntry } from './deleteCacheEntry';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
|
-
* Deletes all references to Cart from the apollo cache
|
|
4
|
+
* Deletes all references to Cart from the apollo cache including entries that
|
|
5
|
+
* start with "$" which were automatically created by Apollo InMemoryCache.
|
|
3
6
|
*
|
|
4
7
|
* @param {ApolloClient} client
|
|
5
8
|
*/
|
|
6
9
|
export const clearCartDataFromCache = async client => {
|
|
7
|
-
|
|
8
|
-
client.cache.evict({ id: 'Cart' });
|
|
9
|
-
client.cache.evict({
|
|
10
|
-
id: 'ROOT_MUTATION',
|
|
11
|
-
fieldName: 'placeOrder'
|
|
12
|
-
});
|
|
13
|
-
// Cached ROOT_QUERY
|
|
14
|
-
client.cache.evict({ fieldName: 'cart' });
|
|
15
|
-
client.cache.evict({ fieldName: 'customerCart' });
|
|
16
|
-
|
|
17
|
-
client.cache.gc();
|
|
10
|
+
await deleteCacheEntry(client, key => key.match(/^\$?Cart/));
|
|
18
11
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
// Any cart subtypes that have key fields must be manually cleared.
|
|
13
|
+
// TODO: we may be able to use cache.evict here instead.
|
|
14
|
+
await deleteCacheEntry(client, key => key.match(/^\$?AppliedGiftCard/));
|
|
15
|
+
await deleteCacheEntry(client, key => key.match(/^\$?ShippingCartAddress/));
|
|
16
|
+
await deleteCacheEntry(client, key =>
|
|
17
|
+
key.match(/^\$?AvailableShippingMethod/)
|
|
18
|
+
);
|
|
22
19
|
};
|
|
@@ -1,26 +1,14 @@
|
|
|
1
|
+
import { deleteCacheEntry } from './deleteCacheEntry';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
|
-
* Deletes all references to Customer from the apollo cache
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Deletes all references to Customer from the apollo cache including entries
|
|
5
|
+
* that start with "$" which were automatically created by Apollo InMemoryCache.
|
|
6
|
+
* By coincidence this rule additionally clears CustomerAddress entries, but
|
|
7
|
+
* we'll need to keep this in mind by adding additional patterns as MyAccount
|
|
8
|
+
* features are completed.
|
|
6
9
|
*
|
|
7
10
|
* @param {ApolloClient} client
|
|
8
11
|
*/
|
|
9
12
|
export const clearCustomerDataFromCache = async client => {
|
|
10
|
-
|
|
11
|
-
client.cache.evict({ id: 'Customer' });
|
|
12
|
-
// Remove createCustomerAddress which references newly created addresses, avoiding gc
|
|
13
|
-
client.cache.evict({
|
|
14
|
-
id: 'ROOT_MUTATION',
|
|
15
|
-
fieldName: 'createCustomerAddress'
|
|
16
|
-
});
|
|
17
|
-
// Cached ROOT_QUERY
|
|
18
|
-
client.cache.evict({ fieldName: 'customer' });
|
|
19
|
-
client.cache.evict({ fieldName: 'customerWishlistProducts' });
|
|
20
|
-
|
|
21
|
-
client.cache.gc();
|
|
22
|
-
|
|
23
|
-
if (client.persistor) {
|
|
24
|
-
await client.persistor.persist();
|
|
25
|
-
}
|
|
13
|
+
await deleteCacheEntry(client, key => key.match(/^\$?Customer/i));
|
|
26
14
|
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { CACHE_PERSIST_PREFIX } from '@magento/peregrine/lib/Apollo/constants';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Deletes specific entry/entries from the apollo cache and then tries to
|
|
5
|
+
* persist the deletions.
|
|
6
|
+
*
|
|
7
|
+
* @param {ApolloClient} client apollo client instance
|
|
8
|
+
* @param {Function} predicate a matching function
|
|
9
|
+
*/
|
|
10
|
+
export const deleteCacheEntry = async (client, predicate) => {
|
|
11
|
+
await deleteActiveCacheEntry(client, predicate);
|
|
12
|
+
await deleteInactiveCachesEntry(client, predicate);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const deleteActiveCacheEntry = async (client, predicate) => {
|
|
16
|
+
// If there is no client or cache then just back out since it doesn't matter :D
|
|
17
|
+
if (
|
|
18
|
+
!client ||
|
|
19
|
+
!client.cache ||
|
|
20
|
+
!client.cache.data ||
|
|
21
|
+
!client.cache.data.data
|
|
22
|
+
) {
|
|
23
|
+
if (process.env.NODE_ENV === 'development') {
|
|
24
|
+
console.warn(
|
|
25
|
+
'Apollo Cache entry deletion attempted without client or cache.'
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Remove from the active cache.
|
|
32
|
+
Object.keys(client.cache.data.data).forEach(key => {
|
|
33
|
+
if (predicate(key)) {
|
|
34
|
+
client.cache.data.delete(key);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// Remove from ROOT_QUERY cache.
|
|
39
|
+
if (client.cache.data.data.ROOT_QUERY) {
|
|
40
|
+
Object.keys(client.cache.data.data.ROOT_QUERY).forEach(key => {
|
|
41
|
+
if (predicate(key)) {
|
|
42
|
+
client.cache.data.delete('ROOT_QUERY', key);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Immediately persist the cache changes to the active cache storage.
|
|
48
|
+
if (client.persistor) {
|
|
49
|
+
await client.persistor.persist();
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const deleteInactiveCachesEntry = async (client, predicate) => {
|
|
54
|
+
if (!client || !client.persistor || !globalThis.localStorage) return;
|
|
55
|
+
|
|
56
|
+
const activeApolloCacheLocalStorageKey =
|
|
57
|
+
client.persistor.persistor.storage.key;
|
|
58
|
+
|
|
59
|
+
const isAnInactiveApolloCache = ([key]) => {
|
|
60
|
+
return (
|
|
61
|
+
key.startsWith(CACHE_PERSIST_PREFIX) &&
|
|
62
|
+
key !== activeApolloCacheLocalStorageKey
|
|
63
|
+
);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const { localStorage } = globalThis;
|
|
67
|
+
|
|
68
|
+
Object.entries(localStorage)
|
|
69
|
+
.filter(isAnInactiveApolloCache)
|
|
70
|
+
.forEach(([inactiveCacheKey, inactiveCacheValue]) => {
|
|
71
|
+
const inactiveApolloCache = JSON.parse(inactiveCacheValue);
|
|
72
|
+
|
|
73
|
+
Object.keys(inactiveApolloCache).forEach(key => {
|
|
74
|
+
if (predicate(key)) {
|
|
75
|
+
delete inactiveApolloCache[key];
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// We're done deleting keys that match the predicate,
|
|
80
|
+
// but we've only mutated the object in memory.
|
|
81
|
+
// Write the updated inactive cache back out to localStorage.
|
|
82
|
+
localStorage.setItem(
|
|
83
|
+
inactiveCacheKey,
|
|
84
|
+
JSON.stringify(inactiveApolloCache)
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
};
|
package/lib/Price/price.js
CHANGED
|
@@ -15,7 +15,6 @@ import { useIntl } from 'react-intl';
|
|
|
15
15
|
* [polyfill]: https://www.npmjs.com/package/intl
|
|
16
16
|
* [Intl.NumberFormat.prototype.formatToParts]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts
|
|
17
17
|
*/
|
|
18
|
-
|
|
19
18
|
const Price = props => {
|
|
20
19
|
const { locale } = useIntl();
|
|
21
20
|
const { value, currencyCode, classes } = props;
|
package/lib/context/cart.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {
|
|
2
|
+
createContext,
|
|
3
|
+
useContext,
|
|
4
|
+
useEffect,
|
|
5
|
+
useMemo,
|
|
6
|
+
useCallback
|
|
7
|
+
} from 'react';
|
|
2
8
|
import { connect } from 'react-redux';
|
|
3
9
|
import { useMutation } from '@apollo/client';
|
|
4
10
|
import gql from 'graphql-tag';
|
|
@@ -7,6 +13,8 @@ import { useAwaitQuery } from '@magento/peregrine/lib/hooks/useAwaitQuery';
|
|
|
7
13
|
import actions from '../store/actions/cart/actions';
|
|
8
14
|
import * as asyncActions from '../store/actions/cart/asyncActions';
|
|
9
15
|
import bindActionCreators from '../util/bindActionCreators';
|
|
16
|
+
import { useEventListener } from '../hooks/useEventListener';
|
|
17
|
+
import BrowserPersistence from '../util/simplePersistence';
|
|
10
18
|
|
|
11
19
|
const CartContext = createContext();
|
|
12
20
|
|
|
@@ -57,6 +65,18 @@ const CartContextProvider = props => {
|
|
|
57
65
|
const [fetchCartId] = useMutation(CREATE_CART_MUTATION);
|
|
58
66
|
const fetchCartDetails = useAwaitQuery(CART_DETAILS_QUERY);
|
|
59
67
|
|
|
68
|
+
// Storage listener to force a state update if cartId changes from another browser tab.
|
|
69
|
+
const storageListener = useCallback(() => {
|
|
70
|
+
const storage = new BrowserPersistence();
|
|
71
|
+
const currentCartId = storage.getItem('cartId');
|
|
72
|
+
const { cartId } = cartState;
|
|
73
|
+
if (cartId && currentCartId && cartId !== currentCartId) {
|
|
74
|
+
globalThis.location && globalThis.location.reload();
|
|
75
|
+
}
|
|
76
|
+
}, [cartState]);
|
|
77
|
+
|
|
78
|
+
useEventListener(globalThis, 'storage', storageListener);
|
|
79
|
+
|
|
60
80
|
useEffect(() => {
|
|
61
81
|
// cartApi.getCartDetails initializes the cart if there isn't one.
|
|
62
82
|
cartApi.getCartDetails({
|
|
@@ -23,7 +23,7 @@ import DEFAULT_OPERATIONS from './couponCode.gql';
|
|
|
23
23
|
* @return {CouponCodeTalonProps}
|
|
24
24
|
*
|
|
25
25
|
* @example <caption>Importing into your project</caption>
|
|
26
|
-
* import { useCouponCode } from '@magento/peregrine/lib/talons/CartPage/PriceAdjustments/useCouponCode';
|
|
26
|
+
* import { useCouponCode } from '@magento/peregrine/lib/talons/CartPage/PriceAdjustments/CouponCode/useCouponCode';
|
|
27
27
|
*/
|
|
28
28
|
export const useCouponCode = props => {
|
|
29
29
|
const operations = mergeOperations(DEFAULT_OPERATIONS, props.operations);
|
|
@@ -120,7 +120,7 @@ export const useShippingMethods = (props = {}) => {
|
|
|
120
120
|
* Can be used as a boolean value since having no shipping methods would return 0.
|
|
121
121
|
* @property {boolean} isShowingForm True if the form should be shown. False otherwise.
|
|
122
122
|
* @property {SelectShippingFields} selectedShippingFields Values for the select input fields on the shipping form
|
|
123
|
-
* @property {String} selectedShippingMethod A serialized string of <carrier-code
|
|
123
|
+
* @property {String} selectedShippingMethod A serialized string of <inlineCode>${carrier-code}\|${method-code}</inlineCode>, eg. <inlineCode>usps\|priority</inlineCode>.
|
|
124
124
|
* @property {Array<Object>} shippingMethods A list of available shipping methods based on the primary shipping address
|
|
125
125
|
* @property {function} showForm A function that sets the `isShowingForm` value to true.
|
|
126
126
|
*/
|
|
@@ -17,7 +17,7 @@ import { useCartContext } from '../../../../context/cart';
|
|
|
17
17
|
*
|
|
18
18
|
* @param {Object} props
|
|
19
19
|
* @param {function} props.setIsCartUpdating Function for setting the updating state of the shopping cart
|
|
20
|
-
* @param {String} props.selectedShippingMethod A serialized string of <carrier-code
|
|
20
|
+
* @param {String} props.selectedShippingMethod A serialized string of <inlineCode>${carrier-code}\|${method-code}</inlineCode>, eg. <inlineCode>usps\|priority</inlineCode>.
|
|
21
21
|
* @param {Array<Object>} props.shippingMethods An array of available shipping methods
|
|
22
22
|
* @param {ShippingRadiosMutations} props.mutations GraphQL mutations for a shipping radio selector component.
|
|
23
23
|
*
|
|
@@ -7,6 +7,7 @@ const GET_CONFIGURABLE_OPTIONS = gql`
|
|
|
7
7
|
products(filter: { sku: { eq: $sku } }) {
|
|
8
8
|
items {
|
|
9
9
|
id
|
|
10
|
+
uid
|
|
10
11
|
...ProductFormFragment
|
|
11
12
|
}
|
|
12
13
|
}
|
|
@@ -17,13 +18,15 @@ const GET_CONFIGURABLE_OPTIONS = gql`
|
|
|
17
18
|
const UPDATE_QUANTITY_MUTATION = gql`
|
|
18
19
|
mutation UpdateCartItemQuantity(
|
|
19
20
|
$cartId: String!
|
|
20
|
-
$cartItemId:
|
|
21
|
+
$cartItemId: ID!
|
|
21
22
|
$quantity: Float!
|
|
22
23
|
) {
|
|
23
24
|
updateCartItems(
|
|
24
25
|
input: {
|
|
25
26
|
cart_id: $cartId
|
|
26
|
-
cart_items: [
|
|
27
|
+
cart_items: [
|
|
28
|
+
{ cart_item_uid: $cartItemId, quantity: $quantity }
|
|
29
|
+
]
|
|
27
30
|
}
|
|
28
31
|
) @connection(key: "updateCartItems") {
|
|
29
32
|
cart {
|
|
@@ -38,7 +41,7 @@ const UPDATE_QUANTITY_MUTATION = gql`
|
|
|
38
41
|
const UPDATE_CONFIGURABLE_OPTIONS_MUTATION = gql`
|
|
39
42
|
mutation UpdateConfigurableOptions(
|
|
40
43
|
$cartId: String!
|
|
41
|
-
$cartItemId:
|
|
44
|
+
$cartItemId: ID!
|
|
42
45
|
$parentSku: String!
|
|
43
46
|
$variantSku: String!
|
|
44
47
|
$quantity: Float!
|
|
@@ -60,7 +63,7 @@ const UPDATE_CONFIGURABLE_OPTIONS_MUTATION = gql`
|
|
|
60
63
|
}
|
|
61
64
|
|
|
62
65
|
removeItemFromCart(
|
|
63
|
-
input: { cart_id: $cartId,
|
|
66
|
+
input: { cart_id: $cartId, cart_item_uid: $cartItemId }
|
|
64
67
|
) @connection(key: "removeItemFromCart") {
|
|
65
68
|
cart {
|
|
66
69
|
id
|
|
@@ -156,7 +156,7 @@ export const useProductForm = props => {
|
|
|
156
156
|
await updateConfigurableOptions({
|
|
157
157
|
variables: {
|
|
158
158
|
cartId,
|
|
159
|
-
cartItemId: cartItem.
|
|
159
|
+
cartItemId: cartItem.uid,
|
|
160
160
|
parentSku: cartItem.product.sku,
|
|
161
161
|
variantSku: selectedVariant.product.sku,
|
|
162
162
|
quantity: formValues.quantity
|
|
@@ -168,7 +168,7 @@ export const useProductForm = props => {
|
|
|
168
168
|
await updateItemQuantity({
|
|
169
169
|
variables: {
|
|
170
170
|
cartId,
|
|
171
|
-
cartItemId: cartItem.
|
|
171
|
+
cartItemId: cartItem.uid,
|
|
172
172
|
quantity: formValues.quantity
|
|
173
173
|
}
|
|
174
174
|
});
|
|
@@ -128,14 +128,14 @@ export const useProduct = props => {
|
|
|
128
128
|
await removeItemFromCart({
|
|
129
129
|
variables: {
|
|
130
130
|
cartId,
|
|
131
|
-
itemId: item.
|
|
131
|
+
itemId: item.uid
|
|
132
132
|
}
|
|
133
133
|
});
|
|
134
134
|
} catch (err) {
|
|
135
135
|
// Make sure any errors from the mutation are displayed.
|
|
136
136
|
setDisplayError(true);
|
|
137
137
|
}
|
|
138
|
-
}, [cartId, item.
|
|
138
|
+
}, [cartId, item.uid, removeItemFromCart]);
|
|
139
139
|
|
|
140
140
|
const handleUpdateItemQuantity = useCallback(
|
|
141
141
|
async quantity => {
|
|
@@ -143,7 +143,7 @@ export const useProduct = props => {
|
|
|
143
143
|
await updateItemQuantity({
|
|
144
144
|
variables: {
|
|
145
145
|
cartId,
|
|
146
|
-
itemId: item.
|
|
146
|
+
itemId: item.uid,
|
|
147
147
|
quantity
|
|
148
148
|
}
|
|
149
149
|
});
|
|
@@ -152,7 +152,7 @@ export const useProduct = props => {
|
|
|
152
152
|
setDisplayError(true);
|
|
153
153
|
}
|
|
154
154
|
},
|
|
155
|
-
[cartId, item.
|
|
155
|
+
[cartId, item.uid, updateItemQuantity]
|
|
156
156
|
);
|
|
157
157
|
|
|
158
158
|
useEffect(() => {
|
|
@@ -56,7 +56,12 @@ export const useAddToCartButton = props => {
|
|
|
56
56
|
cartId,
|
|
57
57
|
cartItem: {
|
|
58
58
|
quantity: 1,
|
|
59
|
-
|
|
59
|
+
entered_options: [
|
|
60
|
+
{
|
|
61
|
+
uid: item.uid,
|
|
62
|
+
value: item.name
|
|
63
|
+
}
|
|
64
|
+
],
|
|
60
65
|
sku: item.sku
|
|
61
66
|
}
|
|
62
67
|
}
|
|
@@ -71,7 +76,16 @@ export const useAddToCartButton = props => {
|
|
|
71
76
|
} catch (error) {
|
|
72
77
|
console.error(error);
|
|
73
78
|
}
|
|
74
|
-
}, [
|
|
79
|
+
}, [
|
|
80
|
+
addToCart,
|
|
81
|
+
cartId,
|
|
82
|
+
history,
|
|
83
|
+
item.sku,
|
|
84
|
+
item.url_key,
|
|
85
|
+
productType,
|
|
86
|
+
item.uid,
|
|
87
|
+
item.name
|
|
88
|
+
]);
|
|
75
89
|
|
|
76
90
|
return {
|
|
77
91
|
handleAddToCart,
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { useState, useCallback } from 'react';
|
|
2
2
|
|
|
3
3
|
export const useItem = props => {
|
|
4
|
-
const {
|
|
4
|
+
const { uid, handleRemoveItem } = props;
|
|
5
5
|
|
|
6
6
|
const [isDeleting, setIsDeleting] = useState(false);
|
|
7
7
|
|
|
8
8
|
const removeItem = useCallback(() => {
|
|
9
9
|
setIsDeleting(true);
|
|
10
|
-
handleRemoveItem(
|
|
11
|
-
}, [handleRemoveItem,
|
|
10
|
+
handleRemoveItem(uid);
|
|
11
|
+
}, [handleRemoveItem, uid]);
|
|
12
12
|
|
|
13
13
|
return {
|
|
14
14
|
isDeleting,
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { gql } from '@apollo/client';
|
|
2
|
+
export const SUBSCRIBE_TO_NEWSLETTER = gql`
|
|
3
|
+
mutation SubscribeToNewsletter($email: String!) {
|
|
4
|
+
subscribeEmailToNewsletter(email: $email) {
|
|
5
|
+
status
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
`;
|
|
9
|
+
export default {
|
|
10
|
+
subscribeMutation: SUBSCRIBE_TO_NEWSLETTER
|
|
11
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { useCallback, useRef, useState, useMemo } from 'react';
|
|
2
|
+
import { useMutation } from '@apollo/client';
|
|
3
|
+
import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
|
|
4
|
+
import DEFAULT_OPERATIONS from './newsletter.gql';
|
|
5
|
+
|
|
6
|
+
export const useNewsletter = (props = {}) => {
|
|
7
|
+
const { subscribeMutation } = mergeOperations(
|
|
8
|
+
DEFAULT_OPERATIONS,
|
|
9
|
+
props.operations
|
|
10
|
+
);
|
|
11
|
+
const [subscribing, setSubscribing] = useState(false);
|
|
12
|
+
const [subscribeNewsLetter, { error: newsLetterError, data }] = useMutation(
|
|
13
|
+
subscribeMutation,
|
|
14
|
+
{
|
|
15
|
+
fetchPolicy: 'no-cache'
|
|
16
|
+
}
|
|
17
|
+
);
|
|
18
|
+
const formApiRef = useRef(null);
|
|
19
|
+
const setFormApi = useCallback(api => (formApiRef.current = api), []);
|
|
20
|
+
const handleSubmit = useCallback(
|
|
21
|
+
async ({ email }) => {
|
|
22
|
+
setSubscribing(true);
|
|
23
|
+
try {
|
|
24
|
+
await subscribeNewsLetter({
|
|
25
|
+
variables: { email }
|
|
26
|
+
});
|
|
27
|
+
if (formApiRef.current) {
|
|
28
|
+
formApiRef.current.reset();
|
|
29
|
+
}
|
|
30
|
+
} catch (error) {
|
|
31
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
32
|
+
console.error(error);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
setSubscribing(false);
|
|
36
|
+
},
|
|
37
|
+
[subscribeNewsLetter]
|
|
38
|
+
);
|
|
39
|
+
const errors = useMemo(
|
|
40
|
+
() => new Map([['subscribeMutation', newsLetterError]]),
|
|
41
|
+
[newsLetterError]
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
errors,
|
|
46
|
+
handleSubmit,
|
|
47
|
+
isBusy: subscribing,
|
|
48
|
+
setFormApi,
|
|
49
|
+
newsLetterResponse: data && data.subscribeEmailToNewsletter
|
|
50
|
+
};
|
|
51
|
+
};
|
|
@@ -368,7 +368,13 @@ export const useProductFullDetail = props => {
|
|
|
368
368
|
product: {
|
|
369
369
|
sku: product.sku,
|
|
370
370
|
quantity
|
|
371
|
-
}
|
|
371
|
+
},
|
|
372
|
+
entered_options: [
|
|
373
|
+
{
|
|
374
|
+
uid: product.uid,
|
|
375
|
+
value: product.name
|
|
376
|
+
}
|
|
377
|
+
]
|
|
372
378
|
};
|
|
373
379
|
|
|
374
380
|
if (selectedOptionsArray.length) {
|
|
@@ -5,6 +5,7 @@ export const ProductDetailsFragment = gql`
|
|
|
5
5
|
__typename
|
|
6
6
|
categories {
|
|
7
7
|
id
|
|
8
|
+
uid
|
|
8
9
|
breadcrumbs {
|
|
9
10
|
category_id
|
|
10
11
|
}
|
|
@@ -13,6 +14,7 @@ export const ProductDetailsFragment = gql`
|
|
|
13
14
|
html
|
|
14
15
|
}
|
|
15
16
|
id
|
|
17
|
+
uid
|
|
16
18
|
media_gallery_entries {
|
|
17
19
|
# id is deprecated and unused in our code, but lint rules require we
|
|
18
20
|
# request it if available
|
|
@@ -67,6 +69,7 @@ export const ProductDetailsFragment = gql`
|
|
|
67
69
|
}
|
|
68
70
|
product {
|
|
69
71
|
id
|
|
72
|
+
uid
|
|
70
73
|
media_gallery_entries {
|
|
71
74
|
# id is deprecated and unused in our code, but lint rules require we
|
|
72
75
|
# request it if available
|
|
@@ -20,8 +20,6 @@ module.exports = targets => {
|
|
|
20
20
|
*
|
|
21
21
|
* @member {tapable.AsyncSeriesHook}
|
|
22
22
|
*
|
|
23
|
-
* @see [list of wrappable hooks][]
|
|
24
|
-
*
|
|
25
23
|
* @see [Intercept function signature]{@link hookInterceptFunction}
|
|
26
24
|
*
|
|
27
25
|
* @example <caption>Access the tapable object</caption>
|
|
@@ -49,8 +47,6 @@ module.exports = targets => {
|
|
|
49
47
|
*
|
|
50
48
|
* @member {tapable.AsyncSeriesHook}
|
|
51
49
|
*
|
|
52
|
-
* @see [list of wrappable talons][]
|
|
53
|
-
*
|
|
54
50
|
* @see [Intercept function signature]{@link hookInterceptFunction}
|
|
55
51
|
*
|
|
56
52
|
* @example <caption>Access the tapable object</caption>
|