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