@sonic-equipment/ui 122.0.0 → 124.0.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.
- package/dist/buttons/add-to-cart-button/add-to-cart-button.js +2 -2
- package/dist/buttons/add-to-cart-button/connected-add-to-cart-button.js +8 -0
- package/dist/buttons/button/button.d.ts +2 -1
- package/dist/buttons/button/button.js +8 -3
- package/dist/buttons/button/button.module.css.js +1 -1
- package/dist/checkout/adyen-payment.d.ts +21 -0
- package/dist/checkout/adyen-payment.js +165 -0
- package/dist/checkout/parse-amount.d.ts +2 -0
- package/dist/checkout/parse-amount.js +10 -0
- package/dist/checkout/payment-details.d.ts +5 -0
- package/dist/checkout/payment-details.js +21 -0
- package/dist/checkout/payment.d.ts +6 -0
- package/dist/checkout/payment.js +69 -0
- package/dist/collapsables/accordion/accordion-item.d.ts +2 -1
- package/dist/collapsables/accordion/accordion-item.js +6 -2
- package/dist/collapsables/accordion/accordion.module.css.js +1 -1
- package/dist/config.js +1 -1
- package/dist/exports.d.ts +22 -0
- package/dist/forms/field-error/field-error.d.ts +14 -1
- package/dist/forms/field-error/field-error.js +15 -1
- package/dist/forms/input/input.d.ts +1 -0
- package/dist/forms/input/input.js +2 -2
- package/dist/forms/number-field/number-field.d.ts +4 -1
- package/dist/forms/number-field/number-field.js +3 -3
- package/dist/forms/select/select.d.ts +4 -1
- package/dist/forms/select/select.js +6 -3
- package/dist/forms/text-field/text-field.d.ts +4 -1
- package/dist/forms/text-field/text-field.js +3 -3
- package/dist/forms/textarea/textarea.d.ts +1 -0
- package/dist/forms/textarea/textarea.js +10 -10
- package/dist/icons/stroke/stroke-information-icon.js +7 -0
- package/dist/index.js +24 -2
- package/dist/intl/translation-id.d.ts +1 -1
- package/dist/loading/progress-circle.d.ts +3 -1
- package/dist/loading/progress-circle.js +3 -3
- package/dist/loading/progress-circle.module.css.js +1 -1
- package/dist/pages/cart-page/cart-page.js +1 -0
- package/dist/pages/product-details-page/product-details.js +7 -0
- package/dist/shared/api/bff/model/bff.model.d.ts +1 -0
- package/dist/shared/api/storefront/hooks/authentication/use-create-guest-account.d.ts +4 -0
- package/dist/shared/api/storefront/hooks/authentication/use-create-guest-account.js +21 -0
- package/dist/shared/api/storefront/hooks/authentication/use-patch-session.d.ts +4 -0
- package/dist/shared/api/storefront/hooks/authentication/use-patch-session.js +15 -0
- package/dist/shared/api/storefront/hooks/authentication/use-sign-in.js +14 -9
- package/dist/shared/api/storefront/hooks/authentication/use-sign-out.js +1 -2
- package/dist/shared/api/storefront/hooks/cart/use-add-product-to-current-cart.js +1 -7
- package/dist/shared/api/storefront/hooks/cart/use-delete-cart-line-by-id.js +1 -4
- package/dist/shared/api/storefront/hooks/cart/use-fetch-current-cart.js +3 -1
- package/dist/shared/api/storefront/hooks/cart/use-patch-cart.d.ts +3 -4
- package/dist/shared/api/storefront/hooks/cart/use-patch-cart.js +6 -8
- package/dist/shared/api/storefront/hooks/cart/use-place-order.d.ts +3 -3
- package/dist/shared/api/storefront/hooks/cart/use-place-order.js +7 -8
- package/dist/shared/api/storefront/hooks/cart/use-update-cart-line-by-id.js +1 -13
- package/dist/shared/api/storefront/hooks/customer/use-fetch-bill-to-addresses.d.ts +1 -0
- package/dist/shared/api/storefront/hooks/customer/use-fetch-bill-to-addresses.js +14 -0
- package/dist/shared/api/storefront/hooks/customer/use-fetch-ship-to-addresses.d.ts +3 -0
- package/dist/shared/api/storefront/hooks/customer/use-fetch-ship-to-addresses.js +15 -0
- package/dist/shared/api/storefront/hooks/customer/use-update-bill-to-address.d.ts +6 -0
- package/dist/shared/api/storefront/hooks/customer/use-update-bill-to-address.js +17 -0
- package/dist/shared/api/storefront/hooks/payment/use-create-adyen-session.d.ts +3 -0
- package/dist/shared/api/storefront/hooks/payment/use-create-adyen-session.js +10 -0
- package/dist/shared/api/storefront/hooks/payment/use-fetch-adyen-config.d.ts +1 -0
- package/dist/shared/api/storefront/hooks/payment/use-fetch-adyen-config.js +14 -0
- package/dist/shared/api/storefront/hooks/payment/use-invalidate-adyen.d.ts +1 -0
- package/dist/shared/api/storefront/hooks/payment/use-invalidate-adyen.js +9 -0
- package/dist/shared/api/storefront/model/shop.model.d.ts +17 -0
- package/dist/shared/api/storefront/services/cart-service.d.ts +15 -2
- package/dist/shared/api/storefront/services/cart-service.js +68 -3
- package/dist/shared/api/storefront/services/customer-service.d.ts +8 -0
- package/dist/shared/api/storefront/services/customer-service.js +31 -0
- package/dist/shared/api/storefront/services/payment-service.d.ts +8 -0
- package/dist/shared/api/storefront/services/payment-service.js +29 -0
- package/dist/shared/ga/data-layer.d.ts +2 -0
- package/dist/shared/ga/data-layer.js +13 -0
- package/dist/shared/ga/google-analytics-provider.d.ts +8 -0
- package/dist/shared/ga/google-analytics-provider.js +15 -0
- package/dist/shared/ga/types.d.ts +34 -0
- package/dist/shared/ga/types.js +8 -0
- package/dist/shared/ga/use-data-layer.d.ts +50 -0
- package/dist/shared/ga/use-data-layer.js +89 -0
- package/dist/shared/model/address.d.ts +2 -0
- package/dist/shared/model/address.js +7 -0
- package/dist/shared/model/countries.d.ts +225 -0
- package/dist/shared/model/countries.js +260 -0
- package/dist/shared/model/currency.d.ts +1 -0
- package/dist/shared/model/currency.js +1 -0
- package/dist/shared/utils/price.d.ts +38 -0
- package/dist/shared/utils/price.js +39 -1
- package/dist/shared/utils/random.d.ts +10 -0
- package/dist/shared/utils/random.js +16 -0
- package/dist/styles.css +306 -107
- package/dist/tooltip/tooltip.d.ts +9 -0
- package/dist/tooltip/tooltip.js +21 -0
- package/dist/tooltip/tooltip.module.css.js +3 -0
- package/package.json +2 -2
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { FormEventHandler, KeyboardEvent } from 'react';
|
|
2
|
+
import { ValidateFunction } from '../field-error/field-error';
|
|
2
3
|
export type NumberFieldSize = 'md' | 'lg';
|
|
3
4
|
interface NumberFieldProps {
|
|
4
5
|
autoFocus?: boolean;
|
|
5
6
|
autoGrow?: boolean;
|
|
7
|
+
'data-test-selector'?: string;
|
|
6
8
|
defaultValue?: number;
|
|
7
9
|
formatOptions?: Intl.NumberFormatOptions;
|
|
8
10
|
isDisabled?: boolean;
|
|
@@ -20,6 +22,7 @@ interface NumberFieldProps {
|
|
|
20
22
|
placeholder?: string;
|
|
21
23
|
showLabel?: boolean;
|
|
22
24
|
size?: NumberFieldSize;
|
|
25
|
+
validate?: ValidateFunction<number>;
|
|
23
26
|
value?: number;
|
|
24
27
|
withButtons?: boolean;
|
|
25
28
|
}
|
|
@@ -27,5 +30,5 @@ interface NumberFieldProps {
|
|
|
27
30
|
* This component is used to create a number field.
|
|
28
31
|
* This field can also grow when a user types in text.
|
|
29
32
|
*/
|
|
30
|
-
export declare function NumberField({ autoFocus, autoGrow, defaultValue, formatOptions, isDisabled, isInvalid, isReadOnly, isRequired, label, maxLength, maxValue, minValue, name, onChange, onInput, onKeyUp, placeholder, showLabel, size, value, withButtons, }: NumberFieldProps): import("react/jsx-runtime").JSX.Element;
|
|
33
|
+
export declare function NumberField({ autoFocus, autoGrow, 'data-test-selector': dataTestSelector, defaultValue, formatOptions, isDisabled, isInvalid, isReadOnly, isRequired, label, maxLength, maxValue, minValue, name, onChange, onInput, onKeyUp, placeholder, showLabel, size, validate, value, withButtons, }: NumberFieldProps): import("react/jsx-runtime").JSX.Element;
|
|
31
34
|
export {};
|
|
@@ -15,12 +15,12 @@ import styles from './number-field.module.css.js';
|
|
|
15
15
|
* This component is used to create a number field.
|
|
16
16
|
* This field can also grow when a user types in text.
|
|
17
17
|
*/
|
|
18
|
-
function NumberField({ autoFocus, autoGrow, defaultValue, formatOptions = { style: 'decimal', useGrouping: false }, isDisabled, isInvalid, isReadOnly, isRequired, label, maxLength, maxValue, minValue, name, onChange, onInput, onKeyUp, placeholder, showLabel = false, size = 'lg', value, withButtons, }) {
|
|
18
|
+
function NumberField({ autoFocus, autoGrow, 'data-test-selector': dataTestSelector, defaultValue, formatOptions = { style: 'decimal', useGrouping: false }, isDisabled, isInvalid, isReadOnly, isRequired, label, maxLength, maxValue, minValue, name, onChange, onInput, onKeyUp, placeholder, showLabel = false, size = 'lg', validate, value, withButtons, }) {
|
|
19
19
|
const inputRef = useRef(null);
|
|
20
|
-
return (jsxs(NumberField$1, { "aria-label": label, autoFocus: autoFocus, className: clsx(styles.field, styles[size]), defaultValue: defaultValue, formatOptions: formatOptions, isDisabled: isDisabled, isInvalid: isInvalid, isReadOnly: isReadOnly, isRequired: isRequired, maxValue: maxValue, minValue: minValue, name: name, onChange: onChange, onInput: onInput, value: value, children: [showLabel && jsx(Label, { isRequired: isRequired, children: label }), jsxs("div", { className: styles['button-input-container'], children: [withButtons && (jsx(Button, { "data-test-selector": "decrement", isDisabled: isDisabled,
|
|
20
|
+
return (jsxs(NumberField$1, { "aria-label": label, autoFocus: autoFocus, className: clsx(styles.field, styles[size]), "data-test-selector": dataTestSelector, defaultValue: defaultValue, formatOptions: formatOptions, isDisabled: isDisabled, isInvalid: isInvalid, isReadOnly: isReadOnly, isRequired: isRequired, maxValue: maxValue, minValue: minValue, name: name, onChange: onChange, onInput: onInput, validate: validate, value: value, children: [showLabel && jsx(Label, { isRequired: isRequired, children: label }), jsxs("div", { className: styles['button-input-container'], children: [withButtons && (jsx(Button, { "data-test-selector": "decrement", isDisabled: isDisabled,
|
|
21
21
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
22
22
|
// @ts-expect-error
|
|
23
|
-
onClick: e => e.preventDefault(), onPressStart: e => e.target.focus(), slot: "decrement", children: (value || 0) <= 1 ? jsx(StrokeTrashIcon, {}) : jsx(StrokeCollapseIcon, {}) })), jsx(Input, { ref: inputRef, autoGrow: autoGrow, maxLength: maxLength, onFocus: e => (e.target.selectionStart = e.target.value.length || 0), onKeyUp: e => onKeyUp?.(e), placeholder: placeholder, size: size }), withButtons && (jsx(Button, { "data-test-selector": "increment", isDisabled: isDisabled,
|
|
23
|
+
onClick: e => e.preventDefault(), onPressStart: e => e.target.focus(), slot: "decrement", children: (value || 0) <= 1 ? jsx(StrokeTrashIcon, {}) : jsx(StrokeCollapseIcon, {}) })), jsx(Input, { ref: inputRef, autoGrow: autoGrow, "data-test-selector": "value", label: label, maxLength: maxLength, onFocus: e => (e.target.selectionStart = e.target.value.length || 0), onKeyUp: e => onKeyUp?.(e), placeholder: placeholder, size: size }), withButtons && (jsx(Button, { "data-test-selector": "increment", isDisabled: isDisabled,
|
|
24
24
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
25
25
|
// @ts-expect-error
|
|
26
26
|
onClick: e => e.preventDefault(), onPressStart: e => e.target.focus(), slot: "increment", children: jsx(StrokeExpandIcon, {}) }))] }), jsx(FieldError, {})] }));
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export interface SelectProps<T> {
|
|
2
2
|
'data-test-selector'?: string;
|
|
3
|
+
defaultSelectedOption?: keyof T;
|
|
3
4
|
isDisabled?: boolean;
|
|
5
|
+
isRequired?: boolean;
|
|
4
6
|
label: string;
|
|
7
|
+
name?: string;
|
|
5
8
|
onChange: (value: keyof T) => void;
|
|
6
9
|
options: T;
|
|
7
10
|
placeholder?: string;
|
|
@@ -11,4 +14,4 @@ export interface SelectProps<T> {
|
|
|
11
14
|
size?: 'sm' | 'md';
|
|
12
15
|
variant?: 'outline' | 'solid';
|
|
13
16
|
}
|
|
14
|
-
export declare function Select<T extends
|
|
17
|
+
export declare function Select<T extends Record<string, string>>({ 'data-test-selector': dataTestSelector, defaultSelectedOption, isDisabled, isRequired, label, name, onChange, options, placeholder, selectedOption, showLabel, showPlaceholder, size, variant, }: SelectProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -5,10 +5,11 @@ import { Select as Select$1, Button, SelectValue, Popover, ListBox, Section, Hea
|
|
|
5
5
|
import clsx from 'clsx';
|
|
6
6
|
import { GlyphsChevronsSlimDownIcon } from '../../icons/glyph/glyphs-chevrons-slim-down-icon.js';
|
|
7
7
|
import { StrokeCheckmarkIcon } from '../../icons/stroke/stroke-checkmark-icon.js';
|
|
8
|
+
import { FieldError } from '../field-error/field-error.js';
|
|
8
9
|
import { Label } from '../label/label.js';
|
|
9
10
|
import styles from './select.module.css.js';
|
|
10
11
|
|
|
11
|
-
function Select({ 'data-test-selector': dataTestSelector, isDisabled = false, label, onChange, options, placeholder, selectedOption, showLabel = true, showPlaceholder = true, size = 'md', variant = 'outline', }) {
|
|
12
|
+
function Select({ 'data-test-selector': dataTestSelector, defaultSelectedOption, isDisabled = false, isRequired = false, label, name, onChange, options, placeholder, selectedOption, showLabel = true, showPlaceholder = true, size = 'md', variant = 'outline', }) {
|
|
12
13
|
const selectRef = useRef(null);
|
|
13
14
|
useEffect(() => {
|
|
14
15
|
const updateWidth = () => {
|
|
@@ -23,9 +24,11 @@ function Select({ 'data-test-selector': dataTestSelector, isDisabled = false, la
|
|
|
23
24
|
window.addEventListener('resize', updateWidth);
|
|
24
25
|
return () => window?.removeEventListener('resize', updateWidth);
|
|
25
26
|
}, []);
|
|
26
|
-
return (jsxs(Select$1, { ref: selectRef, "aria-label": label, className: clsx(styles.select, styles[size], styles[variant]), "data-test-selector": dataTestSelector,
|
|
27
|
+
return (jsxs(Select$1, { ref: selectRef, "aria-label": label, className: clsx(styles.select, styles[size], styles[variant]), "data-test-selector": dataTestSelector, defaultSelectedKey: defaultSelectedOption === undefined
|
|
28
|
+
? undefined
|
|
29
|
+
: String(defaultSelectedOption), isDisabled: isDisabled, isRequired: isRequired, name: name, onSelectionChange: selected => onChange(selected), placeholder: placeholder || label, selectedKey: selectedOption === undefined ? undefined : String(selectedOption), children: [showLabel && jsx(Label, { isRequired: isRequired, children: label }), jsxs(Button, { className: styles.button, children: [jsx(SelectValue, { "data-test-selector": "value" }), jsx(GlyphsChevronsSlimDownIcon, { "aria-hidden": "true", className: styles.chevron })] }), jsx(FieldError, {}), jsx(Popover, { ref: ref =>
|
|
27
30
|
// Workaround for react/react-aria #1513
|
|
28
|
-
ref?.addEventListener('touchend', e => e.preventDefault()), className: clsx(styles.popover, styles[variant]), placement: "bottom left",
|
|
31
|
+
ref?.addEventListener('touchend', e => e.preventDefault()), className: clsx(styles.popover, styles[variant]), placement: "bottom left", children: jsx(ListBox, { className: styles.listbox, "data-test-selector": dataTestSelector ? `${dataTestSelector}_options` : undefined, children: jsxs(Section, { children: [showPlaceholder && (jsx(Header, { className: styles.header, children: placeholder || label })), Object.entries(options).map(([key, value]) => (jsxs(ListBoxItem, { "aria-label": value, className: styles.item, id: key, textValue: value, children: [selectedOption === key && (jsx("span", { slot: "description", children: jsx(StrokeCheckmarkIcon, { className: styles.check }) })), jsx("span", { slot: "label", children: value })] }, key)))] }) }) })] }));
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
export { Select };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { FormEventHandler, KeyboardEvent } from 'react';
|
|
2
|
+
import { ValidateFunction } from '../field-error/field-error';
|
|
2
3
|
interface TextFieldProps {
|
|
3
4
|
autoFocus?: boolean;
|
|
4
5
|
autoGrow?: boolean;
|
|
@@ -10,6 +11,7 @@ interface TextFieldProps {
|
|
|
10
11
|
isRequired?: boolean;
|
|
11
12
|
label: string;
|
|
12
13
|
maxLength?: number;
|
|
14
|
+
minLength?: number;
|
|
13
15
|
name?: string;
|
|
14
16
|
onChange?: (value: string) => void;
|
|
15
17
|
onInput?: FormEventHandler<HTMLInputElement>;
|
|
@@ -18,6 +20,7 @@ interface TextFieldProps {
|
|
|
18
20
|
rows?: number;
|
|
19
21
|
showLabel?: boolean;
|
|
20
22
|
size?: 'md' | 'lg';
|
|
23
|
+
validate?: ValidateFunction<string>;
|
|
21
24
|
value?: string;
|
|
22
25
|
}
|
|
23
26
|
/**
|
|
@@ -25,5 +28,5 @@ interface TextFieldProps {
|
|
|
25
28
|
* It can be used as a single line input or as a textarea.
|
|
26
29
|
* This field can also grow when a user types in text.
|
|
27
30
|
*/
|
|
28
|
-
export declare function TextField({ autoFocus, autoGrow, defaultValue, isDisabled, isInvalid, isMultiline, isReadOnly, isRequired, label, maxLength, name, onChange, onInput, onKeyUp, placeholder, rows, showLabel, size, value, }: TextFieldProps): import("react/jsx-runtime").JSX.Element;
|
|
31
|
+
export declare function TextField({ autoFocus, autoGrow, defaultValue, isDisabled, isInvalid, isMultiline, isReadOnly, isRequired, label, maxLength, minLength, name, onChange, onInput, onKeyUp, placeholder, rows, showLabel, size, validate, value, }: TextFieldProps): import("react/jsx-runtime").JSX.Element;
|
|
29
32
|
export {};
|
|
@@ -13,10 +13,10 @@ import styles from './text-field.module.css.js';
|
|
|
13
13
|
* It can be used as a single line input or as a textarea.
|
|
14
14
|
* This field can also grow when a user types in text.
|
|
15
15
|
*/
|
|
16
|
-
function TextField({ autoFocus, autoGrow, defaultValue, isDisabled, isInvalid, isMultiline, isReadOnly, isRequired, label, maxLength, name, onChange, onInput, onKeyUp, placeholder, rows, showLabel = false, size = 'lg', value, }) {
|
|
17
|
-
return (jsxs(TextField$1, { "aria-label": label, autoFocus: autoFocus, className: clsx(styles.field, styles[size]), defaultValue: defaultValue, isDisabled: isDisabled, isInvalid: isInvalid, isReadOnly: isReadOnly, isRequired: isRequired, maxLength: maxLength, name: name, onChange: value => {
|
|
16
|
+
function TextField({ autoFocus, autoGrow, defaultValue, isDisabled, isInvalid, isMultiline, isReadOnly, isRequired, label, maxLength, minLength, name, onChange, onInput, onKeyUp, placeholder, rows, showLabel = false, size = 'lg', validate, value, }) {
|
|
17
|
+
return (jsxs(TextField$1, { "aria-label": label, autoFocus: autoFocus, className: clsx(styles.field, styles[size]), defaultValue: defaultValue, isDisabled: isDisabled, isInvalid: isInvalid, isReadOnly: isReadOnly, isRequired: isRequired, maxLength: maxLength, minLength: minLength, name: name, onChange: value => {
|
|
18
18
|
onChange?.(value);
|
|
19
|
-
}, onInput: onInput, onKeyUp: e => onKeyUp?.(e), value: value, children: [showLabel && jsx(Label, { isRequired: isRequired, children: label }), isMultiline ? (jsx(TextArea, { autoGrow: autoGrow, placeholder: placeholder, rows: rows, size: size })) : (jsx(Input, { autoGrow: autoGrow, placeholder: placeholder, size: size })), jsx(FieldError, {})] }));
|
|
19
|
+
}, onInput: onInput, onKeyUp: e => onKeyUp?.(e), validate: validate, value: value, children: [showLabel && jsx(Label, { isRequired: isRequired, children: label }), isMultiline ? (jsx(TextArea, { autoGrow: autoGrow, label: label, placeholder: placeholder, rows: rows, size: size })) : (jsx(Input, { autoGrow: autoGrow, label: label, placeholder: placeholder, size: size })), jsx(FieldError, {})] }));
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export { TextField };
|
|
@@ -2,6 +2,7 @@ import { ComponentProps, FC } from 'react';
|
|
|
2
2
|
import { TextArea as AriaTextArea } from 'react-aria-components';
|
|
3
3
|
export interface TextAreaProps extends Omit<ComponentProps<typeof AriaTextArea>, 'size'> {
|
|
4
4
|
autoGrow?: boolean;
|
|
5
|
+
label: string;
|
|
5
6
|
size?: 'md' | 'lg';
|
|
6
7
|
}
|
|
7
8
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
3
3
|
import { forwardRef, useRef, useCallback, useEffect } from 'react';
|
|
4
4
|
import { useContextProps, TextAreaContext, TextArea as TextArea$1 } from 'react-aria-components';
|
|
5
5
|
import styles from './textarea.module.css.js';
|
|
@@ -10,7 +10,7 @@ import styles from './textarea.module.css.js';
|
|
|
10
10
|
* The initial height is calculated based on the style of the textarea.
|
|
11
11
|
* The height is updated everytime the user types.
|
|
12
12
|
*/
|
|
13
|
-
const TextArea = forwardRef(({ autoGrow, size, ...textAreaProps }, _ref) => {
|
|
13
|
+
const TextArea = forwardRef(({ autoGrow, label, size, ...textAreaProps }, _ref) => {
|
|
14
14
|
const textAreaRef = useRef(null);
|
|
15
15
|
const [props, ref] = useContextProps(textAreaProps, textAreaRef, TextAreaContext);
|
|
16
16
|
const initialHeight = useRef(null);
|
|
@@ -40,14 +40,14 @@ const TextArea = forwardRef(({ autoGrow, size, ...textAreaProps }, _ref) => {
|
|
|
40
40
|
}
|
|
41
41
|
updateHeight();
|
|
42
42
|
}, [ref, autoGrow, updateHeight, size]);
|
|
43
|
-
return (jsx("div", { className: styles['input-container'], children: jsx(TextArea$1, { ...textAreaProps, ref: node => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
return (jsx(Fragment, { children: jsx("div", { className: styles['input-container'], children: jsx(TextArea$1, { "aria-label": label, ...textAreaProps, ref: node => {
|
|
44
|
+
ref.current =
|
|
45
|
+
node;
|
|
46
|
+
return (textAreaRef.current = node);
|
|
47
|
+
}, onInput: e => {
|
|
48
|
+
updateHeight();
|
|
49
|
+
props.onInput?.(e);
|
|
50
|
+
} }) }) }));
|
|
51
51
|
});
|
|
52
52
|
TextArea.displayName = 'TextArea';
|
|
53
53
|
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
function StrokeInformationIcon(props) {
|
|
4
|
+
return (jsx("svg", { fill: "currentColor", height: "24", viewBox: "0 0 24 24", width: "24", xmlns: "http://www.w3.org/2000/svg", ...props, children: jsx("path", { d: "M11.9997748,2 C17.5138784,2 22,6.48597148 22,11.9997748 C22,17.5138784 17.5138784,22 11.9997748,22 C6.48597148,22 2,17.5138784 2,11.9997748 C2,6.48597148 6.48597148,2 11.9997748,2 Z M11.9997748,3.33025009 C7.21934336,3.33025009 3.33025009,7.21934336 3.33025009,11.9997748 C3.33025009,16.7803563 7.21934336,20.6697499 11.9997748,20.6697499 C16.7805065,20.6697499 20.6697499,16.7803563 20.6697499,11.9997748 C20.6697499,7.21934336 16.7805065,3.33025009 11.9997748,3.33025009 Z M12,10.0686973 C12.7347233,10.0686973 13.3300999,10.6642241 13.3300999,11.3989474 L13.3300999,16.8046369 C13.3300999,17.53921 12.7347233,18.1347368 12,18.1347368 C11.2652767,18.1347368 10.6699001,17.53921 10.6699001,16.8046369 L10.6699001,11.3989474 C10.6699001,10.6642241 11.2652767,10.0686973 12,10.0686973 Z M12.00003,5.9387205 C12.7337022,5.9387205 13.3305804,6.53559872 13.3305804,7.26927091 C13.3305804,8.0029431 12.7337022,8.59982131 12.00003,8.59982131 C11.2663578,8.59982131 10.6694796,8.0029431 10.6694796,7.26927091 C10.6694796,6.53559872 11.2663578,5.9387205 12.00003,5.9387205 Z", fillRule: "evenodd" }) }));
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export { StrokeInformationIcon };
|
package/dist/index.js
CHANGED
|
@@ -60,6 +60,10 @@ export { ProductUsp } from './carousel/usp-carousel/product-usp-carousel-slide.j
|
|
|
60
60
|
export { USPCarousel } from './carousel/usp-carousel/usp-carousel.js';
|
|
61
61
|
export { CartTotals } from './cart-totals/cart-totals.js';
|
|
62
62
|
export { CartTotalsSummary } from './cart-totals/cart-totals-summary.js';
|
|
63
|
+
export { AdyenPayment } from './checkout/adyen-payment.js';
|
|
64
|
+
export { parseAmount } from './checkout/parse-amount.js';
|
|
65
|
+
export { Payment } from './checkout/payment.js';
|
|
66
|
+
export { PaymentDetails } from './checkout/payment-details.js';
|
|
63
67
|
export { Accordion } from './collapsables/accordion/accordion.js';
|
|
64
68
|
export { AccordionItem } from './collapsables/accordion/accordion-item.js';
|
|
65
69
|
export { ShowAll } from './collapsables/show-all/show-all.js';
|
|
@@ -165,9 +169,11 @@ export { useFetchAnnouncements } from './shared/api/bff/hooks/use-fetch-announce
|
|
|
165
169
|
export { useFetchProductDetailsPageData } from './shared/api/bff/hooks/use-fetch-product-details-page-data.js';
|
|
166
170
|
export { useFetchProductListingPageData } from './shared/api/bff/hooks/use-fetch-product-listing-page-data.js';
|
|
167
171
|
export { fetchAnnouncements, fetchProductDetailsPageData, fetchProductListingPageData } from './shared/api/bff/services/bff-service.js';
|
|
172
|
+
export { useCreateGuestAccount } from './shared/api/storefront/hooks/authentication/use-create-guest-account.js';
|
|
168
173
|
export { useFetchSession } from './shared/api/storefront/hooks/authentication/use-fetch-session.js';
|
|
169
174
|
export { useInvalidateSession } from './shared/api/storefront/hooks/authentication/use-invalidate-session.js';
|
|
170
175
|
export { useIsAuthenticated } from './shared/api/storefront/hooks/authentication/use-is-authenticated.js';
|
|
176
|
+
export { usePatchSession } from './shared/api/storefront/hooks/authentication/use-patch-session.js';
|
|
171
177
|
export { useSignIn } from './shared/api/storefront/hooks/authentication/use-sign-in.js';
|
|
172
178
|
export { useSignOut } from './shared/api/storefront/hooks/authentication/use-sign-out.js';
|
|
173
179
|
export { useAddProductToCurrentCart } from './shared/api/storefront/hooks/cart/use-add-product-to-current-cart.js';
|
|
@@ -186,6 +192,12 @@ export { usePatchCart } from './shared/api/storefront/hooks/cart/use-patch-cart.
|
|
|
186
192
|
export { usePlaceOrder } from './shared/api/storefront/hooks/cart/use-place-order.js';
|
|
187
193
|
export { useSaveCartForLater } from './shared/api/storefront/hooks/cart/use-save-cart-for-later.js';
|
|
188
194
|
export { useUpdateCartLineById } from './shared/api/storefront/hooks/cart/use-update-cart-line-by-id.js';
|
|
195
|
+
export { useFetchBillToAddresses } from './shared/api/storefront/hooks/customer/use-fetch-bill-to-addresses.js';
|
|
196
|
+
export { useFetchShipToAddresses } from './shared/api/storefront/hooks/customer/use-fetch-ship-to-addresses.js';
|
|
197
|
+
export { useUpdateBillToAddress } from './shared/api/storefront/hooks/customer/use-update-bill-to-address.js';
|
|
198
|
+
export { useCreateAdyenSession } from './shared/api/storefront/hooks/payment/use-create-adyen-session.js';
|
|
199
|
+
export { useFetchAdyenConfig } from './shared/api/storefront/hooks/payment/use-fetch-adyen-config.js';
|
|
200
|
+
export { useInvalidateAdyen } from './shared/api/storefront/hooks/payment/use-invalidate-adyen.js';
|
|
189
201
|
export { useFetchTranslations } from './shared/api/storefront/hooks/translation/use-fetch-translations.js';
|
|
190
202
|
export { useFetchCountries } from './shared/api/storefront/hooks/website/use-fetch-countries.js';
|
|
191
203
|
export { useFetchCountriesLanguages } from './shared/api/storefront/hooks/website/use-fetch-countries-languages.js';
|
|
@@ -199,12 +211,18 @@ export { useDeleteWishListItemFromWishList } from './shared/api/storefront/hooks
|
|
|
199
211
|
export { useFetchAllWishListsItems } from './shared/api/storefront/hooks/wishlist/use-fetch-all-wishlists-items.js';
|
|
200
212
|
export { useFetchWishLists } from './shared/api/storefront/hooks/wishlist/use-fetch-wishlists.js';
|
|
201
213
|
export { createGuestAccount, createSession, fetchSession, patchSession, signIn, signOut } from './shared/api/storefront/services/authentication-service.js';
|
|
202
|
-
export { addProductToCurrentCart, deleteCartLineById, deleteCurrentCart, fetchCurrentCart, fetchCurrentCartLines, fetchCurrentCartProductAtp, fetchCurrentCartPromotions, fetchCurrentCheckoutAtp, patchCart, placeOrder, saveCartForLater, updateCartLineById } from './shared/api/storefront/services/cart-service.js';
|
|
214
|
+
export { addProductToCurrentCart, convertToMinorUnits, deleteCartLineById, deleteCurrentCart, fetchCurrentCart, fetchCurrentCartLines, fetchCurrentCartProductAtp, fetchCurrentCartPromotions, fetchCurrentCheckoutAtp, getAdyenPaymentDetails, patchCart, placeOrder, postAdyenPayment, saveCartForLater, updateCartLineById } from './shared/api/storefront/services/cart-service.js';
|
|
215
|
+
export { fetchBillToAddresses, fetchShipToAddresses, updateBillToAddress } from './shared/api/storefront/services/customer-service.js';
|
|
216
|
+
export { createAdyenSession, fetchAdyenConfig } from './shared/api/storefront/services/payment-service.js';
|
|
203
217
|
export { fetchTranslations } from './shared/api/storefront/services/translation-service.js';
|
|
204
218
|
export { fetchCountries, fetchCountriesLanguages, fetchCountriesWithLanguages, fetchSettings, updateLocale } from './shared/api/storefront/services/website-service.js';
|
|
205
219
|
export { WishListNameAlreadyExistsError, addWishListItemToWishList, createWishList, deleteWishList, deleteWishListItemFromWishList, getWishList, getWishListItemsByWishListId, getWishLists } from './shared/api/storefront/services/wishlist-service.js';
|
|
206
220
|
export { useFeatureFlags } from './shared/feature-flags/use-feature-flags.js';
|
|
207
221
|
export { BadRequestError, ForbiddenRequestError, InternalServerErrorRequestError, NotFoundRequestError, RequestError, TimeoutRequestError, UnauthorizedRequestError, UnprocessableContentRequestError, isRequestError, request } from './shared/fetch/request.js';
|
|
222
|
+
export { dataLayer } from './shared/ga/data-layer.js';
|
|
223
|
+
export { GoogleAnalyticsProvider, useGoogleAnalyticsProvider } from './shared/ga/google-analytics-provider.js';
|
|
224
|
+
export { isGAEvent } from './shared/ga/types.js';
|
|
225
|
+
export { useDataLayer } from './shared/ga/use-data-layer.js';
|
|
208
226
|
export { useBreakpoint } from './shared/hooks/use-breakpoint.js';
|
|
209
227
|
export { useCookie } from './shared/hooks/use-cookie.js';
|
|
210
228
|
export { useDebouncedCallback } from './shared/hooks/use-debounced-callback.js';
|
|
@@ -217,8 +235,10 @@ export { useScrollLock } from './shared/hooks/use-scroll-lock.js';
|
|
|
217
235
|
export { scrollToTop, useScrollTo } from './shared/hooks/use-scroll-to.js';
|
|
218
236
|
export { useSessionStorage } from './shared/hooks/use-session-storage.js';
|
|
219
237
|
export { useWatchCssProperty } from './shared/hooks/use-watch-css-property.js';
|
|
238
|
+
export { validateEmail, validatePhone } from './shared/model/address.js';
|
|
220
239
|
export { announcementSubTypes, announcementTypes, isAnnouncementSubtype, isAnnouncementType } from './shared/model/announcement.js';
|
|
221
240
|
export { transformAlgoliaCategoryData } from './shared/model/category.js';
|
|
241
|
+
export { countries } from './shared/model/countries.js';
|
|
222
242
|
export { currencySymbolToISO } from './shared/model/currency.js';
|
|
223
243
|
export { isProductHit, transformAlgoliaProductHitToProductHit, transformAlgoliaPromoHitToPromoHit } from './shared/model/hit.js';
|
|
224
244
|
export { isResponsiveImage } from './shared/model/image.js';
|
|
@@ -237,7 +257,8 @@ export { convertDateUnitToPluralOrSingle, getDateUnitObject } from './shared/uti
|
|
|
237
257
|
export { environment, environments } from './shared/utils/environment.js';
|
|
238
258
|
export { EventEmitter } from './shared/utils/event-emitter.js';
|
|
239
259
|
export { clone, deepMerge, isPlainObject, default as main, merge } from './shared/utils/merge.js';
|
|
240
|
-
export { formatPrice } from './shared/utils/price.js';
|
|
260
|
+
export { currencies, formatPrice, getCurrencyByCountryCode } from './shared/utils/price.js';
|
|
261
|
+
export { random, randomInt } from './shared/utils/random.js';
|
|
241
262
|
export { TIME } from './shared/utils/time.js';
|
|
242
263
|
export { createUUID } from './shared/utils/uuid.js';
|
|
243
264
|
export { wait } from './shared/utils/wait.js';
|
|
@@ -249,6 +270,7 @@ export { Toast } from './toast/toast.js';
|
|
|
249
270
|
export { ToastProvider } from './toast/toast-provider.js';
|
|
250
271
|
export { useToast } from './toast/use-toast.js';
|
|
251
272
|
export { getTokenKeyValue, getTokenValue } from './tokens/tokens.js';
|
|
273
|
+
export { Tooltip } from './tooltip/tooltip.js';
|
|
252
274
|
export { Heading, SIZES, TAGS } from './typography/heading/heading.js';
|
|
253
275
|
|
|
254
276
|
/* eslint-disable simple-import-sort/exports */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export type TranslationId = "'{0}' in all products" | "Try 'Search' and try to find the product you're looking for" | "Unfortnately, We found no articles for your search '{0}'" | ' to your account to manage your lists.' | 'Add to list' | 'Amount: {0}' | 'An unexpected error occured' | 'Are you looking for information about our service? Please visit our customer support page' | 'Are you sure you want to remove all items from your cart?' | 'Are you sure you want to remove this item from your cart?' | 'Cancel' | 'Chosen filters' | 'Clear filters' | 'Clear' | 'Click the button below to continue shopping.' | '
|
|
1
|
+
export type TranslationId = "'{0}' in all products" | "Try 'Search' and try to find the product you're looking for" | "Unfortnately, We found no articles for your search '{0}'" | ' to your account to manage your lists.' | 'Add to list' | 'Amount: {0}' | 'An unexpected error occured' | 'Are you looking for information about our service? Please visit our customer support page' | 'Are you sure you want to remove all items from your cart?' | 'Are you sure you want to remove this item from your cart?' | 'Cancel' | 'Cart' | 'Chosen filters' | 'Clear filters' | 'Clear' | 'Click the button below to continue shopping.' | 'Continue shopping' | 'Continue' | 'Cost overview' | 'Country' | 'Create new list' | 'Delivery expected in {0} {1}' | 'Double check your spelling' | 'Downloads' | 'Easily add your favorite products' | 'Excl. VAT' | 'Explore by categories' | 'Exploring our products by category' | 'Features' | 'Fulfillment method' | 'Hide filters' | 'Incl. VAT' | 'Includes' | 'Language' | 'List name already exists' | 'New list name' | 'Order number' | 'PO Number' | 'Please Sign In' | 'Popular searches' | 'Print' | 'Product Features' | 'Product' | 'Products' | 'Quick access' | 'Recent searches' | 'Recently viewed' | 'Remove all' | 'Save order' | 'Save' | 'Saved cart for later.' | 'Searching again using more general terms' | 'See all results' | 'Select a list' | 'Share your favorite list with others' | 'Shipping and handling' | 'Shop more efficiently and quicker with a favorites list' | 'Show all' | 'Show filters' | 'Show less' | 'Show' | 'Sorry, there are no products found' | 'Sorry, we could not find matches for' | 'Sort by' | 'Specifications' | 'Submit' | 'Subtotal' | 'Suggestions' | 'The product has been added to your cart.' | 'The product has been removed from your cart.' | 'The product has been updated in your cart.' | 'There are no products in your shopping cart.' | 'Total amount is' | 'Total' | 'Try another search' | 'Unable to add the product to your cart.' | 'Unable to empty your cart.' | 'Unable to remove the product from your cart.' | 'Unable to save cart for later.' | 'Unable to update the product in your cart.' | 'Use fewer keywords' | 'VAT Number' | 'VAT' | 'Welcome to Sonic Equipment. Please choose your country and language below.' | 'What are you searching for?' | 'You could try checking the spelling of your search query' | 'You could try exploring our products by category' | 'You could try' | 'You must ' | 'Your cart has been emptied.' | 'Your favorites are available on multiple devices' | 'Your shopping cart is still empty' | 'article' | 'articles' | 'create account' | 'facet.categories' | 'facet.height' | 'facet.weight' | 'of' | 'pc' | 'sign in' | 'sort.newest' | 'sort.price_asc' | 'sort.price_desc' | 'sort.relevance' | 'tag.limited' | 'tag.new' | 'validation.badInput' | 'validation.customError' | 'validation.invalid' | 'validation.patternMismatch' | 'validation.rangeOverflow' | 'validation.rangeUnderflow' | 'validation.stepMismatch' | 'validation.tooLong' | 'validation.tooShort' | 'validation.typeMismatch' | 'validation.valid' | 'validation.valueMissing';
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export interface ProgressCircleProps {
|
|
2
2
|
className?: string;
|
|
3
|
+
size?: 'sm' | 'lg';
|
|
4
|
+
variant?: 'white' | 'gray';
|
|
3
5
|
}
|
|
4
|
-
export declare function ProgressCircle({ className }: ProgressCircleProps): import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
export declare function ProgressCircle({ className, size, variant, }: ProgressCircleProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import clsx from 'clsx';
|
|
3
3
|
import styles from './progress-circle.module.css.js';
|
|
4
4
|
|
|
5
|
-
function ProgressCircle({ className }) {
|
|
6
|
-
return (
|
|
5
|
+
function ProgressCircle({ className, size = 'lg', variant = 'white', }) {
|
|
6
|
+
return (jsx("span", { className: clsx(styles['progress-circle'], styles[variant], styles[size], className) }));
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export { ProgressCircle };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var styles = {"progress-circle":"progress-circle-module-4nweP","spin":"progress-circle-module-kCf7K"};
|
|
1
|
+
var styles = {"progress-circle":"progress-circle-module-4nweP","spin":"progress-circle-module-kCf7K","white":"progress-circle-module-SHNFy","gray":"progress-circle-module-TRZWO","sm":"progress-circle-module--Gspu","md":"progress-circle-module-4tRZd"};
|
|
2
2
|
|
|
3
3
|
export { styles as default };
|
|
@@ -85,6 +85,7 @@ function CartContent({ cartLines }) {
|
|
|
85
85
|
saveCartForLater.mutate({ cart: currentCart });
|
|
86
86
|
}, variant: "outline", children: jsx(FormattedMessage, { id: "Save order" }) })),
|
|
87
87
|
}, mobileSummary: jsx(CartTotalsSummary, { totalAmount: currentCart.orderGrandTotalDisplay }), overview: jsx(CartTotals, { shippingCost: currentCart.shippingAndHandlingDisplay, subtotal: currentCart.orderSubTotalDisplay, tax: currentCart.totalTaxDisplay, total: currentCart.orderGrandTotalDisplay, vatPercentage: cartLines[0]?.pricing?.vatRate || 0 }), children: jsx(OrderLineList, { onRemoveAll: () => deleteCurrentCart.mutate(), children: cartLines.map(cartLine => (jsx(ConnectedOrderLineCard, { deliveryDate: cartLine.atp?.date, href: cartLine.productUri, image: {
|
|
88
|
+
fit: 'contain',
|
|
88
89
|
image: {
|
|
89
90
|
'1': cartLine.smallImagePath,
|
|
90
91
|
'2': cartLine.smallImagePath,
|
|
@@ -4,6 +4,7 @@ import { ConnectedProductCard } from '../../cards/product-card/connected-product
|
|
|
4
4
|
import { CardCarousel } from '../../carousel/card-carousel/card-carousel.js';
|
|
5
5
|
import { ProductUSPCarousel } from '../../carousel/usp-carousel/product-usp-carousel.js';
|
|
6
6
|
import { FormattedMessage } from '../../intl/formatted-message.js';
|
|
7
|
+
import { useDataLayer } from '../../shared/ga/use-data-layer.js';
|
|
7
8
|
import { Heading } from '../../typography/heading/heading.js';
|
|
8
9
|
import { ProductDetailsPageLayout } from '../layouts/product-details-page-layout/product-details-page-layout.js';
|
|
9
10
|
import { Page } from '../page/page.js';
|
|
@@ -13,6 +14,12 @@ import { ProductDetailsRecentlyViewed } from './components/product-details-recen
|
|
|
13
14
|
|
|
14
15
|
function ProductDetails({ data, priceComponent, recentlyViewedComponent, }) {
|
|
15
16
|
const { breadCrumb, included, product, recentlyViewed, usps } = data;
|
|
17
|
+
useDataLayer({
|
|
18
|
+
event: {
|
|
19
|
+
event: 'view_item',
|
|
20
|
+
},
|
|
21
|
+
product,
|
|
22
|
+
});
|
|
16
23
|
return (jsx(Page, { breadCrumb: breadCrumb, children: jsx(ProductDetailsPageLayout, { imageGallery: jsx(ProductDetailImages, { images: product.images }), included: included !== undefined &&
|
|
17
24
|
included.length > 0 && (jsxs(Fragment, { children: [jsx(Heading, { size: "s", tag: "h2", children: jsx(FormattedMessage, { id: "Includes" }) }), jsx(CardCarousel, { allowExpandToGrid: true, hasOverflow: true, cards: included.map(product => (jsx(ConnectedProductCard, { href: product.href, id: product.productId, image: {
|
|
18
25
|
fit: 'contain',
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useQueryClient, useMutation } from '@tanstack/react-query';
|
|
2
|
+
import { createGuestAccount, createSession } from '../../services/authentication-service.js';
|
|
3
|
+
|
|
4
|
+
function useCreateGuestAccount() {
|
|
5
|
+
const queryClient = useQueryClient();
|
|
6
|
+
return useMutation({
|
|
7
|
+
mutationFn: async ({ defaultWarehouseId }) => {
|
|
8
|
+
const body = await createGuestAccount({ defaultWarehouseId });
|
|
9
|
+
await createSession({
|
|
10
|
+
accessToken: body.accessToken,
|
|
11
|
+
password: body.password,
|
|
12
|
+
userName: body.userName,
|
|
13
|
+
});
|
|
14
|
+
queryClient.resetQueries();
|
|
15
|
+
queryClient.clear();
|
|
16
|
+
return body;
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { useCreateGuestAccount };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useQueryClient, useMutation } from '@tanstack/react-query';
|
|
2
|
+
import { patchSession } from '../../services/authentication-service.js';
|
|
3
|
+
|
|
4
|
+
function usePatchSession() {
|
|
5
|
+
const queryClient = useQueryClient();
|
|
6
|
+
return useMutation({
|
|
7
|
+
mutationFn: async ({ session }) => {
|
|
8
|
+
const updatedSession = await patchSession({ session });
|
|
9
|
+
queryClient.setQueriesData({ queryKey: ['session'] }, updatedSession);
|
|
10
|
+
return updatedSession;
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { usePatchSession };
|
|
@@ -5,15 +5,20 @@ function useSignIn() {
|
|
|
5
5
|
const queryClient = useQueryClient();
|
|
6
6
|
return useMutation({
|
|
7
7
|
mutationFn: async ({ password, userName }) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
try {
|
|
9
|
+
const body = await signIn({ password, userName });
|
|
10
|
+
await createSession({
|
|
11
|
+
accessToken: body.access_token,
|
|
12
|
+
password,
|
|
13
|
+
userName,
|
|
14
|
+
});
|
|
15
|
+
queryClient.resetQueries();
|
|
16
|
+
return body;
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
queryClient.resetQueries();
|
|
20
|
+
throw error;
|
|
21
|
+
}
|
|
17
22
|
},
|
|
18
23
|
});
|
|
19
24
|
}
|
|
@@ -3,7 +3,6 @@ import { addProductToCurrentCart } from '../../services/cart-service.js';
|
|
|
3
3
|
|
|
4
4
|
function useAddProductToCurrentCart() {
|
|
5
5
|
const queryClient = useQueryClient();
|
|
6
|
-
const queryKey = ['carts', 'current', 'cartlines'];
|
|
7
6
|
return useMutation({
|
|
8
7
|
mutationFn: async ({ productId, qtyOrdered, unitOfMeasure, }) => {
|
|
9
8
|
const cartLine = await addProductToCurrentCart({
|
|
@@ -13,17 +12,12 @@ function useAddProductToCurrentCart() {
|
|
|
13
12
|
});
|
|
14
13
|
if (cartLine.productId !== productId)
|
|
15
14
|
throw new Error(`Product ${productId} has not been added to the current cart`);
|
|
16
|
-
const cartLines = queryClient.getQueryData(queryKey) ||
|
|
17
|
-
[];
|
|
18
|
-
queryClient.setQueryData(queryKey, cartLines.some(cl => cl.id === cartLine.id)
|
|
19
|
-
? cartLines.map(cl => (cl.id === cartLine.id ? cartLine : cl))
|
|
20
|
-
: [...cartLines, cartLine]);
|
|
21
15
|
// Invalidate the related current cart query cache
|
|
22
16
|
queryClient.invalidateQueries({ queryKey: ['carts', 'current'] });
|
|
23
17
|
return cartLine;
|
|
24
18
|
},
|
|
25
19
|
onError: () => {
|
|
26
|
-
queryClient.invalidateQueries({ queryKey });
|
|
20
|
+
queryClient.invalidateQueries({ queryKey: ['carts', 'current'] });
|
|
27
21
|
},
|
|
28
22
|
});
|
|
29
23
|
}
|
|
@@ -3,17 +3,14 @@ import { deleteCartLineById } from '../../services/cart-service.js';
|
|
|
3
3
|
|
|
4
4
|
function useDeleteCartLineById({ onError, onSuccess, } = {}) {
|
|
5
5
|
const queryClient = useQueryClient();
|
|
6
|
-
const queryKey = ['carts', 'current', 'cartlines'];
|
|
7
6
|
return useMutation({
|
|
8
7
|
mutationFn: async ({ cartLineId, }) => {
|
|
9
8
|
await deleteCartLineById({ cartLineId });
|
|
10
|
-
const cartLines = queryClient.getQueryData(queryKey);
|
|
11
|
-
queryClient.setQueryData(queryKey, cartLines?.filter(line => line.id !== cartLineId));
|
|
12
9
|
// Invalidate the related current cart query cache
|
|
13
10
|
queryClient.invalidateQueries({ queryKey: ['carts', 'current'] });
|
|
14
11
|
},
|
|
15
12
|
onError: () => {
|
|
16
|
-
queryClient.invalidateQueries({ queryKey });
|
|
13
|
+
queryClient.invalidateQueries({ queryKey: ['carts', 'current'] });
|
|
17
14
|
onError?.();
|
|
18
15
|
},
|
|
19
16
|
onSuccess,
|
|
@@ -6,7 +6,9 @@ function useFetchCurrentCart({ select, } = {}) {
|
|
|
6
6
|
return useQuery({
|
|
7
7
|
gcTime: 15 * TIME.MINUTE,
|
|
8
8
|
placeholderData: prev => prev,
|
|
9
|
-
queryFn:
|
|
9
|
+
queryFn: () => {
|
|
10
|
+
return fetchCurrentCart({ needFullCart: true });
|
|
11
|
+
},
|
|
10
12
|
queryKey: ['carts', 'current'],
|
|
11
13
|
retry: 3,
|
|
12
14
|
select: select || (cartModel => cartModel),
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}, unknown>;
|
|
1
|
+
export declare function usePatchCart(): ({ cart }: {
|
|
2
|
+
cart: any;
|
|
3
|
+
}) => Promise<import("../../model/shop.model").CartModel>;
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import { useQueryClient
|
|
1
|
+
import { useQueryClient } from '@tanstack/react-query';
|
|
2
2
|
import { patchCart } from '../../services/cart-service.js';
|
|
3
3
|
|
|
4
4
|
function usePatchCart() {
|
|
5
5
|
const queryClient = useQueryClient();
|
|
6
|
-
return
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
},
|
|
12
|
-
});
|
|
6
|
+
return async ({ cart }) => {
|
|
7
|
+
const updatedCart = await patchCart({ cart });
|
|
8
|
+
queryClient.setQueriesData({ queryKey: ['carts', updatedCart.id] }, { ...updatedCart, cartLines: cart.cartLines });
|
|
9
|
+
return updatedCart;
|
|
10
|
+
};
|
|
13
11
|
}
|
|
14
12
|
|
|
15
13
|
export { usePatchCart };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { CartModel } from '../../model/shop.model';
|
|
2
|
-
export declare const usePlaceOrder: () =>
|
|
3
|
-
cart:
|
|
4
|
-
}
|
|
2
|
+
export declare const usePlaceOrder: () => ({ cart }: {
|
|
3
|
+
cart: any;
|
|
4
|
+
}) => Promise<CartModel>;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import { useQueryClient
|
|
1
|
+
import { useQueryClient } from '@tanstack/react-query';
|
|
2
2
|
import { placeOrder } from '../../services/cart-service.js';
|
|
3
3
|
|
|
4
4
|
const usePlaceOrder = () => {
|
|
5
5
|
const queryClient = useQueryClient();
|
|
6
|
-
return
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
});
|
|
6
|
+
return async ({ cart }) => {
|
|
7
|
+
const updatedCart = await placeOrder({ cart });
|
|
8
|
+
queryClient.invalidateQueries({ queryKey: ['carts', cart.id] });
|
|
9
|
+
queryClient.setQueryData(['carts', updatedCart.id], updatedCart);
|
|
10
|
+
return updatedCart;
|
|
11
|
+
};
|
|
13
12
|
};
|
|
14
13
|
|
|
15
14
|
export { usePlaceOrder };
|