@magento/peregrine 12.2.0 → 12.3.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/clearCustomerDataFromCache.js +1 -0
- package/lib/Apollo/policies/index.js +9 -4
- package/lib/hooks/useGoogleReCaptcha/googleReCaptchaConfig.gql.js +16 -0
- package/lib/hooks/useGoogleReCaptcha/index.js +1 -0
- package/lib/hooks/useGoogleReCaptcha/useGoogleReCaptcha.js +210 -0
- package/lib/hooks/useMediaQuery.js +83 -0
- package/lib/hooks/useScript.js +68 -0
- package/lib/hooks/useSort.js +13 -2
- package/lib/talons/AccountInformationPage/useAccountInformationPage.js +23 -6
- package/lib/talons/CartPage/PriceAdjustments/GiftOptions/giftOptions.gql.js +36 -11
- package/lib/talons/CartPage/PriceAdjustments/GiftOptions/giftOptionsFragments.gql.js +19 -0
- package/lib/talons/CartPage/PriceAdjustments/GiftOptions/useGiftOptions.js +315 -94
- package/lib/talons/CartPage/PriceAdjustments/giftOptionsSection.gql.js +17 -0
- package/lib/talons/CartPage/PriceAdjustments/useGiftOptionsSection.js +61 -0
- package/lib/talons/CartPage/PriceSummary/__fixtures__/priceSummary.js +7 -2
- package/lib/talons/CartPage/PriceSummary/priceSummaryFragments.gql.js +7 -0
- package/lib/talons/CartPage/PriceSummary/queries/giftOptionsSummary.ce.js +8 -0
- package/lib/talons/CartPage/PriceSummary/queries/giftOptionsSummary.ee.js +15 -0
- package/lib/talons/CartPage/PriceSummary/useDiscountSummary.js +71 -0
- package/lib/talons/CartPage/PriceSummary/usePriceSummary.js +3 -1
- package/lib/talons/CartPage/ProductListing/EditModal/__fixtures__/configurableThumbnailSource.js +8 -0
- package/lib/talons/CartPage/ProductListing/EditModal/productForm.gql.js +11 -0
- package/lib/talons/CartPage/ProductListing/EditModal/useProductForm.js +15 -1
- package/lib/talons/CheckoutPage/OrderConfirmationPage/useCreateAccount.js +27 -5
- package/lib/talons/CheckoutPage/PaymentInformation/useCreditCard.js +36 -15
- package/lib/talons/CheckoutPage/useCheckoutPage.js +18 -3
- package/lib/talons/CmsDynamicBlock/client-schema.graphql +4 -0
- package/lib/talons/CmsDynamicBlock/cmsDynamicBlock.gql.js +113 -0
- package/lib/talons/CmsDynamicBlock/useCmsDynamicBlock.js +211 -0
- package/lib/talons/CreateAccount/useCreateAccount.js +29 -5
- package/lib/talons/ForgotPassword/useForgotPassword.js +26 -5
- package/lib/talons/Link/useLink.js +2 -1
- package/lib/talons/MiniCart/miniCartFragments.gql.js +4 -0
- package/lib/talons/MyAccount/useResetPassword.js +23 -5
- package/lib/talons/RootComponents/Category/useCategory.js +1 -1
- package/lib/talons/RootComponents/Product/useProduct.js +1 -6
- package/lib/talons/SearchPage/useSearchPage.js +1 -1
- package/lib/talons/SignIn/useSignIn.js +25 -6
- package/lib/talons/WishlistPage/createWishlist.gql.js +1 -0
- package/lib/talons/WishlistPage/useActionMenu.js +4 -4
- package/lib/talons/WishlistPage/useCreateWishlist.js +7 -4
- package/lib/talons/WishlistPage/useWishlistItem.js +3 -2
- package/lib/talons/WishlistPage/wishlistConfig.gql.ee.js +1 -0
- package/lib/talons/WishlistPage/wishlistItemFragments.gql.js +1 -0
- package/lib/util/configuredVariant.js +10 -6
- package/package.json +1 -1
- package/lib/talons/CartPage/PriceAdjustments/GiftOptions/client-schema.graphql +0 -7
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import { useCallback, useRef, useState } from 'react';
|
|
2
|
-
import {
|
|
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 {
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
119
|
+
// Reset saving options when mutation is complete
|
|
120
|
+
setSavingOptions([]);
|
|
52
121
|
}
|
|
53
|
-
}
|
|
54
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
[
|
|
221
|
+
[handleRemoveGiftMessage]
|
|
78
222
|
);
|
|
79
223
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
variables: { cartId }
|
|
84
|
-
});
|
|
224
|
+
const handleToggleGiftMessageResult = useCallback(() => {
|
|
225
|
+
setShowGiftMessageResult(prevState => !prevState);
|
|
226
|
+
}, []);
|
|
85
227
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
253
|
+
onChange: updateSavingOptionsOnChange
|
|
95
254
|
};
|
|
96
255
|
|
|
97
256
|
const printedCardProps = {
|
|
98
257
|
field: 'includePrintedCard',
|
|
99
|
-
|
|
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
|
-
|
|
104
|
-
|
|
105
|
-
},
|
|
106
|
-
onValueChange: handleValueChange
|
|
289
|
+
initialValues,
|
|
290
|
+
getApi: setFormApi
|
|
107
291
|
};
|
|
108
292
|
|
|
109
|
-
const
|
|
110
|
-
|
|
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
|
-
|
|
328
|
+
loading,
|
|
329
|
+
errors,
|
|
330
|
+
savingOptions,
|
|
116
331
|
giftReceiptProps,
|
|
117
|
-
optionsFormProps,
|
|
118
332
|
printedCardProps,
|
|
119
|
-
|
|
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
|
-
*
|
|
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
|
-
* @
|
|
353
|
+
* @typedef {Object} GiftOptionsTalonProps
|
|
144
354
|
*
|
|
145
|
-
* @
|
|
146
|
-
* for
|
|
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
|
-
*
|
|
151
|
-
*
|
|
152
|
-
* @typedef {Object} GiftOptionsTalonProps
|
|
375
|
+
* This is a type used by the {@link useGiftOptions} talon.
|
|
153
376
|
*
|
|
154
|
-
* @
|
|
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:
|
|
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}
|