@nuvler/cli 0.5.16 → 0.5.18
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/api/theme-context.js +2 -0
- package/dist/api/theme-context.js.map +1 -1
- package/dist/commands/theme/create.js +1 -1
- package/dist/nuvler.js +24 -1
- package/dist/nuvler.js.map +1 -1
- package/dist/templates/nuvler-atelier/package.json +2 -2
- package/dist/templates/nuvler-default/README.md +4 -4
- package/dist/templates/nuvler-default/nuvler.theme.json +1 -1
- package/dist/templates/nuvler-default/package.json +2 -2
- package/dist/templates/nuvler-default/src/catalog-filters.tsx +169 -0
- package/dist/templates/nuvler-default/src/contact-form.tsx +172 -0
- package/dist/templates/nuvler-default/src/home-data.ts +30 -0
- package/dist/templates/nuvler-default/src/home.tsx +2 -196
- package/dist/templates/nuvler-default/src/interaction-colors.ts +49 -0
- package/dist/templates/nuvler-default/src/kit-composition.ts +15 -0
- package/dist/templates/nuvler-default/src/kit-group-selector.tsx +230 -0
- package/dist/templates/nuvler-default/src/kit-selection.ts +39 -0
- package/dist/templates/nuvler-default/src/product-detail-interactive.tsx +420 -115
- package/dist/templates/nuvler-default/src/product-detail.tsx +141 -59
- package/dist/templates/nuvler-default/src/products.tsx +143 -12
- package/dist/templates/nuvler-default/src/server-shell.tsx +21 -3
- package/dist/templates/nuvler-default/src/theme-component.tsx +85 -24
- package/dist/templates/nuvler-default/src/theme.css +673 -6
- package/dist/templates/nuvler-default/src/whatsapp-message.ts +82 -0
- package/dist/templates/nuvler-default/test/catalog-filters.test.mjs +44 -0
- package/dist/templates/nuvler-default/test/interaction-colors.test.mjs +74 -0
- package/dist/templates/nuvler-default/test/kit-composition.test.mjs +28 -0
- package/dist/templates/nuvler-default/test/kit-detail.test.mjs +292 -0
- package/dist/templates/nuvler-default/test/whatsapp-message.test.mjs +126 -0
- package/dist/templates/starter/package.json +2 -2
- package/package.json +3 -3
- package/preview-host/package.json +1 -1
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
+
import {
|
|
4
|
+
formatWhatsappRequest,
|
|
5
|
+
whatsappRequestLabel,
|
|
6
|
+
whatsappRequestUrl,
|
|
7
|
+
} from "./whatsapp-message.js";
|
|
8
|
+
|
|
3
9
|
import {
|
|
4
10
|
createContext,
|
|
5
11
|
useEffect,
|
|
@@ -10,7 +16,16 @@ import {
|
|
|
10
16
|
type PointerEvent,
|
|
11
17
|
type ReactNode,
|
|
12
18
|
} from "react";
|
|
13
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
verifyKitCart,
|
|
21
|
+
productUrl as relativeProductUrl,
|
|
22
|
+
type ProductDetailProps,
|
|
23
|
+
type ThemeCartItem,
|
|
24
|
+
type ThemeImage,
|
|
25
|
+
} from "@nuvler/theme-sdk";
|
|
26
|
+
|
|
27
|
+
import { KitGroupSelector } from "./kit-group-selector.js";
|
|
28
|
+
import { getKitGroupSelection } from "./kit-selection.js";
|
|
14
29
|
|
|
15
30
|
type AddToCart = NonNullable<ProductDetailProps["onAddToCart"]>;
|
|
16
31
|
|
|
@@ -24,7 +39,11 @@ export function ThemeInteractionProvider({
|
|
|
24
39
|
onAddToCart?: AddToCart;
|
|
25
40
|
}) {
|
|
26
41
|
const value = useMemo(() => ({ onAddToCart }), [onAddToCart]);
|
|
27
|
-
return
|
|
42
|
+
return (
|
|
43
|
+
<ThemeInteractionContext.Provider value={value}>
|
|
44
|
+
{children}
|
|
45
|
+
</ThemeInteractionContext.Provider>
|
|
46
|
+
);
|
|
28
47
|
}
|
|
29
48
|
|
|
30
49
|
export function ProductCardAction({
|
|
@@ -40,14 +59,33 @@ export function ProductCardAction({
|
|
|
40
59
|
}) {
|
|
41
60
|
const { onAddToCart } = useContext(ThemeInteractionContext);
|
|
42
61
|
|
|
43
|
-
if (unavailable)
|
|
62
|
+
if (unavailable)
|
|
63
|
+
return (
|
|
64
|
+
<span className="button button-secondary button-block product-card-action product-card-action-unavailable">
|
|
65
|
+
Indisponível
|
|
66
|
+
</span>
|
|
67
|
+
);
|
|
44
68
|
|
|
45
69
|
if (hasVariants) {
|
|
46
|
-
return
|
|
70
|
+
return (
|
|
71
|
+
<a
|
|
72
|
+
className="button button-secondary button-block product-card-action"
|
|
73
|
+
href={href}
|
|
74
|
+
>
|
|
75
|
+
Escolher opções
|
|
76
|
+
</a>
|
|
77
|
+
);
|
|
47
78
|
}
|
|
48
79
|
|
|
49
80
|
if (!onAddToCart) {
|
|
50
|
-
return
|
|
81
|
+
return (
|
|
82
|
+
<a
|
|
83
|
+
className="button button-secondary button-block product-card-action"
|
|
84
|
+
href={href}
|
|
85
|
+
>
|
|
86
|
+
Ver detalhes
|
|
87
|
+
</a>
|
|
88
|
+
);
|
|
51
89
|
}
|
|
52
90
|
|
|
53
91
|
return (
|
|
@@ -56,12 +94,15 @@ export function ProductCardAction({
|
|
|
56
94
|
className="button button-primary button-block product-card-action"
|
|
57
95
|
onClick={() => onAddToCart(item)}
|
|
58
96
|
>
|
|
59
|
-
Adicionar ao
|
|
97
|
+
Adicionar ao Carrinho
|
|
60
98
|
</button>
|
|
61
99
|
);
|
|
62
100
|
}
|
|
63
101
|
|
|
64
|
-
interface ProductDetailInteractiveProps extends Omit<
|
|
102
|
+
interface ProductDetailInteractiveProps extends Omit<
|
|
103
|
+
ProductDetailProps,
|
|
104
|
+
"descriptionContent"
|
|
105
|
+
> {
|
|
65
106
|
information: ReactNode;
|
|
66
107
|
benefits: ReactNode;
|
|
67
108
|
galleryImages: ReactNode;
|
|
@@ -82,13 +123,71 @@ export function ProductDetailInteractive({
|
|
|
82
123
|
const context = useContext(ThemeInteractionContext);
|
|
83
124
|
const addToCart = onAddToCart ?? context.onAddToCart;
|
|
84
125
|
const initialVariant = product.variants.find((item) => item.active);
|
|
85
|
-
const [selected, setSelected] = useState<Record<string, string>>(() =>
|
|
86
|
-
|
|
87
|
-
option
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
126
|
+
const [selected, setSelected] = useState<Record<string, string>>(() =>
|
|
127
|
+
Object.fromEntries(
|
|
128
|
+
product.variantOptions.map((option) => [
|
|
129
|
+
option.name,
|
|
130
|
+
initialVariant?.values.find(({ name }) => name === option.name)
|
|
131
|
+
?.value ??
|
|
132
|
+
option.values[0] ??
|
|
133
|
+
"",
|
|
134
|
+
]),
|
|
135
|
+
),
|
|
136
|
+
);
|
|
91
137
|
const [imageUrl, setImageUrl] = useState<string>();
|
|
138
|
+
const [quantities, setQuantities] = useState<Record<string, string>>({});
|
|
139
|
+
const [kitError, setKitError] = useState("");
|
|
140
|
+
const hasGroups = Boolean(product.kitGroups?.length);
|
|
141
|
+
const groups = product.kitGroups?.length
|
|
142
|
+
? product.kitGroups
|
|
143
|
+
: product.kitSize
|
|
144
|
+
? [
|
|
145
|
+
{
|
|
146
|
+
id: "legacy",
|
|
147
|
+
name: "Sabores",
|
|
148
|
+
quantity: product.kitSize,
|
|
149
|
+
options: product.variants
|
|
150
|
+
.filter((item) => item.id)
|
|
151
|
+
.map((item) => ({
|
|
152
|
+
id: item.id!,
|
|
153
|
+
name:
|
|
154
|
+
item.name ||
|
|
155
|
+
item.values.map((value) => value.value).join(" / "),
|
|
156
|
+
active: item.active,
|
|
157
|
+
})),
|
|
158
|
+
},
|
|
159
|
+
]
|
|
160
|
+
: [];
|
|
161
|
+
const kitSize = groups.reduce((sum, group) => sum + group.quantity, 0);
|
|
162
|
+
const groupSelections = groups.map((group) =>
|
|
163
|
+
getKitGroupSelection(group, hasGroups, quantities),
|
|
164
|
+
);
|
|
165
|
+
const composition = groups.flatMap((group, index) =>
|
|
166
|
+
groupSelections[index].selected.map(({ option, raw }) => ({
|
|
167
|
+
variantId: option.id,
|
|
168
|
+
name: option.name,
|
|
169
|
+
quantity: Number(raw),
|
|
170
|
+
...(hasGroups ? { groupId: group.id } : {}),
|
|
171
|
+
})),
|
|
172
|
+
);
|
|
173
|
+
const completedGroups = groupSelections.filter(
|
|
174
|
+
(selection) => selection.complete,
|
|
175
|
+
).length;
|
|
176
|
+
const kitValid =
|
|
177
|
+
Object.values(quantities).every(
|
|
178
|
+
(value) =>
|
|
179
|
+
value === "" ||
|
|
180
|
+
(Number.isSafeInteger(Number(value)) && Number(value) >= 0),
|
|
181
|
+
) && groupSelections.every((selection) => selection.complete);
|
|
182
|
+
const kitItem = {
|
|
183
|
+
productSlug: product.slug,
|
|
184
|
+
title: product.title,
|
|
185
|
+
sku: product.sku,
|
|
186
|
+
kitSize,
|
|
187
|
+
composition,
|
|
188
|
+
...(hasGroups ? { kitGroups: groups } : {}),
|
|
189
|
+
};
|
|
190
|
+
|
|
92
191
|
const galleryRef = useRef<HTMLDivElement>(null);
|
|
93
192
|
const [zoomEnabled, setZoomEnabled] = useState(true);
|
|
94
193
|
const [zoom, setZoom] = useState({
|
|
@@ -101,75 +200,127 @@ export function ProductDetailInteractive({
|
|
|
101
200
|
backgroundWidth: 0,
|
|
102
201
|
backgroundHeight: 0,
|
|
103
202
|
});
|
|
104
|
-
const variant = useMemo(
|
|
105
|
-
|
|
106
|
-
|
|
203
|
+
const variant = useMemo(
|
|
204
|
+
() =>
|
|
205
|
+
product.variants.find(
|
|
206
|
+
(item) =>
|
|
207
|
+
item.active &&
|
|
208
|
+
item.values.every(({ name, value }) => selected[name] === value),
|
|
209
|
+
),
|
|
210
|
+
[product.variants, selected],
|
|
211
|
+
);
|
|
107
212
|
const images = useMemo(() => {
|
|
108
|
-
if (variant?.image?.url) return [variant.image];
|
|
213
|
+
if (!kitSize && variant?.image?.url) return [variant.image];
|
|
109
214
|
const unique = new Map<string, ThemeImage>();
|
|
110
215
|
[product.image, ...(product.images || [])].forEach((image) => {
|
|
111
216
|
if (image?.url) unique.set(image.url, image);
|
|
112
217
|
});
|
|
113
218
|
return [...unique.values()];
|
|
114
|
-
}, [product.image, product.images, variant]);
|
|
115
|
-
const selectedImage =
|
|
219
|
+
}, [product.image, product.images, variant, kitSize]);
|
|
220
|
+
const selectedImage =
|
|
221
|
+
images.find((image) => image.url === imageUrl) ||
|
|
222
|
+
images[0] ||
|
|
223
|
+
product.image;
|
|
116
224
|
const phone = contact?.whatsapp?.replace(/\D/g, "");
|
|
117
|
-
const variantDescription =
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
:
|
|
122
|
-
const message =
|
|
123
|
-
|
|
225
|
+
const variantDescription =
|
|
226
|
+
variant?.values.map(({ name, value }) => `${name}: ${value}`).join(", ") ||
|
|
227
|
+
"";
|
|
228
|
+
const unitPrice =
|
|
229
|
+
variant && !kitSize ? null : (product.promotionalPrice ?? product.price);
|
|
230
|
+
const message = formatWhatsappRequest(
|
|
231
|
+
[
|
|
232
|
+
{
|
|
233
|
+
...kitItem,
|
|
234
|
+
kitSize: kitSize || null,
|
|
235
|
+
variantName: kitSize ? "" : variantDescription,
|
|
236
|
+
sku: kitSize ? product.sku : variant?.sku || product.sku,
|
|
237
|
+
unitPrice: showPrices ? unitPrice : null,
|
|
238
|
+
productUrl: productUrl ?? undefined,
|
|
239
|
+
},
|
|
240
|
+
],
|
|
241
|
+
showPrices,
|
|
242
|
+
typeof window === "undefined" ? undefined : window.location.origin,
|
|
243
|
+
);
|
|
244
|
+
const whatsapp = phone ? whatsappRequestUrl(phone, message) : null;
|
|
124
245
|
const hasVariants = product.variantOptions.length > 0;
|
|
125
246
|
const outOfStock = product.stockQuantity === 0;
|
|
126
|
-
const canPurchase =
|
|
247
|
+
const canPurchase =
|
|
248
|
+
!outOfStock && (kitSize ? kitValid : !hasVariants || Boolean(variant));
|
|
127
249
|
|
|
128
250
|
useEffect(() => {
|
|
129
251
|
const gallery = galleryRef.current;
|
|
130
252
|
if (!gallery) return;
|
|
131
253
|
const selectedUrl = selectedImage?.url ?? "";
|
|
132
|
-
const allowedUrls = new Set(
|
|
254
|
+
const allowedUrls = new Set(
|
|
255
|
+
images.flatMap((image) => (image.url ? [image.url] : [])),
|
|
256
|
+
);
|
|
133
257
|
|
|
134
|
-
gallery
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
258
|
+
gallery
|
|
259
|
+
.querySelectorAll<HTMLElement>("[data-product-main-image]")
|
|
260
|
+
.forEach((node) => {
|
|
261
|
+
node.hidden = node.dataset.productMainImage !== selectedUrl;
|
|
262
|
+
});
|
|
263
|
+
gallery
|
|
264
|
+
.querySelectorAll<HTMLButtonElement>("[data-product-thumbnail]")
|
|
265
|
+
.forEach((button) => {
|
|
266
|
+
const url = button.dataset.productThumbnail ?? "";
|
|
267
|
+
button.hidden = !allowedUrls.has(url);
|
|
268
|
+
button.classList.toggle("active", url === selectedUrl);
|
|
269
|
+
button.setAttribute("aria-pressed", String(url === selectedUrl));
|
|
270
|
+
});
|
|
143
271
|
}, [images, selectedImage?.url]);
|
|
144
272
|
|
|
145
273
|
function moveZoom(event: PointerEvent<HTMLDivElement>) {
|
|
146
|
-
if (
|
|
274
|
+
if (
|
|
275
|
+
event.pointerType !== "mouse" ||
|
|
276
|
+
!selectedImage?.url ||
|
|
277
|
+
!zoomEnabled ||
|
|
278
|
+
(event.target as Element).closest(".product-zoom-toggle")
|
|
279
|
+
) {
|
|
147
280
|
setZoom((current) => ({ ...current, visible: false }));
|
|
148
281
|
return;
|
|
149
282
|
}
|
|
150
283
|
const bounds = event.currentTarget.getBoundingClientRect();
|
|
151
|
-
const image = event.currentTarget.querySelector<HTMLImageElement>(
|
|
152
|
-
|
|
153
|
-
|
|
284
|
+
const image = event.currentTarget.querySelector<HTMLImageElement>(
|
|
285
|
+
"[data-product-main-image]:not([hidden]) img",
|
|
286
|
+
);
|
|
287
|
+
const naturalWidth =
|
|
288
|
+
image?.naturalWidth || selectedImage.width || bounds.width;
|
|
289
|
+
const naturalHeight =
|
|
290
|
+
image?.naturalHeight || selectedImage.height || bounds.height;
|
|
154
291
|
const imageAspect = naturalWidth / naturalHeight;
|
|
155
292
|
const containerAspect = bounds.width / bounds.height;
|
|
156
|
-
const renderedWidth =
|
|
157
|
-
|
|
293
|
+
const renderedWidth =
|
|
294
|
+
imageAspect > containerAspect
|
|
295
|
+
? bounds.width
|
|
296
|
+
: bounds.height * imageAspect;
|
|
297
|
+
const renderedHeight =
|
|
298
|
+
imageAspect > containerAspect
|
|
299
|
+
? bounds.width / imageAspect
|
|
300
|
+
: bounds.height;
|
|
158
301
|
const left = (bounds.width - renderedWidth) / 2;
|
|
159
302
|
const top = (bounds.height - renderedHeight) / 2;
|
|
160
|
-
const pointerX = Math.max(
|
|
161
|
-
|
|
303
|
+
const pointerX = Math.max(
|
|
304
|
+
left,
|
|
305
|
+
Math.min(left + renderedWidth, event.clientX - bounds.left),
|
|
306
|
+
);
|
|
307
|
+
const pointerY = Math.max(
|
|
308
|
+
top,
|
|
309
|
+
Math.min(top + renderedHeight, event.clientY - bounds.top),
|
|
310
|
+
);
|
|
162
311
|
const size = Math.min(280, Math.max(210, bounds.width * 0.42));
|
|
163
312
|
const scale = 2.5;
|
|
164
313
|
const backgroundWidth = renderedWidth * scale;
|
|
165
314
|
const backgroundHeight = renderedHeight * scale;
|
|
166
315
|
setZoom({
|
|
167
316
|
visible: true,
|
|
168
|
-
x: pointerX / bounds.width * 100,
|
|
169
|
-
y: pointerY / bounds.height * 100,
|
|
317
|
+
x: (pointerX / bounds.width) * 100,
|
|
318
|
+
y: (pointerY / bounds.height) * 100,
|
|
170
319
|
size,
|
|
171
|
-
backgroundX:
|
|
172
|
-
|
|
320
|
+
backgroundX:
|
|
321
|
+
size / 2 - ((pointerX - left) / renderedWidth) * backgroundWidth,
|
|
322
|
+
backgroundY:
|
|
323
|
+
size / 2 - ((pointerY - top) / renderedHeight) * backgroundHeight,
|
|
173
324
|
backgroundWidth,
|
|
174
325
|
backgroundHeight,
|
|
175
326
|
});
|
|
@@ -183,41 +334,56 @@ export function ProductDetailInteractive({
|
|
|
183
334
|
data-zoom-enabled={zoomEnabled}
|
|
184
335
|
onPointerEnter={moveZoom}
|
|
185
336
|
onPointerMove={moveZoom}
|
|
186
|
-
onPointerLeave={() =>
|
|
337
|
+
onPointerLeave={() =>
|
|
338
|
+
setZoom((current) => ({ ...current, visible: false }))
|
|
339
|
+
}
|
|
187
340
|
>
|
|
188
341
|
{galleryImages}
|
|
189
|
-
{selectedImage?.url &&
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
342
|
+
{selectedImage?.url && (
|
|
343
|
+
<button
|
|
344
|
+
className={`product-zoom-toggle${zoomEnabled ? " active" : ""}`}
|
|
345
|
+
type="button"
|
|
346
|
+
aria-pressed={zoomEnabled}
|
|
347
|
+
aria-label={zoomEnabled ? "Desativar lupa" : "Ativar lupa"}
|
|
348
|
+
onClick={() => {
|
|
349
|
+
setZoomEnabled((enabled) => !enabled);
|
|
350
|
+
setZoom((current) => ({ ...current, visible: false }));
|
|
351
|
+
}}
|
|
352
|
+
>
|
|
353
|
+
<svg viewBox="0 0 24 24" aria-hidden="true">
|
|
354
|
+
<circle cx="10.5" cy="10.5" r="6.5" />
|
|
355
|
+
<path d="m15.5 15.5 5 5M10.5 7.5v6M7.5 10.5h6" />
|
|
356
|
+
{!zoomEnabled && (
|
|
357
|
+
<path className="zoom-off-line" d="M3 3l18 18" />
|
|
358
|
+
)}
|
|
359
|
+
</svg>
|
|
360
|
+
<span>Lupa</span>
|
|
361
|
+
</button>
|
|
362
|
+
)}
|
|
363
|
+
{selectedImage?.url && (
|
|
364
|
+
<span
|
|
365
|
+
className={`product-zoom-lens${zoom.visible ? " visible" : ""}`}
|
|
366
|
+
aria-hidden="true"
|
|
367
|
+
style={{
|
|
368
|
+
left: `${zoom.x}%`,
|
|
369
|
+
top: `${zoom.y}%`,
|
|
370
|
+
width: zoom.size,
|
|
371
|
+
height: zoom.size,
|
|
372
|
+
backgroundImage: `url(${JSON.stringify(selectedImage.url)})`,
|
|
373
|
+
backgroundPosition: `${zoom.backgroundX}px ${zoom.backgroundY}px`,
|
|
374
|
+
backgroundSize: `${zoom.backgroundWidth}px ${zoom.backgroundHeight}px`,
|
|
375
|
+
}}
|
|
376
|
+
/>
|
|
377
|
+
)}
|
|
215
378
|
</div>
|
|
216
379
|
<div
|
|
217
380
|
className="product-thumbnails"
|
|
218
381
|
onClick={(event) => {
|
|
219
|
-
const button = (event.target as Element).closest<HTMLButtonElement>(
|
|
220
|
-
|
|
382
|
+
const button = (event.target as Element).closest<HTMLButtonElement>(
|
|
383
|
+
"[data-product-thumbnail]",
|
|
384
|
+
);
|
|
385
|
+
if (button?.dataset.productThumbnail)
|
|
386
|
+
setImageUrl(button.dataset.productThumbnail);
|
|
221
387
|
}}
|
|
222
388
|
>
|
|
223
389
|
{galleryThumbnails}
|
|
@@ -226,44 +392,183 @@ export function ProductDetailInteractive({
|
|
|
226
392
|
<div className="product-info">
|
|
227
393
|
{information}
|
|
228
394
|
<div className="product-purchase">
|
|
229
|
-
{
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
}
|
|
242
|
-
|
|
395
|
+
{kitSize > 0 && (
|
|
396
|
+
<div className="kit-groups">
|
|
397
|
+
{hasGroups && (
|
|
398
|
+
<div className="kit-heading">
|
|
399
|
+
<h2>Monte seu combo</h2>
|
|
400
|
+
<p>
|
|
401
|
+
Complete cada grupo para adicionar o combo ao orçamento.
|
|
402
|
+
</p>
|
|
403
|
+
</div>
|
|
404
|
+
)}
|
|
405
|
+
{groups.map((group, index) => (
|
|
406
|
+
<KitGroupSelector
|
|
407
|
+
key={group.id}
|
|
408
|
+
group={group}
|
|
409
|
+
grouped={hasGroups}
|
|
410
|
+
quantities={quantities}
|
|
411
|
+
setQuantities={setQuantities}
|
|
412
|
+
initiallyOpen={index === 0}
|
|
413
|
+
collapsible={groups.length > 1}
|
|
414
|
+
/>
|
|
415
|
+
))}
|
|
416
|
+
</div>
|
|
417
|
+
)}
|
|
418
|
+
{hasVariants && !kitSize && (
|
|
419
|
+
<div className="variant-selector">
|
|
420
|
+
{product.variantOptions.map((option) => (
|
|
421
|
+
<fieldset key={option.name}>
|
|
422
|
+
<legend>
|
|
423
|
+
{option.name}: <strong>{selected[option.name]}</strong>
|
|
424
|
+
</legend>
|
|
425
|
+
<div className="variant-values">
|
|
426
|
+
{option.values.map((value) => (
|
|
427
|
+
<button
|
|
428
|
+
key={value}
|
|
429
|
+
type="button"
|
|
430
|
+
className={
|
|
431
|
+
selected[option.name] === value ? "active" : ""
|
|
432
|
+
}
|
|
433
|
+
aria-pressed={selected[option.name] === value}
|
|
434
|
+
onClick={() => {
|
|
435
|
+
setSelected((current) => ({
|
|
436
|
+
...current,
|
|
437
|
+
[option.name]: value,
|
|
438
|
+
}));
|
|
439
|
+
setImageUrl(undefined);
|
|
440
|
+
}}
|
|
441
|
+
>
|
|
442
|
+
{value}
|
|
443
|
+
</button>
|
|
444
|
+
))}
|
|
445
|
+
</div>
|
|
446
|
+
</fieldset>
|
|
447
|
+
))}
|
|
448
|
+
{variant ? (
|
|
449
|
+
<p className="selected-variant">
|
|
450
|
+
<strong>{variant.name || variantDescription}</strong>
|
|
451
|
+
{variant.sku && <span>Referência: {variant.sku}</span>}
|
|
452
|
+
</p>
|
|
453
|
+
) : (
|
|
454
|
+
<p className="variant-unavailable">
|
|
455
|
+
Esta combinação não está disponível.
|
|
456
|
+
</p>
|
|
457
|
+
)}
|
|
458
|
+
</div>
|
|
459
|
+
)}
|
|
460
|
+
{kitError && <p role="alert">{kitError}</p>}
|
|
461
|
+
{outOfStock && (
|
|
462
|
+
<p className="product-purchase-unavailable" role="status">
|
|
463
|
+
Este produto está indisponível no momento.
|
|
464
|
+
</p>
|
|
465
|
+
)}
|
|
466
|
+
<div className={hasGroups ? "kit-purchase-actions" : undefined}>
|
|
467
|
+
{hasGroups && (
|
|
468
|
+
<div
|
|
469
|
+
className="kit-completion-summary"
|
|
470
|
+
data-complete={kitValid || undefined}
|
|
471
|
+
>
|
|
472
|
+
<p role="status" aria-live="polite">
|
|
473
|
+
<strong>
|
|
474
|
+
{completedGroups} de {groups.length}{" "}
|
|
475
|
+
{groups.length === 1
|
|
476
|
+
? "grupo completo"
|
|
477
|
+
: "grupos completos"}
|
|
478
|
+
</strong>
|
|
479
|
+
</p>
|
|
480
|
+
<div className="kit-completion-groups">
|
|
481
|
+
{groups.map((group, index) => (
|
|
482
|
+
<span
|
|
483
|
+
key={group.id}
|
|
484
|
+
data-complete={
|
|
485
|
+
groupSelections[index].complete || undefined
|
|
486
|
+
}
|
|
487
|
+
>
|
|
488
|
+
{groupSelections[index].complete ? "✓ " : ""}
|
|
489
|
+
{group.name}: {groupSelections[index].total}/
|
|
490
|
+
{group.quantity}
|
|
491
|
+
</span>
|
|
492
|
+
))}
|
|
493
|
+
</div>
|
|
494
|
+
<p>
|
|
495
|
+
{kitValid
|
|
496
|
+
? "Tudo pronto para adicionar ao orçamento."
|
|
497
|
+
: "Complete os grupos pendentes para continuar."}
|
|
498
|
+
</p>
|
|
243
499
|
</div>
|
|
244
|
-
|
|
245
|
-
{
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
500
|
+
)}
|
|
501
|
+
{!outOfStock && addToCart && (kitSize > 0 || canPurchase) && (
|
|
502
|
+
<button
|
|
503
|
+
disabled={!canPurchase}
|
|
504
|
+
type="button"
|
|
505
|
+
className="button button-primary button-block"
|
|
506
|
+
onClick={() =>
|
|
507
|
+
canPurchase &&
|
|
508
|
+
addToCart({
|
|
509
|
+
productSlug: product.slug,
|
|
510
|
+
productUrl: relativeProductUrl(product),
|
|
511
|
+
title: product.title,
|
|
512
|
+
sku: kitSize ? product.sku : variant?.sku || product.sku,
|
|
513
|
+
...(kitSize
|
|
514
|
+
? {
|
|
515
|
+
kitSize,
|
|
516
|
+
composition,
|
|
517
|
+
...(hasGroups ? { kitGroups: groups } : {}),
|
|
518
|
+
}
|
|
519
|
+
: {}),
|
|
520
|
+
variantId: kitSize ? null : variant?.id,
|
|
521
|
+
variantName: kitSize ? "" : variantDescription,
|
|
522
|
+
image: kitSize
|
|
523
|
+
? product.image
|
|
524
|
+
: variant?.image || product.image,
|
|
525
|
+
unitPrice: showPrices ? unitPrice : null,
|
|
526
|
+
})
|
|
527
|
+
}
|
|
528
|
+
>
|
|
529
|
+
Adicionar ao Carrinho
|
|
530
|
+
</button>
|
|
531
|
+
)}
|
|
532
|
+
{canPurchase && whatsapp && (
|
|
533
|
+
<a
|
|
534
|
+
className={`button ${addToCart ? "button-secondary" : "button-primary"} button-block`}
|
|
535
|
+
href={whatsapp}
|
|
536
|
+
onClick={async (event) => {
|
|
537
|
+
if (!kitSize) return;
|
|
538
|
+
event.preventDefault();
|
|
539
|
+
try {
|
|
540
|
+
await verifyKitCart([kitItem]);
|
|
541
|
+
setKitError("");
|
|
542
|
+
window.location.assign(whatsapp);
|
|
543
|
+
} catch {
|
|
544
|
+
setKitError(
|
|
545
|
+
"Não foi possível confirmar o kit. Revise os sabores ou tente novamente.",
|
|
546
|
+
);
|
|
547
|
+
}
|
|
548
|
+
}}
|
|
549
|
+
target="_blank"
|
|
550
|
+
rel="noreferrer"
|
|
551
|
+
>
|
|
552
|
+
{whatsappRequestLabel}
|
|
553
|
+
</a>
|
|
554
|
+
)}
|
|
555
|
+
{canPurchase && !whatsapp && contact?.email && (
|
|
556
|
+
<a
|
|
557
|
+
className="button button-primary button-block"
|
|
558
|
+
href={`mailto:${contact.email}?subject=${encodeURIComponent(`Orçamento: ${product.title}`)}&body=${encodeURIComponent(message)}`}
|
|
559
|
+
>
|
|
560
|
+
Solicitar orçamento por e-mail
|
|
561
|
+
</a>
|
|
562
|
+
)}
|
|
563
|
+
{canPurchase && !whatsapp && !contact?.email && contact?.phone && (
|
|
564
|
+
<a
|
|
565
|
+
className="button button-primary button-block"
|
|
566
|
+
href={`tel:${contact.phone}`}
|
|
567
|
+
>
|
|
568
|
+
Ligar e solicitar orçamento
|
|
569
|
+
</a>
|
|
570
|
+
)}
|
|
571
|
+
</div>
|
|
267
572
|
</div>
|
|
268
573
|
{benefits}
|
|
269
574
|
</div>
|