@magento/peregrine 12.2.0 → 12.3.0

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 (47) hide show
  1. package/lib/Apollo/clearCustomerDataFromCache.js +1 -0
  2. package/lib/Apollo/policies/index.js +9 -4
  3. package/lib/hooks/useGoogleReCaptcha/googleReCaptchaConfig.gql.js +16 -0
  4. package/lib/hooks/useGoogleReCaptcha/index.js +1 -0
  5. package/lib/hooks/useGoogleReCaptcha/useGoogleReCaptcha.js +210 -0
  6. package/lib/hooks/useMediaQuery.js +83 -0
  7. package/lib/hooks/useScript.js +68 -0
  8. package/lib/hooks/useSort.js +13 -2
  9. package/lib/talons/AccountInformationPage/useAccountInformationPage.js +23 -6
  10. package/lib/talons/CartPage/PriceAdjustments/GiftOptions/giftOptions.gql.js +36 -11
  11. package/lib/talons/CartPage/PriceAdjustments/GiftOptions/giftOptionsFragments.gql.js +19 -0
  12. package/lib/talons/CartPage/PriceAdjustments/GiftOptions/useGiftOptions.js +315 -94
  13. package/lib/talons/CartPage/PriceAdjustments/giftOptionsSection.gql.js +17 -0
  14. package/lib/talons/CartPage/PriceAdjustments/useGiftOptionsSection.js +61 -0
  15. package/lib/talons/CartPage/PriceSummary/__fixtures__/priceSummary.js +7 -2
  16. package/lib/talons/CartPage/PriceSummary/priceSummaryFragments.gql.js +7 -0
  17. package/lib/talons/CartPage/PriceSummary/queries/giftOptionsSummary.ce.js +8 -0
  18. package/lib/talons/CartPage/PriceSummary/queries/giftOptionsSummary.ee.js +15 -0
  19. package/lib/talons/CartPage/PriceSummary/useDiscountSummary.js +71 -0
  20. package/lib/talons/CartPage/PriceSummary/usePriceSummary.js +3 -1
  21. package/lib/talons/CartPage/ProductListing/EditModal/__fixtures__/configurableThumbnailSource.js +8 -0
  22. package/lib/talons/CartPage/ProductListing/EditModal/productForm.gql.js +11 -0
  23. package/lib/talons/CartPage/ProductListing/EditModal/useProductForm.js +15 -1
  24. package/lib/talons/CheckoutPage/OrderConfirmationPage/useCreateAccount.js +27 -5
  25. package/lib/talons/CheckoutPage/PaymentInformation/useCreditCard.js +36 -15
  26. package/lib/talons/CheckoutPage/useCheckoutPage.js +18 -3
  27. package/lib/talons/CmsDynamicBlock/client-schema.graphql +4 -0
  28. package/lib/talons/CmsDynamicBlock/cmsDynamicBlock.gql.js +113 -0
  29. package/lib/talons/CmsDynamicBlock/useCmsDynamicBlock.js +211 -0
  30. package/lib/talons/CreateAccount/useCreateAccount.js +29 -5
  31. package/lib/talons/ForgotPassword/useForgotPassword.js +26 -5
  32. package/lib/talons/Link/useLink.js +2 -1
  33. package/lib/talons/MiniCart/miniCartFragments.gql.js +4 -0
  34. package/lib/talons/MyAccount/useResetPassword.js +23 -5
  35. package/lib/talons/RootComponents/Category/useCategory.js +1 -1
  36. package/lib/talons/RootComponents/Product/useProduct.js +1 -6
  37. package/lib/talons/SearchPage/useSearchPage.js +1 -1
  38. package/lib/talons/SignIn/useSignIn.js +25 -6
  39. package/lib/talons/WishlistPage/createWishlist.gql.js +1 -0
  40. package/lib/talons/WishlistPage/useActionMenu.js +4 -4
  41. package/lib/talons/WishlistPage/useCreateWishlist.js +7 -4
  42. package/lib/talons/WishlistPage/useWishlistItem.js +3 -2
  43. package/lib/talons/WishlistPage/wishlistConfig.gql.ee.js +1 -0
  44. package/lib/talons/WishlistPage/wishlistItemFragments.gql.js +1 -0
  45. package/lib/util/configuredVariant.js +10 -6
  46. package/package.json +1 -1
  47. package/lib/talons/CartPage/PriceAdjustments/GiftOptions/client-schema.graphql +0 -7
@@ -1,7 +1,11 @@
1
- import { useCallback, useRef, useState } from 'react';
2
- import { useApolloClient, useQuery } from '@apollo/client';
1
+ import { useCallback, useMemo, useRef, useState } from 'react';
2
+ import { useMutation, useQuery } from '@apollo/client';
3
+ import debounce from 'lodash.debounce';
4
+
3
5
  import { useCartContext } from '@magento/peregrine/lib/context/cart';
4
6
  import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
7
+ import { isRequired } from '@magento/venia-ui/lib/util/formValidators';
8
+
5
9
  import DEFAULT_OPERATIONS from './giftOptions.gql';
6
10
 
7
11
  /**
@@ -16,145 +20,362 @@ import DEFAULT_OPERATIONS from './giftOptions.gql';
16
20
  * @function
17
21
  *
18
22
  * @param {Object} props
19
- * @param {GiftOptionsMutations} props.mutations GraphQL mutations for Gift Options
20
- * @param {GiftOptionsQueries} props.queries GraphQL queries for Gift Options
23
+ * @param {GiftOptionsOperations} props.operations
21
24
  *
22
25
  * @returns {GiftOptionsTalonProps}
23
26
  *
24
27
  * @example <caption>Importing into your project</caption>
25
28
  * import { useGiftOptions } from '@magento/peregrine/lib/talons/CartPage/GiftOptions/useGiftOptions';
26
29
  */
27
- const useGiftOptions = (props = {}) => {
30
+ export const useGiftOptions = (props = {}) => {
28
31
  const operations = mergeOperations(DEFAULT_OPERATIONS, props.operations);
29
- const { getGiftOptionsQuery } = operations;
32
+ const { setGiftOptionsOnCartMutation, getGiftOptionsQuery } = operations;
30
33
 
31
34
  const [{ cartId }] = useCartContext();
32
- const { cache } = useApolloClient();
33
-
34
- // The form will be a child, not a parent, so we can't call `useFormApi`.
35
- // Need to use a ref and `props.getApi` instead.
36
- const formApiRef = useRef();
37
- const [hasHydrated, setHasHydrated] = useState(false);
38
-
39
- // Could be an effect, but a callback should be slightly better.
40
- const handleCompleted = useCallback(
41
- data => {
42
- // Only write values to the form once, ideally before user input.
43
- // Afterward, treat client state as the single source of truth.
44
- if (data && !hasHydrated) {
45
- formApiRef.current.setValues({
46
- cardMessage: data.cart.local_gift_message,
47
- includeGiftReceipt: data.cart.include_gift_receipt,
48
- includePrintedCard: data.cart.include_printed_card
35
+
36
+ const [
37
+ setGiftOptionsOnCart,
38
+ { error: setGiftOptionsOnCartError }
39
+ ] = useMutation(setGiftOptionsOnCartMutation);
40
+ const {
41
+ data: getGiftOptionsData,
42
+ error: getGiftOptionsError,
43
+ loading
44
+ } = useQuery(getGiftOptionsQuery, {
45
+ fetchPolicy: 'cache-and-network',
46
+ nextFetchPolicy: 'cache-first',
47
+ skip: !cartId,
48
+ variables: { cartId }
49
+ });
50
+
51
+ const { cart } = getGiftOptionsData || {};
52
+
53
+ const formApiRef = useRef(null);
54
+
55
+ const [giftMessageIsChecked, setGiftMessageIsChecked] = useState(false);
56
+ const [showGiftMessageResult, setShowGiftMessageResult] = useState(false);
57
+ const [savingOptions, setSavingOptions] = useState([]);
58
+
59
+ const initialValues = useMemo(() => {
60
+ const hasInitialGiftMessage =
61
+ cart?.gift_message?.from.length > 0 ||
62
+ cart?.gift_message?.to.length > 0 ||
63
+ cart?.gift_message?.message.length > 0;
64
+
65
+ if (formApiRef?.current?.getState()?.values === undefined) {
66
+ setGiftMessageIsChecked(hasInitialGiftMessage);
67
+ setShowGiftMessageResult(hasInitialGiftMessage);
68
+ }
69
+
70
+ return {
71
+ cardFrom: cart?.gift_message?.from || '',
72
+ cardTo: cart?.gift_message?.to || '',
73
+ cardMessage: cart?.gift_message?.message || '',
74
+ includeGiftReceipt: cart?.gift_receipt_included === true,
75
+ includeGiftMessage: hasInitialGiftMessage,
76
+ includePrintedCard: cart?.printed_card_included === true
77
+ };
78
+ }, [cart]);
79
+
80
+ const giftMessageResult = useMemo(
81
+ () => ({
82
+ cardFrom: cart?.gift_message?.from || '',
83
+ cardTo: cart?.gift_message?.to || '',
84
+ cardMessage: cart?.gift_message?.message || ''
85
+ }),
86
+ [
87
+ cart?.gift_message?.from,
88
+ cart?.gift_message?.message,
89
+ cart?.gift_message?.to
90
+ ]
91
+ );
92
+
93
+ const printedCardPrice = cart?.prices?.gift_options?.printed_card || {};
94
+
95
+ const hasGiftMessage =
96
+ giftMessageResult.cardFrom.length > 0 &&
97
+ giftMessageResult.cardTo.length > 0 &&
98
+ giftMessageResult.cardMessage.length > 0;
99
+
100
+ const setFormApi = useCallback(api => (formApiRef.current = api), []);
101
+
102
+ const handleOnChange = useCallback(async () => {
103
+ try {
104
+ const formApi = formApiRef.current;
105
+
106
+ if (formApi) {
107
+ await setGiftOptionsOnCart({
108
+ variables: {
109
+ cartId,
110
+ giftReceiptIncluded: formApi.getValue(
111
+ 'includeGiftReceipt'
112
+ ),
113
+ printedCardIncluded: formApi.getValue(
114
+ 'includePrintedCard'
115
+ )
116
+ }
49
117
  });
50
118
 
51
- setHasHydrated(true);
119
+ // Reset saving options when mutation is complete
120
+ setSavingOptions([]);
52
121
  }
53
- },
54
- [hasHydrated, setHasHydrated]
55
- );
122
+ } catch (e) {
123
+ // Error is logged by apollo link - no need to double log.
124
+ }
125
+ }, [cartId, setGiftOptionsOnCart]);
126
+
127
+ // TODO: Update mutation when backend provides the option to remove Gift Message
128
+ const handleRemoveGiftMessage = useCallback(async () => {
129
+ try {
130
+ const formApi = formApiRef.current;
131
+
132
+ if (formApi) {
133
+ // Indicates Gift Message is currently saving
134
+ setSavingOptions([...savingOptions, 'giftMessage']);
56
135
 
57
- const handleValueChange = useCallback(
58
- values => {
59
- // Write values to the cache after every user input.
60
- // Apollo should batch these writes if the user inputs quickly.
61
- cache.writeQuery({
62
- query: getGiftOptionsQuery,
63
- variables: {
64
- cart_id: cartId
65
- },
66
- data: {
67
- cart: {
68
- __typename: 'Cart',
69
- id: cartId,
70
- include_gift_receipt: !!values.includeGiftReceipt,
71
- include_printed_card: !!values.includePrintedCard,
72
- local_gift_message: values.cardMessage || ''
136
+ // Reset form data and form errors
137
+ formApi.setValues({
138
+ cardTo: '',
139
+ cardFrom: '',
140
+ cardMessage: ''
141
+ });
142
+ formApi.setError('cardTo');
143
+ formApi.setError('cardFrom');
144
+ formApi.setError('cardMessage');
145
+ setShowGiftMessageResult(false);
146
+
147
+ await setGiftOptionsOnCart({
148
+ variables: {
149
+ cartId,
150
+ giftMessage: {
151
+ to: '',
152
+ from: '',
153
+ message: ''
154
+ },
155
+ // Mutation requires both options to be provided
156
+ giftReceiptIncluded: formApi.getValue(
157
+ 'includeGiftReceipt'
158
+ ),
159
+ printedCardIncluded: formApi.getValue(
160
+ 'includePrintedCard'
161
+ )
73
162
  }
163
+ });
164
+
165
+ // Reset saving options when mutation is complete
166
+ setSavingOptions([]);
167
+ }
168
+ } catch (e) {
169
+ // Error is logged by apollo link - no need to double log.
170
+ }
171
+ }, [cartId, savingOptions, setGiftOptionsOnCart]);
172
+
173
+ const handleUpdateGiftMessage = useCallback(async () => {
174
+ try {
175
+ const formApi = formApiRef.current;
176
+
177
+ if (formApi) {
178
+ formApi.validate();
179
+
180
+ if (!formApi.getState().invalid) {
181
+ // Indicates Gift Message is currently saving
182
+ setSavingOptions([...savingOptions, 'giftMessage']);
183
+
184
+ await setGiftOptionsOnCart({
185
+ variables: {
186
+ cartId,
187
+ giftMessage: {
188
+ to: formApi.getValue('cardTo'),
189
+ from: formApi.getValue('cardFrom'),
190
+ message: formApi.getValue('cardMessage')
191
+ },
192
+ // Mutation requires both options to be provided
193
+ giftReceiptIncluded: formApi.getValue(
194
+ 'includeGiftReceipt'
195
+ ),
196
+ printedCardIncluded: formApi.getValue(
197
+ 'includePrintedCard'
198
+ )
199
+ }
200
+ });
201
+
202
+ setShowGiftMessageResult(true);
203
+ // Reset saving options when mutation is complete
204
+ setSavingOptions([]);
74
205
  }
75
- });
206
+ }
207
+ } catch (e) {
208
+ // Error is logged by apollo link - no need to double log.
209
+ }
210
+ }, [cartId, savingOptions, setGiftOptionsOnCart]);
211
+
212
+ const handleToggleGiftMessageIsChecked = useCallback(
213
+ async isChecked => {
214
+ if (!isChecked) {
215
+ // Remove Gift Message and reset form
216
+ await handleRemoveGiftMessage();
217
+ }
218
+
219
+ setGiftMessageIsChecked(prevState => !prevState);
76
220
  },
77
- [cartId, cache, getGiftOptionsQuery]
221
+ [handleRemoveGiftMessage]
78
222
  );
79
223
 
80
- useQuery(getGiftOptionsQuery, {
81
- onCompleted: handleCompleted,
82
- skip: !cartId,
83
- variables: { cartId }
84
- });
224
+ const handleToggleGiftMessageResult = useCallback(() => {
225
+ setShowGiftMessageResult(prevState => !prevState);
226
+ }, []);
85
227
 
86
- const cardMessageProps = {
87
- field: 'cardMessage',
88
- initialValue: '',
89
- keepState: true
90
- };
228
+ // Batch writes if the user inputs quickly.
229
+ const debouncedOnChange = useMemo(
230
+ () =>
231
+ debounce(() => {
232
+ handleOnChange();
233
+ }, 500),
234
+ [handleOnChange]
235
+ );
236
+
237
+ // Indicates which options are currently saving
238
+ const updateSavingOptionsOnChange = useCallback(
239
+ element => {
240
+ const elementName = element.target.name;
241
+
242
+ if (!savingOptions.includes(elementName)) {
243
+ setSavingOptions([...savingOptions, elementName]);
244
+ }
245
+
246
+ debouncedOnChange();
247
+ },
248
+ [debouncedOnChange, savingOptions]
249
+ );
91
250
 
92
251
  const giftReceiptProps = {
93
252
  field: 'includeGiftReceipt',
94
- initialValue: false
253
+ onChange: updateSavingOptionsOnChange
95
254
  };
96
255
 
97
256
  const printedCardProps = {
98
257
  field: 'includePrintedCard',
99
- initialValue: false
258
+ onChange: updateSavingOptionsOnChange
259
+ };
260
+
261
+ const giftMessageCheckboxProps = {
262
+ disabled: savingOptions.includes('giftMessage'),
263
+ field: 'includeGiftMessage',
264
+ onValueChange: handleToggleGiftMessageIsChecked
265
+ };
266
+
267
+ const cardToProps = {
268
+ disabled:
269
+ !giftMessageIsChecked || savingOptions.includes('giftMessage'),
270
+ field: 'cardTo',
271
+ validate: isRequired
272
+ };
273
+
274
+ const cardFromProps = {
275
+ disabled:
276
+ !giftMessageIsChecked || savingOptions.includes('giftMessage'),
277
+ field: 'cardFrom',
278
+ validate: isRequired
279
+ };
280
+
281
+ const cardMessageProps = {
282
+ disabled:
283
+ !giftMessageIsChecked || savingOptions.includes('giftMessage'),
284
+ field: 'cardMessage',
285
+ validate: isRequired
100
286
  };
101
287
 
102
288
  const optionsFormProps = {
103
- getApi: api => {
104
- formApiRef.current = api;
105
- },
106
- onValueChange: handleValueChange
289
+ initialValues,
290
+ getApi: setFormApi
107
291
  };
108
292
 
109
- const shouldPromptForMessage = useCallback(
110
- ({ values }) => values.includePrintedCard,
111
- []
293
+ const editGiftMessageButtonProps = {
294
+ disabled:
295
+ !giftMessageIsChecked || savingOptions.includes('giftMessage'),
296
+ priority: 'normal',
297
+ type: 'button',
298
+ onClick: handleToggleGiftMessageResult
299
+ };
300
+
301
+ const cancelGiftMessageButtonProps = {
302
+ disabled:
303
+ !giftMessageIsChecked || savingOptions.includes('giftMessage'),
304
+ priority: 'low',
305
+ type: 'button',
306
+ onClick: handleToggleGiftMessageResult
307
+ };
308
+
309
+ const saveGiftMessageButtonProps = {
310
+ disabled:
311
+ !giftMessageIsChecked || savingOptions.includes('giftMessage'),
312
+ priority: 'normal',
313
+ type: 'button',
314
+ onClick: handleUpdateGiftMessage
315
+ };
316
+
317
+ // Create a memoized error map and toggle individual errors when they change
318
+ const errors = useMemo(
319
+ () =>
320
+ new Map([
321
+ ['setGiftOptionsOnCartMutation', setGiftOptionsOnCartError],
322
+ ['getGiftOptionsQuery', getGiftOptionsError]
323
+ ]),
324
+ [getGiftOptionsError, setGiftOptionsOnCartError]
112
325
  );
113
326
 
114
327
  return {
115
- cardMessageProps,
328
+ loading,
329
+ errors,
330
+ savingOptions,
116
331
  giftReceiptProps,
117
- optionsFormProps,
118
332
  printedCardProps,
119
- shouldPromptForMessage
333
+ printedCardPrice,
334
+ giftMessageCheckboxProps,
335
+ giftMessageResult,
336
+ hasGiftMessage,
337
+ showGiftMessageResult,
338
+ cardToProps,
339
+ cardFromProps,
340
+ cardMessageProps,
341
+ editGiftMessageButtonProps,
342
+ cancelGiftMessageButtonProps,
343
+ saveGiftMessageButtonProps,
344
+ optionsFormProps
120
345
  };
121
346
  };
122
347
 
123
- export default useGiftOptions;
124
-
125
348
  /** JSDocs type definitions */
126
349
 
127
350
  /**
128
- * GraphQL mutations for Gift Options
129
- *
130
- * @typedef {Object} GiftOptionsMutations
131
- *
132
- * @property {GraphQLAST} setGiftOptionsMutation Mutation to use for setting the gift options for the cart
133
- *
134
- * @see [giftOptions.gql.js]{@link https://github.com/magento/pwa-studio/blob/develop/packages/venia-ui/lib/components/CartPage/PriceAdjustments/GiftOptions/giftOptions.gql.js}
135
- * for the query Venia uses.
136
- */
137
-
138
- /**
139
- * GraphQL query for Gift Options
140
- *
141
- * @typedef {Object} GiftOptionsQueries
351
+ * Props data to use when rendering a gift options component.
142
352
  *
143
- * @property {GraphQLAST} getGiftOptionsQuery Query to get gift options data
353
+ * @typedef {Object} GiftOptionsTalonProps
144
354
  *
145
- * @see [giftOptions.gql.js]{@link https://github.com/magento/pwa-studio/blob/develop/packages/venia-ui/lib/components/CartPage/PriceAdjustments/GiftOptions/giftOptions.gql.js}
146
- * for the query Venia uses.
355
+ * @property {Boolean} loading Query loading indicator.
356
+ * @property {Object} errors Errors for GraphQl query and mutation.
357
+ * @property {Array} savingOptions Array containing fields that are busy.
358
+ * @property {Object} giftReceiptProps Props for the `includeGiftReceipt` checkbox element.
359
+ * @property {Object} printedCardProps Props for the `includePrintedCard` checkbox element.
360
+ * @property {Object} printedCardPrice Printed Card Price object.
361
+ * @property {Object} giftMessageCheckboxProps Props for the `includeGiftMessage` checkbox element.
362
+ * @property {Object} giftMessageResult Object containing Gift Message data.
363
+ * @property {Boolean} hasGiftMessage Checks if Gift Message data has all fields filled.
364
+ * @property {Boolean} showGiftMessageResult Show or hide Gift Message result.
365
+ * @property {Object} cardToProps Props for the `cardTo` text input element.
366
+ * @property {Object} cardFromProps Props for the `cardFrom` text input element.
367
+ * @property {Object} cardMessageProps Props for the `cardMessage` textarea element.
368
+ * @property {Object} editGiftMessageButtonProps Props for the Edit Gift Message button.
369
+ * @property {Object} cancelGiftMessageButtonProps Props for the Cancel Gift Message button.
370
+ * @property {Object} saveGiftMessageButtonProps Props for the Update Gift Message button.
371
+ * @property {Object} optionsFormProps Props for the form element.
147
372
  */
148
373
 
149
374
  /**
150
- * Props data to use when rendering a gift options component.
151
- *
152
- * @typedef {Object} GiftOptionsTalonProps
375
+ * This is a type used by the {@link useGiftOptions} talon.
153
376
  *
154
- * @property {object} cardMessageProps Props for the `cardMessage` textarea element.
155
- * @property {object} giftReceiptProps Props for the `includeGiftReceipt` checkbox element.
156
- * @property {object} optionsFormProps Props for the form element.
157
- * @property {object} printedCardProps Props for the `includePrintedCard` checkbox element.
158
- * @property {function} shouldPromptForMessage Determines whether to show the `cardMessage` textarea element.
377
+ * @typedef {Object} GiftOptionsOperations
159
378
  *
379
+ * @property {GraphQLAST} setGiftOptionsOnCartMutation sets the gift options on cart.
380
+ * @property {GraphQLAST} getGiftOptionsQuery fetch the gift options.
160
381
  */
@@ -0,0 +1,17 @@
1
+ import { gql } from '@apollo/client';
2
+
3
+ const GET_GIFT_OPTIONS_CONFIG = gql`
4
+ query GetStoreConfigForGiftOptions {
5
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
6
+ storeConfig {
7
+ store_code
8
+ allow_order
9
+ allow_gift_receipt
10
+ allow_printed_card
11
+ }
12
+ }
13
+ `;
14
+
15
+ export default {
16
+ getGiftOptionsConfigQuery: GET_GIFT_OPTIONS_CONFIG
17
+ };
@@ -0,0 +1,61 @@
1
+ import { useQuery } from '@apollo/client';
2
+
3
+ import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
4
+
5
+ import DEFAULT_OPERATIONS from './giftOptionsSection.gql.js';
6
+
7
+ /**
8
+ * This talon fetches the gift options section data.
9
+ * @function
10
+ *
11
+ * @param {Object} props
12
+ * @param {GiftOptionsSectionOperations} props.operations
13
+ *
14
+ * @return {GiftOptionsSectionProps}
15
+ */
16
+ export const useGiftOptionsSection = (props = {}) => {
17
+ const { getGiftOptionsConfigQuery } = mergeOperations(
18
+ DEFAULT_OPERATIONS,
19
+ props.operations
20
+ );
21
+
22
+ const { data, loading } = useQuery(getGiftOptionsConfigQuery, {
23
+ fetchPolicy: 'cache-and-network',
24
+ nextFetchPolicy: 'cache-first'
25
+ });
26
+
27
+ const storeConfig = data?.storeConfig || {};
28
+ const {
29
+ allow_order = '0',
30
+ allow_gift_receipt = '0',
31
+ allow_printed_card = '0'
32
+ } = storeConfig;
33
+ const isVisible =
34
+ allow_order === '1' ||
35
+ allow_gift_receipt === '1' ||
36
+ allow_printed_card === '1';
37
+
38
+ return {
39
+ giftOptionsConfigData: storeConfig,
40
+ isLoading: loading,
41
+ isVisible
42
+ };
43
+ };
44
+
45
+ /**
46
+ * Object type returned by the {@link useGiftOptionsSection} talon.
47
+ *
48
+ * @typedef {Object} GiftOptionsSectionProps
49
+ *
50
+ * @property {Object} giftOptionsConfigData Data returned from the `getGiftOptionsConfigQuery`.
51
+ * @property {boolean} isLoading True if the data is still loading.
52
+ * @property {boolean} isVisible True if the gift options section should be displayed.
53
+ */
54
+
55
+ /**
56
+ * This is a type used by the {@link useGiftOptionsSection} talon.
57
+ *
58
+ * @typedef {Object} GiftOptionsSectionOperations
59
+ *
60
+ * @property {GraphQLAST} getGiftOptionsConfigQuery fetch the store configuration.
61
+ */
@@ -5,7 +5,7 @@ export const priceSummaryResponse = {
5
5
  value: 20
6
6
  },
7
7
  grand_total: {
8
- value: 30
8
+ value: 40
9
9
  },
10
10
  discounts: [
11
11
  {
@@ -20,7 +20,12 @@ export const priceSummaryResponse = {
20
20
  value: 7
21
21
  }
22
22
  }
23
- ]
23
+ ],
24
+ gift_options: {
25
+ printed_card: {
26
+ value: 10
27
+ }
28
+ }
24
29
  },
25
30
  applied_gift_cards: [
26
31
  {
@@ -2,6 +2,7 @@ import { gql } from '@apollo/client';
2
2
 
3
3
  import { DiscountSummaryFragment } from './discountSummary.gql';
4
4
  import { GiftCardSummaryFragment } from './queries/giftCardSummary';
5
+ import { GiftOptionsSummaryFragment } from './queries/giftOptionsSummary';
5
6
  import { ShippingSummaryFragment } from './shippingSummary.gql';
6
7
  import { TaxSummaryFragment } from './taxSummary.gql';
7
8
 
@@ -31,11 +32,17 @@ export const PriceSummaryFragment = gql`
31
32
  currency
32
33
  value
33
34
  }
35
+ subtotal_including_tax {
36
+ currency
37
+ value
38
+ }
34
39
  }
35
40
  ...GiftCardSummaryFragment
41
+ ...GiftOptionsSummaryFragment
36
42
  }
37
43
  ${DiscountSummaryFragment}
38
44
  ${GiftCardSummaryFragment}
45
+ ${GiftOptionsSummaryFragment}
39
46
  ${GrandTotalFragment}
40
47
  ${ShippingSummaryFragment}
41
48
  ${TaxSummaryFragment}
@@ -0,0 +1,8 @@
1
+ import { gql } from '@apollo/client';
2
+
3
+ export const GiftOptionsSummaryFragment = gql`
4
+ fragment GiftOptionsSummaryFragment on Cart {
5
+ id
6
+ __typename
7
+ }
8
+ `;
@@ -0,0 +1,15 @@
1
+ import { gql } from '@apollo/client';
2
+
3
+ export const GiftOptionsSummaryFragment = gql`
4
+ fragment GiftOptionsSummaryFragment on Cart {
5
+ id
6
+ prices {
7
+ gift_options {
8
+ printed_card {
9
+ value
10
+ currency
11
+ }
12
+ }
13
+ }
14
+ }
15
+ `;