@ikas/code-components-mcp 2.6.1 → 2.7.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/data/framework.json +68 -8
- package/data/migration.json +9 -3
- package/data/section-templates/add-to-cart/index.tsx +16 -2
- package/data/section-templates/add-to-cart/sub-components/QuantitySelector/index.tsx +11 -3
- package/data/section-templates/add-to-cart/utils/cartLimits.ts +23 -0
- package/data/section-templates/cart-section/sub-components/CartItem/index.tsx +57 -24
- package/data/section-templates/cart-section/sub-components/CartItem/styles.css +14 -0
- package/data/section-templates/cart-section/sub-components/QuantitySelector/index.tsx +11 -3
- package/data/section-templates/header-section/sub-components/CartItem/index.tsx +57 -24
- package/data/section-templates/header-section/sub-components/CartItem/styles.css +14 -0
- package/data/section-templates/header-section/sub-components/QuantitySelector/index.tsx +11 -3
- package/data/section-templates/image-handling/ikas-config-snippet.json +1 -0
- package/data/section-templates/navigation/sub-components/CartItem/index.tsx +57 -24
- package/data/section-templates/navigation/sub-components/CartItem/styles.css +14 -0
- package/data/section-templates/navigation/sub-components/QuantitySelector/index.tsx +11 -3
- package/data/section-templates/product-detail-section/children/ProductDetailAddToCart/index.tsx +16 -2
- package/data/section-templates/product-detail-section/children/ProductDetailBackInStock/components/BackInStockForm/index.tsx +92 -0
- package/data/section-templates/product-detail-section/children/ProductDetailBackInStock/ikas-config-snippet.json +159 -0
- package/data/section-templates/product-detail-section/children/ProductDetailBackInStock/index.tsx +141 -0
- package/data/section-templates/product-detail-section/children/ProductDetailBackInStock/styles.css +47 -0
- package/data/section-templates/product-detail-section/children/ProductDetailBackInStock/types.ts +25 -0
- package/data/section-templates/product-detail-section/ikas-config-snippet.json +1 -0
- package/data/section-templates/product-detail-section/sub-components/Modal/index.tsx +120 -0
- package/data/section-templates/product-detail-section/sub-components/Modal/styles.css +70 -0
- package/data/section-templates/product-detail-section/sub-components/QuantitySelector/index.tsx +11 -3
- package/data/section-templates/product-detail-section/utils/cartLimits.ts +23 -0
- package/data/storefront-api.json +82 -12
- package/data/storefront-types.json +2747 -22
- package/dist/index.js +582 -179
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -14,6 +14,8 @@ import {
|
|
|
14
14
|
getOrderLineItemFormattedOverridenPriceWithQuantity,
|
|
15
15
|
hasOrderLineItemDiscount,
|
|
16
16
|
getOrderLineItemOverridenPriceWithQuantity,
|
|
17
|
+
cartStore,
|
|
18
|
+
isOrderLineItemAutoCreated,
|
|
17
19
|
} from "@ikas/bp-storefront";
|
|
18
20
|
import { resolveAspectRatio, resolveObjectFit } from "../../utils/media";
|
|
19
21
|
import { cx } from "../../utils/cx";
|
|
@@ -25,6 +27,7 @@ interface CartItemProps {
|
|
|
25
27
|
variant?: "sidebar" | "page";
|
|
26
28
|
aspectRatio?: AspectRatio;
|
|
27
29
|
objectFit?: ObjectFit;
|
|
30
|
+
giftLabel?: string;
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
const CartItem = observer(function CartItem({
|
|
@@ -33,9 +36,25 @@ const CartItem = observer(function CartItem({
|
|
|
33
36
|
variant = "sidebar",
|
|
34
37
|
aspectRatio,
|
|
35
38
|
objectFit,
|
|
39
|
+
giftLabel = "Gift",
|
|
36
40
|
}: CartItemProps) {
|
|
37
41
|
const isPage = variant === "page";
|
|
38
42
|
|
|
43
|
+
// Lines a campaign added automatically (e.g. a "buy 1 get 1" gift) cannot be
|
|
44
|
+
// edited or removed on their own, so render them read-only with a badge.
|
|
45
|
+
const isAutoCreated =
|
|
46
|
+
!!cartStore.cart && isOrderLineItemAutoCreated(cartStore.cart, item);
|
|
47
|
+
const giftBadge = isAutoCreated ? (
|
|
48
|
+
<span className="kombos-cart-item__gift-badge text-xs-medium">
|
|
49
|
+
{giftLabel}
|
|
50
|
+
</span>
|
|
51
|
+
) : null;
|
|
52
|
+
const staticQuantity = (
|
|
53
|
+
<span className="kombos-cart-item__qty-static text-sm-medium">
|
|
54
|
+
×{item.quantity}
|
|
55
|
+
</span>
|
|
56
|
+
);
|
|
57
|
+
|
|
39
58
|
const mediaStyle: Record<string, string> = {
|
|
40
59
|
aspectRatio: resolveAspectRatio(aspectRatio),
|
|
41
60
|
objectFit: resolveObjectFit(objectFit),
|
|
@@ -103,6 +122,7 @@ const CartItem = observer(function CartItem({
|
|
|
103
122
|
<a href={href} className={nameClass}>
|
|
104
123
|
{item.variant?.name}
|
|
105
124
|
</a>
|
|
125
|
+
{giftBadge}
|
|
106
126
|
{variantValues.length > 0 && (
|
|
107
127
|
<p className="kombos-cart-item__variant-text text-sm-regular">
|
|
108
128
|
{variantValues
|
|
@@ -113,19 +133,22 @@ const CartItem = observer(function CartItem({
|
|
|
113
133
|
</p>
|
|
114
134
|
)}
|
|
115
135
|
</div>
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
136
|
+
{!isAutoCreated && (
|
|
137
|
+
<button
|
|
138
|
+
className="kombos-cart-item__remove"
|
|
139
|
+
onClick={() => onRemove(item)}
|
|
140
|
+
aria-label="Remove"
|
|
141
|
+
>
|
|
142
|
+
<TrashSVG />
|
|
143
|
+
</button>
|
|
144
|
+
)}
|
|
123
145
|
</div>
|
|
124
146
|
) : (
|
|
125
147
|
<>
|
|
126
148
|
<a href={href} className={nameClass}>
|
|
127
149
|
{item.variant?.name}
|
|
128
150
|
</a>
|
|
151
|
+
{giftBadge}
|
|
129
152
|
|
|
130
153
|
{variantValues.length > 0 && (
|
|
131
154
|
<div className="kombos-cart-item__variants">
|
|
@@ -151,11 +174,15 @@ const CartItem = observer(function CartItem({
|
|
|
151
174
|
|
|
152
175
|
{isPage ? (
|
|
153
176
|
<div className="kombos-cart-item__bottom">
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
177
|
+
{isAutoCreated ? (
|
|
178
|
+
staticQuantity
|
|
179
|
+
) : (
|
|
180
|
+
<QuantitySelector
|
|
181
|
+
size="sm"
|
|
182
|
+
value={item.quantity}
|
|
183
|
+
onChange={(qty) => changeItemQuantity(item, qty)}
|
|
184
|
+
/>
|
|
185
|
+
)}
|
|
159
186
|
<div className="kombos-cart-item__prices">
|
|
160
187
|
{hasDiscount && (
|
|
161
188
|
<span className="kombos-cart-item__original-price text-sm-regular-strike">
|
|
@@ -193,18 +220,24 @@ const CartItem = observer(function CartItem({
|
|
|
193
220
|
</div>
|
|
194
221
|
|
|
195
222
|
<div className="kombos-cart-item__actions">
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
223
|
+
{isAutoCreated ? (
|
|
224
|
+
staticQuantity
|
|
225
|
+
) : (
|
|
226
|
+
<>
|
|
227
|
+
<QuantitySelector
|
|
228
|
+
size="sm"
|
|
229
|
+
value={item.quantity}
|
|
230
|
+
onChange={(qty) => changeItemQuantity(item, qty)}
|
|
231
|
+
/>
|
|
232
|
+
<button
|
|
233
|
+
className="kombos-cart-item__remove"
|
|
234
|
+
onClick={() => onRemove(item)}
|
|
235
|
+
aria-label="Remove"
|
|
236
|
+
>
|
|
237
|
+
<TrashSVG />
|
|
238
|
+
</button>
|
|
239
|
+
</>
|
|
240
|
+
)}
|
|
208
241
|
</div>
|
|
209
242
|
</>
|
|
210
243
|
)}
|
|
@@ -168,3 +168,17 @@
|
|
|
168
168
|
flex-shrink: 0;
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
+
/* Auto-created (campaign gift) line: badge + read-only quantity */
|
|
172
|
+
.kombos-cart-item__gift-badge {
|
|
173
|
+
display: inline-flex;
|
|
174
|
+
align-self: flex-start;
|
|
175
|
+
padding: 0.125rem 0.5rem;
|
|
176
|
+
border-radius: 999px;
|
|
177
|
+
background: var(--kombos-gray-100);
|
|
178
|
+
color: var(--kombos-gray-500);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
.kombos-cart-item__qty-static {
|
|
182
|
+
color: var(--kombos-gray-500);
|
|
183
|
+
}
|
|
184
|
+
|
|
@@ -5,20 +5,27 @@ interface Props {
|
|
|
5
5
|
value: number;
|
|
6
6
|
onChange: (value: number) => void;
|
|
7
7
|
size?: "default" | "sm";
|
|
8
|
+
min?: number;
|
|
9
|
+
max?: number;
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
export default function QuantitySelector({
|
|
11
13
|
value,
|
|
12
14
|
onChange,
|
|
13
15
|
size = "default",
|
|
16
|
+
min = 1,
|
|
17
|
+
max,
|
|
14
18
|
}: Props) {
|
|
19
|
+
const canDecrease = value > min;
|
|
20
|
+
const canIncrease = max == null || value < max;
|
|
21
|
+
|
|
15
22
|
return (
|
|
16
23
|
<div className={cx("kombos-pd__qty", size === "sm" && "kombos-pd__qty--sm")}>
|
|
17
24
|
<button
|
|
18
25
|
type="button"
|
|
19
26
|
className="kombos-pd__qty-btn"
|
|
20
|
-
onClick={() => onChange(Math.max(
|
|
21
|
-
disabled={
|
|
27
|
+
onClick={() => onChange(Math.max(min, value - 1))}
|
|
28
|
+
disabled={!canDecrease}
|
|
22
29
|
aria-label="Decrease quantity"
|
|
23
30
|
>
|
|
24
31
|
<MinusSVG />
|
|
@@ -31,7 +38,8 @@ export default function QuantitySelector({
|
|
|
31
38
|
<button
|
|
32
39
|
type="button"
|
|
33
40
|
className="kombos-pd__qty-btn"
|
|
34
|
-
onClick={() => onChange(value + 1)}
|
|
41
|
+
onClick={() => onChange(max == null ? value + 1 : Math.min(max, value + 1))}
|
|
42
|
+
disabled={!canIncrease}
|
|
35
43
|
aria-label="Increase quantity"
|
|
36
44
|
>
|
|
37
45
|
<PlusSVG />
|
package/data/section-templates/product-detail-section/children/ProductDetailAddToCart/index.tsx
CHANGED
|
@@ -10,13 +10,14 @@ import {
|
|
|
10
10
|
IkasBundleSettings,
|
|
11
11
|
IkasStorefrontConfig,
|
|
12
12
|
} from "@ikas/bp-storefront";
|
|
13
|
-
import { useState } from "preact/hooks";
|
|
13
|
+
import { useEffect, useState } from "preact/hooks";
|
|
14
14
|
import { Props } from "./types";
|
|
15
15
|
import Button from "../../sub-components/Button";
|
|
16
16
|
import QuantitySelector from "../../sub-components/QuantitySelector";
|
|
17
17
|
import PayWithIkas from "./components/PayWithIkas";
|
|
18
18
|
import { isBundleOutOfStock } from "../../utils/bundle";
|
|
19
19
|
import { validateOptionSet } from "../../utils/optionSet";
|
|
20
|
+
import { getProductCartLimits } from "../../utils/cartLimits";
|
|
20
21
|
import { showToast } from "../../utils/toast";
|
|
21
22
|
|
|
22
23
|
export function ProductDetailAddToCart({
|
|
@@ -37,6 +38,12 @@ export function ProductDetailAddToCart({
|
|
|
37
38
|
const [quantity, setQuantity] = useState(1);
|
|
38
39
|
const [isAddingToCart, setIsAddingToCart] = useState(false);
|
|
39
40
|
|
|
41
|
+
// Seed the quantity to the product's minimum-per-cart when the product changes.
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (!product) return;
|
|
44
|
+
setQuantity(getProductCartLimits(product).min);
|
|
45
|
+
}, [product?.id]);
|
|
46
|
+
|
|
40
47
|
if (!product) return null;
|
|
41
48
|
|
|
42
49
|
const editLineID =
|
|
@@ -59,6 +66,8 @@ export function ProductDetailAddToCart({
|
|
|
59
66
|
|
|
60
67
|
const isDisabled = isOutOfStock || isAddingToCart;
|
|
61
68
|
|
|
69
|
+
const { min: minQuantity, max: maxQuantity } = getProductCartLimits(product);
|
|
70
|
+
|
|
62
71
|
const payWithIkasUrl = IkasStorefrontConfig.getPayWithIkasUrl();
|
|
63
72
|
const routing = IkasStorefrontConfig.getCurrentRouting();
|
|
64
73
|
const showPayWithIkas =
|
|
@@ -119,7 +128,12 @@ export function ProductDetailAddToCart({
|
|
|
119
128
|
>
|
|
120
129
|
<div className="kombos-pd-atc__actions">
|
|
121
130
|
{!hideQuantityInput && !isOutOfStock && (
|
|
122
|
-
<QuantitySelector
|
|
131
|
+
<QuantitySelector
|
|
132
|
+
value={quantity}
|
|
133
|
+
onChange={setQuantity}
|
|
134
|
+
min={minQuantity}
|
|
135
|
+
max={maxQuantity}
|
|
136
|
+
/>
|
|
123
137
|
)}
|
|
124
138
|
<Button
|
|
125
139
|
variant="primary"
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IkasProductVariant,
|
|
3
|
+
getProductVariantBackInStockForm,
|
|
4
|
+
initBackInStockNotificationForm,
|
|
5
|
+
setBackInStockNotificationFormEmail,
|
|
6
|
+
submitBackInStockNotificationForm,
|
|
7
|
+
} from "@ikas/bp-storefront";
|
|
8
|
+
import { observer } from "@ikas/component-utils";
|
|
9
|
+
import { useEffect } from "preact/hooks";
|
|
10
|
+
import Button from "../../../../sub-components/Button";
|
|
11
|
+
import Input from "../../../../sub-components/Input";
|
|
12
|
+
import FormItem from "../../../../sub-components/FormItem";
|
|
13
|
+
|
|
14
|
+
interface Props {
|
|
15
|
+
variant: IkasProductVariant;
|
|
16
|
+
description: string;
|
|
17
|
+
emailLabel: string;
|
|
18
|
+
submitButtonText: string;
|
|
19
|
+
submittingText: string;
|
|
20
|
+
errorMessage: string;
|
|
21
|
+
onSaved: () => void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// observer() because it reads the MobX-backed notification form and must
|
|
25
|
+
// re-render as the customer types and as the submit status flags change.
|
|
26
|
+
const BackInStockForm = observer(function BackInStockForm({
|
|
27
|
+
variant,
|
|
28
|
+
description,
|
|
29
|
+
emailLabel,
|
|
30
|
+
submitButtonText,
|
|
31
|
+
submittingText,
|
|
32
|
+
errorMessage,
|
|
33
|
+
onSaved,
|
|
34
|
+
}: Props) {
|
|
35
|
+
const form = getProductVariantBackInStockForm(variant);
|
|
36
|
+
|
|
37
|
+
// Initialize once per variant (resets fields + validation flags).
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
initBackInStockNotificationForm(form, variant);
|
|
40
|
+
}, [form, variant]);
|
|
41
|
+
|
|
42
|
+
const emailHasError = !!form.email?.hasError;
|
|
43
|
+
|
|
44
|
+
const handleSubmit = async (e: Event) => {
|
|
45
|
+
e.preventDefault();
|
|
46
|
+
if (await submitBackInStockNotificationForm(form)) onSaved();
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const handleEmailInput = (e: Event) =>
|
|
50
|
+
setBackInStockNotificationFormEmail(
|
|
51
|
+
form,
|
|
52
|
+
(e.target as HTMLInputElement).value,
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<form className="kombos-pd-bis__form" onSubmit={handleSubmit}>
|
|
57
|
+
{description && <p className="kombos-pd-bis__desc">{description}</p>}
|
|
58
|
+
<FormItem
|
|
59
|
+
label={emailLabel}
|
|
60
|
+
htmlFor="back-in-stock-email"
|
|
61
|
+
status={emailHasError ? "error" : "default"}
|
|
62
|
+
helper={emailHasError ? form.email?.message : undefined}
|
|
63
|
+
>
|
|
64
|
+
<Input
|
|
65
|
+
id="back-in-stock-email"
|
|
66
|
+
type="email"
|
|
67
|
+
value={form.email?.value ?? ""}
|
|
68
|
+
placeholder={form.email?.placeholder}
|
|
69
|
+
status={emailHasError ? "error" : "default"}
|
|
70
|
+
onInput={handleEmailInput}
|
|
71
|
+
/>
|
|
72
|
+
</FormItem>
|
|
73
|
+
{form.isFailure && (
|
|
74
|
+
<p className="kombos-pd-bis__error">
|
|
75
|
+
{form.responseMessage || errorMessage}
|
|
76
|
+
</p>
|
|
77
|
+
)}
|
|
78
|
+
<Button
|
|
79
|
+
variant="primary"
|
|
80
|
+
size="s"
|
|
81
|
+
type="submit"
|
|
82
|
+
className="kombos-pd-bis__submit"
|
|
83
|
+
loading={form.isSubmitting}
|
|
84
|
+
disabled={form.isSubmitting}
|
|
85
|
+
>
|
|
86
|
+
{form.isSubmitting ? submittingText : submitButtonText}
|
|
87
|
+
</Button>
|
|
88
|
+
</form>
|
|
89
|
+
);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
export default BackInStockForm;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "{{PROJECT_ID}}-product-detail-back-in-stock",
|
|
3
|
+
"name": "ProductDetailBackInStock",
|
|
4
|
+
"type": "component",
|
|
5
|
+
"entry": "./src/components/ProductDetailBackInStock/index.tsx",
|
|
6
|
+
"styles": "./src/components/ProductDetailBackInStock/styles.css",
|
|
7
|
+
"props": [
|
|
8
|
+
{
|
|
9
|
+
"name": "product",
|
|
10
|
+
"displayName": "Product",
|
|
11
|
+
"type": "PRODUCT",
|
|
12
|
+
"required": false
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"name": "notifyButtonText",
|
|
16
|
+
"displayName": "Notify Button Text",
|
|
17
|
+
"type": "TEXT",
|
|
18
|
+
"required": false,
|
|
19
|
+
"defaultValue": "Notify Me When Available",
|
|
20
|
+
"groupId": "texts"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"name": "reminderSavedText",
|
|
24
|
+
"displayName": "Reminder Saved Text",
|
|
25
|
+
"type": "TEXT",
|
|
26
|
+
"required": false,
|
|
27
|
+
"defaultValue": "We'll notify you",
|
|
28
|
+
"groupId": "texts"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"name": "alreadySavedMessage",
|
|
32
|
+
"displayName": "Already Saved Message",
|
|
33
|
+
"type": "TEXT",
|
|
34
|
+
"required": false,
|
|
35
|
+
"defaultValue": "You're already on the list — we'll email you when it's back.",
|
|
36
|
+
"groupId": "texts"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"name": "savedMessage",
|
|
40
|
+
"displayName": "Saved Success Message",
|
|
41
|
+
"type": "TEXT",
|
|
42
|
+
"required": false,
|
|
43
|
+
"defaultValue": "Great! We'll email you when this product is back in stock.",
|
|
44
|
+
"groupId": "texts"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"name": "loginRequiredMessage",
|
|
48
|
+
"displayName": "Login Required Message",
|
|
49
|
+
"type": "TEXT",
|
|
50
|
+
"required": false,
|
|
51
|
+
"defaultValue": "Please sign in so we can notify you.",
|
|
52
|
+
"groupId": "texts"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"name": "errorMessage",
|
|
56
|
+
"displayName": "Error Message",
|
|
57
|
+
"type": "TEXT",
|
|
58
|
+
"required": false,
|
|
59
|
+
"defaultValue": "Something went wrong. Please try again.",
|
|
60
|
+
"groupId": "texts"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"name": "modalTitle",
|
|
64
|
+
"displayName": "Email Modal Title",
|
|
65
|
+
"type": "TEXT",
|
|
66
|
+
"required": false,
|
|
67
|
+
"defaultValue": "Notify me when available",
|
|
68
|
+
"groupId": "texts"
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"name": "modalDescription",
|
|
72
|
+
"displayName": "Email Modal Description",
|
|
73
|
+
"type": "TEXT",
|
|
74
|
+
"required": false,
|
|
75
|
+
"defaultValue": "Enter your email and we'll let you know the moment this product is back in stock.",
|
|
76
|
+
"groupId": "texts"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"name": "emailLabel",
|
|
80
|
+
"displayName": "Email Field Label",
|
|
81
|
+
"type": "TEXT",
|
|
82
|
+
"required": false,
|
|
83
|
+
"defaultValue": "Email",
|
|
84
|
+
"groupId": "texts"
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"name": "submitButtonText",
|
|
88
|
+
"displayName": "Submit Button Text",
|
|
89
|
+
"type": "TEXT",
|
|
90
|
+
"required": false,
|
|
91
|
+
"defaultValue": "Notify Me",
|
|
92
|
+
"groupId": "texts"
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"name": "submittingText",
|
|
96
|
+
"displayName": "Submitting Text",
|
|
97
|
+
"type": "TEXT",
|
|
98
|
+
"required": false,
|
|
99
|
+
"defaultValue": "Saving...",
|
|
100
|
+
"groupId": "texts"
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
"name": "mobileMarginTop",
|
|
104
|
+
"displayName": "Top Spacing",
|
|
105
|
+
"type": "TYPE",
|
|
106
|
+
"required": false,
|
|
107
|
+
"groupId": "mobile",
|
|
108
|
+
"typeId": "@ikas/bp-storefront-models-MarginTopStyleType"
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
"name": "mobileMarginBottom",
|
|
112
|
+
"displayName": "Bottom Spacing",
|
|
113
|
+
"type": "TYPE",
|
|
114
|
+
"required": false,
|
|
115
|
+
"groupId": "mobile",
|
|
116
|
+
"typeId": "@ikas/bp-storefront-models-MarginBottomStyleType"
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
"name": "desktopMarginTop",
|
|
120
|
+
"displayName": "Top Spacing",
|
|
121
|
+
"type": "TYPE",
|
|
122
|
+
"required": false,
|
|
123
|
+
"groupId": "desktop",
|
|
124
|
+
"typeId": "@ikas/bp-storefront-models-MarginTopStyleType"
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
"name": "desktopMarginBottom",
|
|
128
|
+
"displayName": "Bottom Spacing",
|
|
129
|
+
"type": "TYPE",
|
|
130
|
+
"required": false,
|
|
131
|
+
"groupId": "desktop",
|
|
132
|
+
"typeId": "@ikas/bp-storefront-models-MarginBottomStyleType"
|
|
133
|
+
}
|
|
134
|
+
],
|
|
135
|
+
"propGroups": [
|
|
136
|
+
{
|
|
137
|
+
"id": "appearance",
|
|
138
|
+
"name": "Appearance Settings",
|
|
139
|
+
"children": [
|
|
140
|
+
{
|
|
141
|
+
"id": "mobile",
|
|
142
|
+
"name": "Mobile View",
|
|
143
|
+
"description": "Margin settings for mobile devices"
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
"id": "desktop",
|
|
147
|
+
"name": "Desktop View",
|
|
148
|
+
"description": "Margin settings for desktop devices"
|
|
149
|
+
}
|
|
150
|
+
],
|
|
151
|
+
"description": "Component mobile and desktop view settings"
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
"id": "texts",
|
|
155
|
+
"name": "Texts",
|
|
156
|
+
"description": "Button, status and modal texts"
|
|
157
|
+
}
|
|
158
|
+
]
|
|
159
|
+
}
|
package/data/section-templates/product-detail-section/children/ProductDetailBackInStock/index.tsx
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getSelectedProductVariant,
|
|
3
|
+
hasProductStock,
|
|
4
|
+
hasProductVariantStock,
|
|
5
|
+
getProductVariantIsBackInStockEnabled,
|
|
6
|
+
getProductVariantIsBackInStockCustomerLoginRequired,
|
|
7
|
+
saveProductVariantBackInStockReminder,
|
|
8
|
+
getFormattedMarginTopSize,
|
|
9
|
+
getFormattedMarginBottomSize,
|
|
10
|
+
customerStore,
|
|
11
|
+
Router,
|
|
12
|
+
} from "@ikas/bp-storefront";
|
|
13
|
+
import { useEffect, useState } from "preact/hooks";
|
|
14
|
+
import { Props } from "./types";
|
|
15
|
+
import Button from "../../sub-components/Button";
|
|
16
|
+
import Modal from "../../sub-components/Modal";
|
|
17
|
+
import { showToast } from "../../utils/toast";
|
|
18
|
+
import BackInStockForm from "./components/BackInStockForm";
|
|
19
|
+
|
|
20
|
+
export function ProductDetailBackInStock({
|
|
21
|
+
product,
|
|
22
|
+
notifyButtonText = "Notify Me When Available",
|
|
23
|
+
reminderSavedText = "We'll notify you",
|
|
24
|
+
alreadySavedMessage = "You're already on the list — we'll email you when it's back.",
|
|
25
|
+
savedMessage = "Great! We'll email you when this product is back in stock.",
|
|
26
|
+
loginRequiredMessage = "Please sign in so we can notify you.",
|
|
27
|
+
errorMessage = "Something went wrong. Please try again.",
|
|
28
|
+
modalTitle = "Notify me when available",
|
|
29
|
+
modalDescription = "Enter your email and we'll let you know the moment this product is back in stock.",
|
|
30
|
+
emailLabel = "Email",
|
|
31
|
+
submitButtonText = "Notify Me",
|
|
32
|
+
submittingText = "Saving...",
|
|
33
|
+
mobileMarginTop,
|
|
34
|
+
mobileMarginBottom,
|
|
35
|
+
desktopMarginTop,
|
|
36
|
+
desktopMarginBottom,
|
|
37
|
+
}: Props) {
|
|
38
|
+
const [isEmailModalOpen, setIsEmailModalOpen] = useState(false);
|
|
39
|
+
const [reminderSaved, setReminderSaved] = useState(false);
|
|
40
|
+
|
|
41
|
+
const selectedVariant = product
|
|
42
|
+
? getSelectedProductVariant(product)
|
|
43
|
+
: undefined;
|
|
44
|
+
|
|
45
|
+
// Reset local UI state when the selected variant changes, seeding "saved"
|
|
46
|
+
// from the variant's own persisted reminder state.
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
setReminderSaved(!!selectedVariant?.isBackInStockReminderSaved);
|
|
49
|
+
setIsEmailModalOpen(false);
|
|
50
|
+
}, [selectedVariant?.id]);
|
|
51
|
+
|
|
52
|
+
if (!product || !selectedVariant) return null;
|
|
53
|
+
|
|
54
|
+
// This component owns the notify-me flow only. Stay out of the way unless the
|
|
55
|
+
// variant is out of stock AND back-in-stock reminders are enabled for it.
|
|
56
|
+
const isOutOfStock =
|
|
57
|
+
!hasProductStock(product) || !hasProductVariantStock(selectedVariant);
|
|
58
|
+
if (!isOutOfStock || !getProductVariantIsBackInStockEnabled(selectedVariant)) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Login-required branch: register a logged-in customer immediately, otherwise
|
|
63
|
+
// send an anonymous visitor to login first.
|
|
64
|
+
const registerWithCustomerEmail = async () => {
|
|
65
|
+
const email = customerStore.customer?.email;
|
|
66
|
+
if (!email) {
|
|
67
|
+
showToast(loginRequiredMessage, "error");
|
|
68
|
+
Router.navigateToPage("LOGIN");
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const ok = await saveProductVariantBackInStockReminder(selectedVariant, email);
|
|
72
|
+
setReminderSaved(ok);
|
|
73
|
+
showToast(ok ? savedMessage : errorMessage, ok ? "success" : "error");
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const handleNotifyClick = () => {
|
|
77
|
+
if (reminderSaved) {
|
|
78
|
+
showToast(alreadySavedMessage, "success");
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (getProductVariantIsBackInStockCustomerLoginRequired(selectedVariant)) {
|
|
82
|
+
void registerWithCustomerEmail();
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
// No login required: collect the email through the form.
|
|
86
|
+
setIsEmailModalOpen(true);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const handleFormSaved = () => {
|
|
90
|
+
setReminderSaved(true);
|
|
91
|
+
setIsEmailModalOpen(false);
|
|
92
|
+
showToast(savedMessage, "success");
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
<div
|
|
97
|
+
className="kombos-pd-bis"
|
|
98
|
+
style={{
|
|
99
|
+
"--mobile-mt": getFormattedMarginTopSize(mobileMarginTop),
|
|
100
|
+
"--mobile-mb": getFormattedMarginBottomSize(mobileMarginBottom),
|
|
101
|
+
"--desktop-mt": getFormattedMarginTopSize(desktopMarginTop),
|
|
102
|
+
"--desktop-mb": getFormattedMarginBottomSize(desktopMarginBottom),
|
|
103
|
+
}}
|
|
104
|
+
>
|
|
105
|
+
{reminderSaved ? (
|
|
106
|
+
<div className="kombos-pd-bis__saved" aria-live="polite">
|
|
107
|
+
{reminderSavedText}
|
|
108
|
+
</div>
|
|
109
|
+
) : (
|
|
110
|
+
<Button
|
|
111
|
+
variant="secondary"
|
|
112
|
+
size="s"
|
|
113
|
+
className="kombos-pd-bis__btn"
|
|
114
|
+
onClick={handleNotifyClick}
|
|
115
|
+
>
|
|
116
|
+
{notifyButtonText}
|
|
117
|
+
</Button>
|
|
118
|
+
)}
|
|
119
|
+
|
|
120
|
+
{isEmailModalOpen && (
|
|
121
|
+
<Modal
|
|
122
|
+
title={modalTitle}
|
|
123
|
+
onClose={() => setIsEmailModalOpen(false)}
|
|
124
|
+
footer={null}
|
|
125
|
+
>
|
|
126
|
+
<BackInStockForm
|
|
127
|
+
variant={selectedVariant}
|
|
128
|
+
description={modalDescription}
|
|
129
|
+
emailLabel={emailLabel}
|
|
130
|
+
submitButtonText={submitButtonText}
|
|
131
|
+
submittingText={submittingText}
|
|
132
|
+
errorMessage={errorMessage}
|
|
133
|
+
onSaved={handleFormSaved}
|
|
134
|
+
/>
|
|
135
|
+
</Modal>
|
|
136
|
+
)}
|
|
137
|
+
</div>
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export default ProductDetailBackInStock;
|
package/data/section-templates/product-detail-section/children/ProductDetailBackInStock/styles.css
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/* ===== ProductDetailBackInStock ===== */
|
|
2
|
+
|
|
3
|
+
.kombos-pd-bis {
|
|
4
|
+
display: flex;
|
|
5
|
+
flex-direction: column;
|
|
6
|
+
gap: 0.75rem;
|
|
7
|
+
margin-top: var(--mobile-mt);
|
|
8
|
+
margin-bottom: var(--mobile-mb);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.kombos-pd-bis__btn {
|
|
12
|
+
width: 100%;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.kombos-pd-bis__saved {
|
|
16
|
+
padding: 0.75rem 1rem;
|
|
17
|
+
border: 1px solid var(--color-border, #e5e5e5);
|
|
18
|
+
border-radius: 0.5rem;
|
|
19
|
+
text-align: center;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.kombos-pd-bis__form {
|
|
23
|
+
display: flex;
|
|
24
|
+
flex-direction: column;
|
|
25
|
+
gap: 1rem;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.kombos-pd-bis__desc {
|
|
29
|
+
margin: 0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.kombos-pd-bis__error {
|
|
33
|
+
margin: 0;
|
|
34
|
+
color: var(--color-danger, #d92d20);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.kombos-pd-bis__submit {
|
|
38
|
+
width: 100%;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/* ===== Desktop (>=1024px) ===== */
|
|
42
|
+
@media (min-width: 1024px) {
|
|
43
|
+
.kombos-pd-bis {
|
|
44
|
+
margin-top: var(--desktop-mt, var(--mobile-mt));
|
|
45
|
+
margin-bottom: var(--desktop-mb, var(--mobile-mb));
|
|
46
|
+
}
|
|
47
|
+
}
|