storefront-layouts 1.0.9 → 1.0.13
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/components/shipping/ProductDeliveryInfoSection.d.ts.map +1 -1
- package/dist/components/shipping/ProductDeliveryInfoSection.js +10 -3
- package/dist/components/ui/address-selector.d.ts.map +1 -1
- package/dist/components/ui/address-selector.js +4 -3
- package/dist/components/ui/button.js +1 -1
- package/dist/components/ui/checkout-button.d.ts.map +1 -1
- package/dist/components/ui/checkout-button.js +2 -1
- package/dist/components/ui/product-card.d.ts.map +1 -1
- package/dist/components/ui/product-card.js +15 -4
- package/dist/components/ui/route-skeleton-loader.d.ts.map +1 -1
- package/dist/components/ui/route-skeleton-loader.js +6 -2
- package/dist/components/ui/sheet.d.ts.map +1 -1
- package/dist/components/ui/sheet.js +2 -2
- package/dist/components/ui/skeletons/checkout-skeleton.js +1 -1
- package/dist/editor/blocks/defaults/clothing-minimal-home.js +1 -1
- package/dist/editor/blocks/migrate-clothing-minimal.js +1 -1
- package/dist/hooks/use-pdp-variation.d.ts +57 -0
- package/dist/hooks/use-pdp-variation.d.ts.map +1 -0
- package/dist/hooks/use-pdp-variation.js +69 -0
- package/dist/hooks/use-product-by-slug.d.ts.map +1 -1
- package/dist/hooks/use-product-by-slug.js +0 -5
- package/dist/hooks/use-product-variation-selection.js +1 -1
- package/dist/hooks/use-shipping-quote.d.ts +1 -0
- package/dist/hooks/use-shipping-quote.d.ts.map +1 -1
- package/dist/hooks/use-shipping-quote.js +3 -0
- package/dist/layouts/booking/pages/ProductDetailPage.d.ts.map +1 -1
- package/dist/layouts/booking/pages/ProductDetailPage.js +130 -223
- package/dist/layouts/booking-agenda/pages/ProductDetailPage.d.ts.map +1 -1
- package/dist/layouts/booking-agenda/pages/ProductDetailPage.js +130 -223
- package/dist/layouts/clothing/components/ClothingHomePage.d.ts.map +1 -1
- package/dist/layouts/clothing/components/ClothingHomePage.js +40 -2
- package/dist/layouts/clothing/pages/ProductDetailPage.d.ts.map +1 -1
- package/dist/layouts/clothing/pages/ProductDetailPage.js +127 -209
- package/dist/layouts/clothing/pages/ProductsPage.d.ts.map +1 -1
- package/dist/layouts/clothing/pages/ProductsPage.js +2 -5
- package/dist/layouts/clothing-minimal/components/ClothingHomePageMinimal.d.ts.map +1 -1
- package/dist/layouts/clothing-minimal/components/ClothingHomePageMinimal.js +5 -3
- package/dist/layouts/clothing-minimal/components/clothing-minimal-block-render.d.ts.map +1 -1
- package/dist/layouts/clothing-minimal/components/clothing-minimal-block-render.js +13 -4
- package/dist/layouts/clothing-minimal/pages/ProductDetailPage.d.ts.map +1 -1
- package/dist/layouts/clothing-minimal/pages/ProductDetailPage.js +130 -223
- package/dist/layouts/clothing-minimal/pages/ProductsPage.d.ts.map +1 -1
- package/dist/layouts/clothing-minimal/pages/ProductsPage.js +2 -5
- package/dist/layouts/electronics/components/ElectronicsGridProductCard.js +1 -1
- package/dist/layouts/electronics/components/ElectronicsStoreHeader.d.ts.map +1 -1
- package/dist/layouts/electronics/components/ElectronicsStoreHeader.js +10 -9
- package/dist/layouts/electronics/pages/ProductDetailPage.d.ts.map +1 -1
- package/dist/layouts/electronics/pages/ProductDetailPage.js +130 -223
- package/dist/layouts/electronics/pages/ProductsPage.d.ts.map +1 -1
- package/dist/layouts/electronics/pages/ProductsPage.js +2 -5
- package/dist/layouts/electronics-grid/components/ElectronicsGridProductCard.js +1 -1
- package/dist/layouts/electronics-grid/components/ElectronicsHomePageGrid.d.ts.map +1 -1
- package/dist/layouts/electronics-grid/components/ElectronicsHomePageGrid.js +4 -5
- package/dist/layouts/electronics-grid/pages/ProductDetailPage.d.ts.map +1 -1
- package/dist/layouts/electronics-grid/pages/ProductDetailPage.js +130 -223
- package/dist/layouts/electronics-grid/pages/ProductsPage.d.ts.map +1 -1
- package/dist/layouts/electronics-grid/pages/ProductsPage.js +2 -5
- package/dist/layouts/food/pages/MenuPage.js +1 -1
- package/dist/layouts/food/pages/ProductDetailPage.d.ts.map +1 -1
- package/dist/layouts/food/pages/ProductDetailPage.js +37 -140
- package/dist/layouts/food/pages/ProductsPage.d.ts.map +1 -1
- package/dist/layouts/food/pages/ProductsPage.js +2 -5
- package/dist/layouts/food-modern/pages/MenuPage.js +1 -1
- package/dist/layouts/food-modern/pages/ProductDetailPage.d.ts.map +1 -1
- package/dist/layouts/food-modern/pages/ProductDetailPage.js +130 -223
- package/dist/layouts/food-modern/pages/ProductsPage.d.ts.map +1 -1
- package/dist/layouts/food-modern/pages/ProductsPage.js +2 -5
- package/dist/layouts/motivational-speaker/pages/ProductsPage.d.ts.map +1 -1
- package/dist/layouts/motivational-speaker/pages/ProductsPage.js +2 -5
- package/dist/layouts/shared/components/PdpColorSwatch.d.ts +11 -0
- package/dist/layouts/shared/components/PdpColorSwatch.d.ts.map +1 -0
- package/dist/layouts/shared/components/PdpColorSwatch.js +29 -0
- package/dist/layouts/shared/components/PdpVariationSelectors.d.ts +13 -0
- package/dist/layouts/shared/components/PdpVariationSelectors.d.ts.map +1 -0
- package/dist/layouts/shared/components/PdpVariationSelectors.js +65 -0
- package/dist/layouts/shared/components/StoreCartSheet.d.ts +8 -0
- package/dist/layouts/shared/components/StoreCartSheet.d.ts.map +1 -0
- package/dist/layouts/shared/components/StoreCartSheet.js +16 -0
- package/dist/layouts/shared/components/StoreHeader.d.ts.map +1 -1
- package/dist/layouts/shared/components/StoreHeader.js +13 -12
- package/dist/layouts/shared/components/headers/ClothingMinimalHeader.d.ts.map +1 -1
- package/dist/layouts/shared/components/headers/ClothingMinimalHeader.js +5 -7
- package/dist/layouts/shared/pages/CartPage.d.ts.map +1 -1
- package/dist/layouts/shared/pages/CartPage.js +6 -5
- package/dist/layouts/shared/pages/CheckoutPage.d.ts.map +1 -1
- package/dist/layouts/shared/pages/CheckoutPage.js +209 -107
- package/dist/layouts/shared/product-category-filter-chip.d.ts +2 -0
- package/dist/layouts/shared/product-category-filter-chip.d.ts.map +1 -0
- package/dist/layouts/shared/product-category-filter-chip.js +6 -0
- package/dist/lib/pdp-cart-actions.d.ts +5 -0
- package/dist/lib/pdp-cart-actions.d.ts.map +1 -0
- package/dist/lib/pdp-cart-actions.js +19 -0
- package/dist/lib/product-variation-utils.d.ts +17 -0
- package/dist/lib/product-variation-utils.d.ts.map +1 -1
- package/dist/lib/product-variation-utils.js +193 -14
- package/dist/lib/services/checkout.service.d.ts +11 -0
- package/dist/lib/services/checkout.service.d.ts.map +1 -1
- package/dist/lib/services/shipping.service.d.ts +3 -0
- package/dist/lib/services/shipping.service.d.ts.map +1 -1
- package/dist/lib/store-config-utils.d.ts.map +1 -1
- package/dist/lib/store-config-utils.js +104 -11
- package/dist/lib/store-context.d.ts.map +1 -1
- package/dist/lib/store-context.js +23 -8
- package/dist/lib/utils/asset-helpers.d.ts +2 -0
- package/dist/lib/utils/asset-helpers.d.ts.map +1 -1
- package/dist/lib/utils/asset-helpers.js +24 -0
- package/dist/styles/index.css +143 -45
- package/package.json +8 -2
|
@@ -5,8 +5,8 @@ import { useProductReviews } from '../../../hooks/use-product-reviews.js';
|
|
|
5
5
|
import { Button } from '../../../components/ui/button.js';
|
|
6
6
|
import { Breadcrumbs } from '../../../components/ui/breadcrumbs.js';
|
|
7
7
|
import { Modal } from '../../../components/ui/modal.js';
|
|
8
|
-
import { ShoppingCart, Heart, Star, CheckCircle, ThumbsUp, User, Minus, Plus,
|
|
9
|
-
import { useState, useMemo, useEffect } from 'react';
|
|
8
|
+
import { ShoppingCart, Heart, Star, CheckCircle, ThumbsUp, User, Minus, Plus, Share2, Info } from 'lucide-react';
|
|
9
|
+
import { useState, useMemo, useEffect, useCallback } from 'react';
|
|
10
10
|
import { useStore } from '../../../lib/store-context.js';
|
|
11
11
|
import { useToast } from '../../../components/ui/toast.js';
|
|
12
12
|
import { useRouter } from 'next/navigation';
|
|
@@ -23,8 +23,12 @@ import { ButtonLoader } from '../../../components/ui/page-loader.js';
|
|
|
23
23
|
import { extractImageUrls } from '../../../lib/store-config-utils.js';
|
|
24
24
|
import { OutOfStockOverlay } from '../../../components/ui/out-of-stock-overlay.js';
|
|
25
25
|
import { cn, formatCurrency, filterActiveProducts, isEditorPreviewMode, resolvePdpProduct } from '../../../lib/utils/index.js';
|
|
26
|
+
import { usePdpVariation } from '../../../hooks/use-pdp-variation.js';
|
|
27
|
+
import { buildPdpBuyNowItem } from '../../../lib/pdp-cart-actions.js';
|
|
28
|
+
import { assertVariationSelected } from '../../../lib/product-variation-utils.js';
|
|
26
29
|
import { shippingService } from '../../../lib/services/shipping.service.js';
|
|
27
30
|
import { ProductDeliveryInfoSection } from '../../../components/shipping/ProductDeliveryInfoSection';
|
|
31
|
+
import { PdpVariationSelectors } from '../../shared/components/PdpVariationSelectors';
|
|
28
32
|
import { formatDateSafe } from '../../../utils/date';
|
|
29
33
|
// Helper function to format date
|
|
30
34
|
const formatDate = (dateString) => {
|
|
@@ -116,21 +120,11 @@ export function ProductDetailPage({ storeConfig: initialConfig, productSlug }) {
|
|
|
116
120
|
addToast('Failed to update wishlist', 'error');
|
|
117
121
|
}
|
|
118
122
|
};
|
|
119
|
-
|
|
120
|
-
const colorVariants = product?.variants?.filter(v => v.name === 'Color') || [];
|
|
121
|
-
const sizeVariants = product?.variants?.filter(v => v.name === 'Size') || [];
|
|
122
|
-
// Initialize state with defaults
|
|
123
|
+
const { optionGroups, selectedAttributes, setAttribute, isOptionAvailable, selectedVariation, galleryImages, displayPrice, displayCompareAt, displaySKU, isOutOfStock, getOptionImage, } = usePdpVariation(product);
|
|
123
124
|
const [selectedImage, setSelectedImage] = useState(0);
|
|
124
|
-
// Ensure selectedImage is within bounds when images change
|
|
125
125
|
useEffect(() => {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
const timer = setTimeout(() => setSelectedImage(0), 0);
|
|
129
|
-
return () => clearTimeout(timer);
|
|
130
|
-
}
|
|
131
|
-
}, [product, selectedImage]);
|
|
132
|
-
const [selectedColor, setSelectedColor] = useState(colorVariants.length > 0 ? colorVariants[0].value : null);
|
|
133
|
-
const [selectedSize, setSelectedSize] = useState(sizeVariants.length > 0 ? sizeVariants[0].value : null);
|
|
126
|
+
setSelectedImage(0);
|
|
127
|
+
}, [selectedVariation?.id, galleryImages.join('|')]);
|
|
134
128
|
const [quantity, setQuantity] = useState(1);
|
|
135
129
|
const [showAllReviews, setShowAllReviews] = useState(false);
|
|
136
130
|
const [isReviewModalOpen, setIsReviewModalOpen] = useState(false);
|
|
@@ -151,6 +145,102 @@ export function ProductDetailPage({ storeConfig: initialConfig, productSlug }) {
|
|
|
151
145
|
const [shippingError, setShippingError] = useState(null);
|
|
152
146
|
const [freeShippingEligible, setFreeShippingEligible] = useState(false);
|
|
153
147
|
const [freeShippingThreshold, setFreeShippingThreshold] = useState(undefined);
|
|
148
|
+
const calculateShipping = useCallback(async () => {
|
|
149
|
+
if (!product || !shippingAddress.country || !shippingAddress.city) {
|
|
150
|
+
setShippingError('Please provide country and city to calculate shipping');
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
setIsCalculatingShipping(true);
|
|
154
|
+
setShippingError(null);
|
|
155
|
+
try {
|
|
156
|
+
const currency = product.currency || storeConfig.settings?.currency || 'USD';
|
|
157
|
+
const subtotal = displayPrice * quantity;
|
|
158
|
+
const result = await shippingService.calculateShipping({
|
|
159
|
+
storeId: storeConfig.id,
|
|
160
|
+
address: {
|
|
161
|
+
country: shippingAddress.country,
|
|
162
|
+
city: shippingAddress.city,
|
|
163
|
+
zipCode: shippingAddress.zipCode,
|
|
164
|
+
},
|
|
165
|
+
items: [{ productId: product.id, quantity }],
|
|
166
|
+
subtotal,
|
|
167
|
+
currency,
|
|
168
|
+
});
|
|
169
|
+
setShippingMethods(result.methods || []);
|
|
170
|
+
setFreeShippingEligible(result.freeShippingEligible || false);
|
|
171
|
+
setFreeShippingThreshold(result.freeShippingThreshold);
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
console.error('Shipping calculation error:', error);
|
|
175
|
+
setShippingError(error instanceof Error ? error.message : 'Failed to calculate shipping. Please try again.');
|
|
176
|
+
setShippingMethods([]);
|
|
177
|
+
}
|
|
178
|
+
finally {
|
|
179
|
+
setIsCalculatingShipping(false);
|
|
180
|
+
}
|
|
181
|
+
}, [
|
|
182
|
+
product,
|
|
183
|
+
shippingAddress.country,
|
|
184
|
+
shippingAddress.city,
|
|
185
|
+
shippingAddress.zipCode,
|
|
186
|
+
quantity,
|
|
187
|
+
displayPrice,
|
|
188
|
+
storeConfig.id,
|
|
189
|
+
storeConfig.settings?.currency,
|
|
190
|
+
]);
|
|
191
|
+
useEffect(() => {
|
|
192
|
+
const loadAddresses = async () => {
|
|
193
|
+
if (isAuthenticated) {
|
|
194
|
+
try {
|
|
195
|
+
const addresses = await customerService.getAddresses();
|
|
196
|
+
setSavedAddresses(addresses);
|
|
197
|
+
if (addresses.length > 0) {
|
|
198
|
+
const defaultAddress = addresses.find((a) => a.isDefault) || addresses[0];
|
|
199
|
+
if (defaultAddress) {
|
|
200
|
+
setShippingAddress({
|
|
201
|
+
country: defaultAddress.country || '',
|
|
202
|
+
city: defaultAddress.city || '',
|
|
203
|
+
zipCode: defaultAddress.zipCode || '',
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
console.error('Failed to load addresses:', error);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
loadAddresses();
|
|
214
|
+
}, [isAuthenticated]);
|
|
215
|
+
useEffect(() => {
|
|
216
|
+
if (!shippingAddress.country || !shippingAddress.city || !product)
|
|
217
|
+
return;
|
|
218
|
+
const timer = setTimeout(() => {
|
|
219
|
+
calculateShipping();
|
|
220
|
+
}, 500);
|
|
221
|
+
return () => clearTimeout(timer);
|
|
222
|
+
}, [
|
|
223
|
+
shippingAddress.country,
|
|
224
|
+
shippingAddress.city,
|
|
225
|
+
shippingAddress.zipCode,
|
|
226
|
+
quantity,
|
|
227
|
+
product?.id,
|
|
228
|
+
displayPrice,
|
|
229
|
+
calculateShipping,
|
|
230
|
+
]);
|
|
231
|
+
useEffect(() => {
|
|
232
|
+
if (product && storeConfig?.id) {
|
|
233
|
+
trackEvent({
|
|
234
|
+
eventType: 'product_view',
|
|
235
|
+
metadata: {
|
|
236
|
+
productId: product.id,
|
|
237
|
+
productName: product.name,
|
|
238
|
+
categoryId: product.categoryId,
|
|
239
|
+
price: displayPrice,
|
|
240
|
+
},
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
}, [product?.id, storeConfig?.id, displayPrice, trackEvent]);
|
|
154
244
|
const handleSubmitReview = async (e) => {
|
|
155
245
|
e.preventDefault();
|
|
156
246
|
if (!product?.id)
|
|
@@ -189,8 +279,6 @@ export function ProductDetailPage({ storeConfig: initialConfig, productSlug }) {
|
|
|
189
279
|
if (!product) {
|
|
190
280
|
return (_jsx("div", { className: "min-h-screen bg-white flex items-center justify-center p-8", children: _jsxs("div", { className: "text-center", children: [_jsx("h1", { className: "text-2xl font-bold mb-2", children: "Product Not Found" }), _jsx("p", { className: "text-gray-600 mb-4", children: "The product you're looking for doesn't exist." })] }) }));
|
|
191
281
|
}
|
|
192
|
-
// Use SKU for display, fallback to generated SKU from slug if not available
|
|
193
|
-
const displaySKU = product.sku || product.slug?.toUpperCase().replace(/-/g, '').substring(0, 12).padEnd(8, 'X') || 'N/A';
|
|
194
282
|
// Build category breadcrumb path with all parent categories
|
|
195
283
|
const buildCategoryPath = (categoryId) => {
|
|
196
284
|
if (!categoryId)
|
|
@@ -224,42 +312,7 @@ export function ProductDetailPage({ storeConfig: initialConfig, productSlug }) {
|
|
|
224
312
|
// Extract product images - product.images should already be string[] from transformation,
|
|
225
313
|
// but handle edge cases where it might still be in object format
|
|
226
314
|
// Use the comprehensive extraction utility from store-config-utils for consistency
|
|
227
|
-
const productImages = (
|
|
228
|
-
// Debug: Log the raw product.images to understand its format
|
|
229
|
-
if (process.env.NODE_ENV === 'development') {
|
|
230
|
-
console.log('[ProductDetailPage] Raw product.images:', {
|
|
231
|
-
productId: product.id,
|
|
232
|
-
productName: product.name,
|
|
233
|
-
images: product.images,
|
|
234
|
-
imagesType: typeof product.images,
|
|
235
|
-
imagesIsArray: Array.isArray(product.images),
|
|
236
|
-
imagesLength: Array.isArray(product.images) ? product.images.length : 'N/A',
|
|
237
|
-
firstItem: Array.isArray(product.images) && product.images.length > 0 ? product.images[0] : 'N/A',
|
|
238
|
-
firstItemType: Array.isArray(product.images) && product.images.length > 0 ? typeof product.images[0] : 'N/A'
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
// If already an array of strings (normal case after transformation)
|
|
242
|
-
if (Array.isArray(product.images) && product.images.length > 0) {
|
|
243
|
-
const firstItem = product.images[0];
|
|
244
|
-
if (typeof firstItem === 'string') {
|
|
245
|
-
const filtered = product.images.filter((img) => typeof img === 'string' && img.trim().length > 0);
|
|
246
|
-
if (process.env.NODE_ENV === 'development') {
|
|
247
|
-
console.log('[ProductDetailPage] Using string array directly:', { count: filtered.length, firstImage: filtered[0]?.substring(0, 100) });
|
|
248
|
-
}
|
|
249
|
-
return filtered;
|
|
250
|
-
}
|
|
251
|
-
// If array but not strings, extract using utility
|
|
252
|
-
if (process.env.NODE_ENV === 'development') {
|
|
253
|
-
console.log('[ProductDetailPage] Array but not strings, using extractImageUrls');
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
// Use the comprehensive extraction utility for any other format (objects, nested structures, etc.)
|
|
257
|
-
const extracted = extractImageUrls(product.images);
|
|
258
|
-
if (process.env.NODE_ENV === 'development') {
|
|
259
|
-
console.log('[ProductDetailPage] Extracted using utility:', { count: extracted.length, firstImage: extracted[0]?.substring(0, 100) });
|
|
260
|
-
}
|
|
261
|
-
return extracted;
|
|
262
|
-
})();
|
|
315
|
+
const productImages = galleryImages.length > 0 ? galleryImages : extractImageUrls(product.images);
|
|
263
316
|
// For gallery, use actual images only (don't duplicate to fill 5 slots)
|
|
264
317
|
const displayImages = productImages.slice(0, 5);
|
|
265
318
|
const hasMoreImages = productImages.length > 5;
|
|
@@ -284,20 +337,6 @@ export function ProductDetailPage({ storeConfig: initialConfig, productSlug }) {
|
|
|
284
337
|
});
|
|
285
338
|
}
|
|
286
339
|
}
|
|
287
|
-
// Color swatch mapping
|
|
288
|
-
const colorSwatches = {
|
|
289
|
-
'White': '#FFFFFF',
|
|
290
|
-
'Black': '#000000',
|
|
291
|
-
'Gray': '#808080',
|
|
292
|
-
'Grey': '#808080',
|
|
293
|
-
'Blue': '#3B82F6',
|
|
294
|
-
'Red': '#EF4444',
|
|
295
|
-
'Green': '#10B981',
|
|
296
|
-
'Yellow': '#FBBF24',
|
|
297
|
-
'Brown': '#92400E',
|
|
298
|
-
'Navy': '#1E3A8A',
|
|
299
|
-
'Beige': '#F5F5DC',
|
|
300
|
-
};
|
|
301
340
|
// Reviews loaded from API (product payload does not include review rows)
|
|
302
341
|
const displayedReviews = showAllReviews ? reviews : reviews.slice(0, 3);
|
|
303
342
|
const hasMoreReviews = reviews.length > 3;
|
|
@@ -306,7 +345,6 @@ export function ProductDetailPage({ storeConfig: initialConfig, productSlug }) {
|
|
|
306
345
|
? reviews.reduce((sum, review) => sum + review.rating, 0) / reviews.length
|
|
307
346
|
: Number(product.rating) || 0;
|
|
308
347
|
// Out of stock check
|
|
309
|
-
const isOutOfStock = !product.inStock;
|
|
310
348
|
// Calculate rating distribution
|
|
311
349
|
const ratingDistribution = [5, 4, 3, 2, 1].map(rating => {
|
|
312
350
|
const count = reviews.filter(r => Math.round(r.rating) === rating).length;
|
|
@@ -316,29 +354,19 @@ export function ProductDetailPage({ storeConfig: initialConfig, productSlug }) {
|
|
|
316
354
|
percentage: reviews.length > 0 ? (count / reviews.length) * 100 : 0,
|
|
317
355
|
};
|
|
318
356
|
});
|
|
319
|
-
const handleAddToCart = () => {
|
|
357
|
+
const handleAddToCart = async () => {
|
|
320
358
|
if (isOutOfStock) {
|
|
321
359
|
addToast('This product is currently out of stock', 'error');
|
|
322
360
|
return;
|
|
323
361
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
const sizeMatch = !selectedSize || attrs.size === selectedSize;
|
|
332
|
-
return colorMatch && sizeMatch;
|
|
333
|
-
});
|
|
334
|
-
variationId = matchingVariation?.id;
|
|
362
|
+
try {
|
|
363
|
+
assertVariationSelected(product, selectedVariation, selectedAttributes);
|
|
364
|
+
await addToCart(product, quantity, selectedVariation?.id);
|
|
365
|
+
addToast(`${product.name} added to cart`, 'success');
|
|
366
|
+
}
|
|
367
|
+
catch (error) {
|
|
368
|
+
addToast(error instanceof Error ? error.message : 'Could not add to cart', 'error');
|
|
335
369
|
}
|
|
336
|
-
// Fallback to composite string for backward compatibility if no variation found
|
|
337
|
-
const variantId = variationId || (selectedColor || selectedSize
|
|
338
|
-
? [selectedColor, selectedSize].filter(Boolean).join(' / ')
|
|
339
|
-
: undefined);
|
|
340
|
-
addToCart(product, quantity, variantId);
|
|
341
|
-
addToast(`${product.name} added to cart`, 'success');
|
|
342
370
|
};
|
|
343
371
|
const handleBuyNow = async () => {
|
|
344
372
|
if (isOutOfStock) {
|
|
@@ -350,43 +378,14 @@ export function ProductDetailPage({ storeConfig: initialConfig, productSlug }) {
|
|
|
350
378
|
}
|
|
351
379
|
setIsBuyNowLoading(true);
|
|
352
380
|
try {
|
|
353
|
-
|
|
354
|
-
// Note: StoreProduct uses 'variants' not 'variations'
|
|
355
|
-
let variationId;
|
|
356
|
-
let variantName;
|
|
357
|
-
if (product.variants && Array.isArray(product.variants) && product.variants.length > 0) {
|
|
358
|
-
const matchingVariation = product.variants.find((variation) => {
|
|
359
|
-
const attrs = variation.attributes || {};
|
|
360
|
-
const colorMatch = !selectedColor || attrs.color === selectedColor;
|
|
361
|
-
const sizeMatch = !selectedSize || attrs.size === selectedSize;
|
|
362
|
-
return colorMatch && sizeMatch;
|
|
363
|
-
});
|
|
364
|
-
variationId = matchingVariation?.id;
|
|
365
|
-
variantName = matchingVariation?.name || matchingVariation?.value;
|
|
366
|
-
}
|
|
367
|
-
// Fallback to composite string for backward compatibility if no variation found
|
|
368
|
-
const variantId = variationId || (selectedColor || selectedSize
|
|
369
|
-
? [selectedColor, selectedSize].filter(Boolean).join(' / ')
|
|
370
|
-
: undefined);
|
|
371
|
-
// Create buy now item (don't add to cart)
|
|
372
|
-
const buyNowItemId = variantId ? `${product.id}-${variantId}` : product.id;
|
|
373
|
-
const buyNowItem = {
|
|
374
|
-
id: buyNowItemId,
|
|
375
|
-
productId: product.id,
|
|
376
|
-
quantity,
|
|
377
|
-
variantId,
|
|
378
|
-
variantName: variantName || variantId,
|
|
379
|
-
price: product.price,
|
|
380
|
-
product
|
|
381
|
-
};
|
|
382
|
-
// Set buy now item and navigate directly to checkout
|
|
381
|
+
const buyNowItem = buildPdpBuyNowItem(product, quantity, selectedVariation, displayPrice, selectedAttributes);
|
|
383
382
|
setBuyNowItem(buyNowItem);
|
|
384
383
|
// Navigate to checkout page for direct checkout
|
|
385
384
|
router.push(`/${storeConfig.slug}/checkout`);
|
|
386
385
|
}
|
|
387
386
|
catch (error) {
|
|
388
387
|
console.error('Buy Now error:', error);
|
|
389
|
-
addToast('Failed to proceed to checkout. Please try again.', 'error');
|
|
388
|
+
addToast(error instanceof Error ? error.message : 'Failed to proceed to checkout. Please try again.', 'error');
|
|
390
389
|
}
|
|
391
390
|
finally {
|
|
392
391
|
setIsBuyNowLoading(false);
|
|
@@ -399,113 +398,21 @@ export function ProductDetailPage({ storeConfig: initialConfig, productSlug }) {
|
|
|
399
398
|
// Note: This is now only used for other flows, not buy now
|
|
400
399
|
// Buy now now redirects to checkout page
|
|
401
400
|
};
|
|
402
|
-
// Calculate shipping when address is provided
|
|
403
|
-
const calculateShipping = async () => {
|
|
404
|
-
if (!product || !shippingAddress.country || !shippingAddress.city) {
|
|
405
|
-
setShippingError('Please provide country and city to calculate shipping');
|
|
406
|
-
return;
|
|
407
|
-
}
|
|
408
|
-
setIsCalculatingShipping(true);
|
|
409
|
-
setShippingError(null);
|
|
410
|
-
try {
|
|
411
|
-
const currency = product.currency || storeConfig.settings?.currency || 'USD';
|
|
412
|
-
const subtotal = product.price * quantity;
|
|
413
|
-
const result = await shippingService.calculateShipping({
|
|
414
|
-
storeId: storeConfig.id,
|
|
415
|
-
address: {
|
|
416
|
-
country: shippingAddress.country,
|
|
417
|
-
city: shippingAddress.city,
|
|
418
|
-
zipCode: shippingAddress.zipCode,
|
|
419
|
-
},
|
|
420
|
-
items: [{
|
|
421
|
-
productId: product.id,
|
|
422
|
-
quantity: quantity,
|
|
423
|
-
}],
|
|
424
|
-
subtotal: subtotal,
|
|
425
|
-
currency: currency,
|
|
426
|
-
});
|
|
427
|
-
setShippingMethods(result.methods || []);
|
|
428
|
-
setFreeShippingEligible(result.freeShippingEligible || false);
|
|
429
|
-
setFreeShippingThreshold(result.freeShippingThreshold);
|
|
430
|
-
}
|
|
431
|
-
catch (error) {
|
|
432
|
-
console.error('Shipping calculation error:', error);
|
|
433
|
-
setShippingError(error.message || 'Failed to calculate shipping. Please try again.');
|
|
434
|
-
setShippingMethods([]);
|
|
435
|
-
}
|
|
436
|
-
finally {
|
|
437
|
-
setIsCalculatingShipping(false);
|
|
438
|
-
}
|
|
439
|
-
};
|
|
440
|
-
// Load saved addresses for authenticated users and auto-populate shipping address
|
|
441
|
-
useEffect(() => {
|
|
442
|
-
const loadAddresses = async () => {
|
|
443
|
-
if (isAuthenticated) {
|
|
444
|
-
try {
|
|
445
|
-
const addresses = await customerService.getAddresses();
|
|
446
|
-
setSavedAddresses(addresses);
|
|
447
|
-
// Auto-populate with default address or first address if available
|
|
448
|
-
if (addresses.length > 0) {
|
|
449
|
-
const defaultAddress = addresses.find(a => a.isDefault) || addresses[0];
|
|
450
|
-
if (defaultAddress) {
|
|
451
|
-
setShippingAddress({
|
|
452
|
-
country: defaultAddress.country || '',
|
|
453
|
-
city: defaultAddress.city || '',
|
|
454
|
-
zipCode: defaultAddress.zipCode || '',
|
|
455
|
-
});
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
catch (error) {
|
|
460
|
-
console.error('Failed to load addresses:', error);
|
|
461
|
-
// Don't show error toast - addresses are optional
|
|
462
|
-
// Users can still manually enter shipping address
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
};
|
|
466
|
-
loadAddresses();
|
|
467
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
468
|
-
}, [isAuthenticated]);
|
|
469
|
-
// Auto-calculate shipping when address fields are filled (debounced)
|
|
470
|
-
useEffect(() => {
|
|
471
|
-
if (!shippingAddress.country || !shippingAddress.city || !product) {
|
|
472
|
-
return;
|
|
473
|
-
}
|
|
474
|
-
const timer = setTimeout(() => {
|
|
475
|
-
calculateShipping();
|
|
476
|
-
}, 500); // Debounce 500ms
|
|
477
|
-
return () => clearTimeout(timer);
|
|
478
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
479
|
-
}, [shippingAddress.country, shippingAddress.city, shippingAddress.zipCode, quantity, product?.id, product?.price]);
|
|
480
|
-
// Track product view
|
|
481
|
-
useEffect(() => {
|
|
482
|
-
if (product && storeConfig?.id) {
|
|
483
|
-
trackEvent({
|
|
484
|
-
eventType: 'product_view',
|
|
485
|
-
metadata: {
|
|
486
|
-
productId: product.id,
|
|
487
|
-
productName: product.name,
|
|
488
|
-
categoryId: product.categoryId,
|
|
489
|
-
price: product.price,
|
|
490
|
-
},
|
|
491
|
-
});
|
|
492
|
-
}
|
|
493
|
-
}, [product?.id, storeConfig?.id, trackEvent]);
|
|
494
401
|
return (_jsxs("div", { className: "min-h-screen bg-white", children: [_jsxs("div", { "data-content-ready": true, className: "container mx-auto px-4 sm:px-6 lg:px-8 py-8 lg:py-12 max-w-7xl", children: [_jsx("div", { className: "mb-6", children: _jsx(Breadcrumbs, { items: breadcrumbItems }) }), _jsxs("div", { className: "grid grid-cols-1 lg:grid-cols-2 gap-8 lg:gap-16 mb-20", children: [_jsxs("div", { className: "relative lg:sticky lg:top-24 self-start z-0", children: [_jsxs("div", { className: "relative aspect-square bg-gray-50 rounded-xl overflow-hidden mb-4 border border-gray-100 shadow-sm group", children: [_jsx(ImageWithFallback, { "data-product-image": true, src: displayImages[selectedImage] || displayImages[0] || productImages[0], alt: product.name, className: cn("w-full h-full object-cover transition-transform duration-300 group-hover:scale-105", isOutOfStock && "grayscale"), skeletonAspectRatio: "square" }), isOutOfStock && (_jsx(OutOfStockOverlay, { badgePosition: "center" }))] }), displayImages.length > 0 && (_jsxs("div", { className: "grid grid-cols-5 gap-2", children: [displayImages.map((image, index) => (_jsx("button", { onClick: () => setSelectedImage(Math.min(index, displayImages.length - 1)), className: `aspect-square rounded-lg overflow-hidden border-2 transition-all ${selectedImage === index
|
|
495
402
|
? 'border-gray-900 ring-2 ring-gray-900 ring-offset-2'
|
|
496
|
-
: 'border-gray-200 hover:border-gray-300'}`, children: _jsx(ImageWithFallback, { src: image, alt: `${product.name} view ${index + 1}`, className: cn("w-full h-full object-cover", isOutOfStock && "grayscale"), skeletonAspectRatio: "square" }) }, index))), hasMoreImages && (_jsxs("div", { className: "aspect-square rounded-lg border-2 border-gray-200 bg-gray-50 flex items-center justify-center text-xs text-gray-500 font-medium", children: ["+", productImages.length - 5, " more"] }))] }))] }), _jsxs("div", { className: "flex flex-col", children: [_jsxs("div", { className: "flex items-center justify-between mb-2", children: [_jsx("span", { className: "text-sm font-semibold text-gray-700 uppercase tracking-wide", children: directCategory?.name || storeConfig.name }), _jsx("button", { onClick: handleShare, className: "text-gray-400 hover:text-gray-900 transition-colors p-2 rounded-full hover:bg-gray-100", title: "Share this product", children: _jsx(Share2, { className: "h-5 w-5" }) })] }), _jsx("h1", { "data-product-name": true, className: "text-3xl sm:text-4xl lg:text-5xl font-bold text-gray-900 mb-3 leading-tight tracking-tight", children: product.name }), _jsxs("p", { className: "text-sm text-gray-500 mb-6 font-mono", children: ["SKU: ", displaySKU] }), _jsx("div", { className: "mb-4 flex items-center gap-2", children:
|
|
497
|
-
const colorValue = variant.value;
|
|
498
|
-
const swatchColor = colorSwatches[colorValue] || '#CCCCCC';
|
|
499
|
-
const isSelected = selectedColor === colorValue;
|
|
500
|
-
return (_jsx("button", { onClick: () => setSelectedColor(colorValue), className: `relative w-12 h-12 rounded-full border-2 transition-all ${isSelected
|
|
501
|
-
? 'border-gray-900 ring-2 ring-gray-900 ring-offset-2 scale-105'
|
|
502
|
-
: 'border-gray-200 hover:border-gray-300'}`, style: { backgroundColor: swatchColor }, title: colorValue, children: isSelected && (_jsx("div", { className: "absolute inset-0 flex items-center justify-center", children: _jsx(CheckCircle, { className: `h-5 w-5 ${['White', 'Beige', 'Yellow'].includes(colorValue) ? 'text-gray-900' : 'text-white'} drop-shadow-sm` }) })) }, variant.id));
|
|
503
|
-
}) })] })), sizeVariants.length > 0 && (_jsxs("div", { className: "mb-8", children: [_jsxs("div", { className: "flex items-center justify-between mb-4", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("span", { className: "text-sm font-semibold text-gray-900", children: "Size:" }), _jsx("span", { className: "text-sm text-gray-600", children: selectedSize || 'Select Size' })] }), _jsxs("a", { href: `/${storeConfig.slug}/size-guide`, target: "_blank", rel: "noopener noreferrer", className: "flex items-center gap-1.5 text-xs font-medium text-gray-600 hover:text-gray-900 underline decoration-gray-400 underline-offset-4", children: [_jsx(Ruler, { className: "h-3.5 w-3.5" }), " Size guide"] })] }), _jsx("div", { className: "grid grid-cols-4 sm:grid-cols-5 gap-2.5", children: sizeVariants.map((variant) => {
|
|
504
|
-
const isSelected = selectedSize === variant.value;
|
|
505
|
-
return (_jsx("button", { onClick: () => setSelectedSize(variant.value), className: `px-4 py-3 rounded-lg border-2 text-sm font-semibold transition-all ${isSelected
|
|
506
|
-
? 'bg-gray-900 text-white border-gray-900 shadow-md transform -translate-y-0.5'
|
|
507
|
-
: 'bg-white text-gray-700 border-gray-200 hover:border-gray-300 hover:bg-gray-50'}`, children: variant.value }, variant.id));
|
|
508
|
-
}) })] })), _jsxs("div", { className: "flex flex-col gap-4 mb-8", children: [_jsxs("div", { className: "flex items-center gap-3", children: [_jsx("span", { className: "text-sm font-semibold text-gray-900", children: "Quantity" }), _jsxs("div", { className: "flex items-center border border-gray-300 rounded-lg", children: [_jsx("button", { className: "p-3 text-gray-600 hover:bg-gray-100 rounded-l-lg disabled:opacity-50", onClick: () => setQuantity(Math.max(1, quantity - 1)), disabled: quantity <= 1, children: _jsx(Minus, { className: "h-4 w-4" }) }), _jsx("span", { className: "w-12 text-center font-semibold text-gray-900", children: quantity }), _jsx("button", { className: "p-3 text-gray-600 hover:bg-gray-100 rounded-r-lg", onClick: () => setQuantity(quantity + 1), children: _jsx(Plus, { className: "h-4 w-4" }) })] })] }), _jsxs("div", { className: "flex flex-col sm:flex-row gap-3 mt-2", children: [_jsx(Button, { "data-add-to-cart": true, size: "lg", onClick: handleAddToCart, disabled: isCartLoading || isOutOfStock, className: "flex-1 bg-white border-2 border-gray-900 text-gray-900 hover:bg-gray-50 rounded-full h-14 text-base font-bold shadow-sm transition-all disabled:opacity-50 disabled:cursor-not-allowed", children: isCartLoading ? (_jsxs(_Fragment, { children: [_jsx(ButtonLoader, { className: "mr-2" }), "Adding..."] })) : (_jsxs(_Fragment, { children: [_jsx(ShoppingCart, { className: "h-5 w-5 mr-2" }), "Add to Cart"] })) }), _jsx(Button, { size: "lg", onClick: handleBuyNow, disabled: isOutOfStock || isBuyNowLoading || isCartLoading, className: "flex-1 bg-gray-900 hover:bg-gray-800 text-white rounded-full h-14 text-base font-bold shadow-lg hover:shadow-xl transition-all disabled:opacity-50 disabled:cursor-not-allowed", children: isBuyNowLoading || isCartLoading ? (_jsxs(_Fragment, { children: [_jsx(ButtonLoader, { className: "mr-2" }), "Adding..."] })) : ('Buy Now') }), storeConfig.features.wishlist && (_jsx(Button, { variant: "outline", size: "lg", onClick: handleWishlistClick, disabled: isWishlistLoading || !product, className: cn("h-14 w-14 rounded-full border-2 transition-all disabled:opacity-50 disabled:cursor-not-allowed", product && isInWishlist(product.id)
|
|
403
|
+
: 'border-gray-200 hover:border-gray-300'}`, children: _jsx(ImageWithFallback, { src: image, alt: `${product.name} view ${index + 1}`, className: cn("w-full h-full object-cover", isOutOfStock && "grayscale"), skeletonAspectRatio: "square" }) }, index))), hasMoreImages && (_jsxs("div", { className: "aspect-square rounded-lg border-2 border-gray-200 bg-gray-50 flex items-center justify-center text-xs text-gray-500 font-medium", children: ["+", productImages.length - 5, " more"] }))] }))] }), _jsxs("div", { className: "flex flex-col", children: [_jsxs("div", { className: "flex items-center justify-between mb-2", children: [_jsx("span", { className: "text-sm font-semibold text-gray-700 uppercase tracking-wide", children: directCategory?.name || storeConfig.name }), _jsx("button", { onClick: handleShare, className: "text-gray-400 hover:text-gray-900 transition-colors p-2 rounded-full hover:bg-gray-100", title: "Share this product", children: _jsx(Share2, { className: "h-5 w-5" }) })] }), _jsx("h1", { "data-product-name": true, className: "text-3xl sm:text-4xl lg:text-5xl font-bold text-gray-900 mb-3 leading-tight tracking-tight", children: product.name }), _jsxs("p", { className: "text-sm text-gray-500 mb-6 font-mono", children: ["SKU: ", displaySKU] }), _jsx("div", { className: "mb-4 flex items-center gap-2", children: !isOutOfStock ? (_jsxs("span", { className: "inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-green-100 text-green-800", children: [_jsx(CheckCircle, { className: "w-3 h-3 mr-1" }), "In Stock"] })) : (_jsxs("span", { className: "inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-red-100 text-red-800", children: [_jsx(Info, { className: "w-3 h-3 mr-1" }), "Out of Stock"] })) }), _jsxs("div", { className: "mb-8", children: [_jsxs("div", { className: "flex items-baseline gap-4", children: [_jsx("span", { "data-product-price": true, className: "text-4xl lg:text-5xl font-bold text-gray-900", children: formatCurrency(displayPrice, product.currency || 'USD') }), displayCompareAt != null && displayCompareAt > displayPrice && (_jsx("span", { className: "text-2xl text-gray-500 line-through", children: formatCurrency(displayCompareAt, product.currency || 'USD') }))] }), displayCompareAt != null && displayCompareAt > displayPrice && (_jsxs("span", { className: "inline-block mt-2 bg-red-100 text-red-700 text-xs font-bold px-2 py-1 rounded", children: ["SAVE ", Math.round(((displayCompareAt - displayPrice) / displayCompareAt) * 100), "%"] }))] }), _jsx(PdpVariationSelectors, { optionGroups: optionGroups, selectedAttributes: selectedAttributes, setAttribute: setAttribute, isOptionAvailable: isOptionAvailable, getOptionImage: getOptionImage, storeSlug: storeConfig.slug, showSizeGuide: productDetailConfig?.showSizeGuide !== false, onAfterClearAttribute: () => setQuantity(1) }), _jsxs("div", { className: "flex flex-col gap-4 mb-8", children: [_jsxs("div", { className: "flex items-center gap-3", children: [_jsx("span", { className: "text-sm font-semibold text-gray-900", children: "Quantity" }), _jsxs("div", { className: "flex items-center border border-gray-300 rounded-lg", children: [_jsx("button", { className: "p-3 text-gray-600 hover:bg-gray-100 rounded-l-lg disabled:opacity-50", onClick: () => setQuantity(Math.max(1, quantity - 1)), disabled: quantity <= 1, children: _jsx(Minus, { className: "h-4 w-4" }) }), _jsx("span", { className: "w-12 text-center font-semibold text-gray-900", children: quantity }), _jsx("button", { className: "p-3 text-gray-600 hover:bg-gray-100 rounded-r-lg", onClick: () => setQuantity(quantity + 1), children: _jsx(Plus, { className: "h-4 w-4" }) })] })] }), _jsxs("div", { className: "flex flex-row items-stretch gap-2 sm:gap-3 mt-2 w-full", children: [_jsx(Button, { "data-add-to-cart": true, variant: "outline", size: "lg", onClick: handleAddToCart, disabled: isCartLoading || isOutOfStock, className: "flex-1 min-w-0 bg-white border-2 border-gray-900 text-gray-900 hover:bg-gray-50 rounded-full h-12 sm:h-14 px-3 sm:px-6 text-sm sm:text-base font-bold [&_svg]:text-gray-900 shadow-sm transition-all disabled:opacity-50 disabled:cursor-not-allowed", children: isCartLoading ? (_jsxs(_Fragment, { children: [_jsx(ButtonLoader, { className: "mr-1.5 sm:mr-2" }), "Adding..."] })) : (_jsxs(_Fragment, { children: [_jsx(ShoppingCart, { className: "h-4 w-4 sm:h-5 sm:w-5 mr-1.5 sm:mr-2 shrink-0 text-gray-900" }), "Add to Cart"] })) }), _jsx(Button, { size: "lg", onClick: handleBuyNow, disabled: isOutOfStock || isBuyNowLoading || isCartLoading, className: "flex-1 min-w-0 bg-gray-900 hover:bg-gray-800 text-white rounded-full h-12 sm:h-14 px-3 sm:px-6 text-sm sm:text-base font-bold shadow-lg hover:shadow-xl transition-all disabled:opacity-50 disabled:cursor-not-allowed", children: isBuyNowLoading || isCartLoading ? (_jsxs(_Fragment, { children: [_jsx(ButtonLoader, { className: "mr-1.5 sm:mr-2" }), "Adding..."] })) : ('Buy Now') }), storeConfig.features.wishlist && (_jsx(Button, { variant: "outline", size: "lg", onClick: handleWishlistClick, disabled: isWishlistLoading || !product, className: cn("h-12 w-12 sm:h-14 sm:w-14 shrink-0 rounded-full border-2 transition-all disabled:opacity-50 disabled:cursor-not-allowed", product && isInWishlist(product.id)
|
|
509
404
|
? "border-red-500 bg-red-50 text-red-500 hover:bg-red-100"
|
|
510
|
-
: "border-gray-200 hover:border-gray-300 hover:bg-gray-50"), children: isWishlistLoading ? (_jsx(ButtonLoader, { className: "h-5 w-5" })) : (_jsx(Heart, { className: cn("h-5 w-5", product && isInWishlist(product.id) && "fill-current") })) }))] })] }), _jsx(ProductDeliveryInfoSection, { storeConfig: storeConfig, currency: storeConfig.settings?.currency || 'USD', productCurrency: product.currency, productPrice:
|
|
405
|
+
: "border-gray-200 hover:border-gray-300 hover:bg-gray-50"), children: isWishlistLoading ? (_jsx(ButtonLoader, { className: "h-5 w-5" })) : (_jsx(Heart, { className: cn("h-5 w-5", product && isInWishlist(product.id) && "fill-current") })) }))] })] }), _jsx(ProductDeliveryInfoSection, { storeConfig: storeConfig, currency: storeConfig.settings?.currency || 'USD', productCurrency: product.currency, productPrice: displayPrice, quantity: quantity, shippingAddress: shippingAddress, updateShippingAddress: (patch) => setShippingAddress((prev) => ({ ...prev, ...patch })), shippingMethods: shippingMethods, isCalculatingShipping: isCalculatingShipping, shippingError: shippingError, freeShippingEligible: freeShippingEligible, freeShippingThreshold: freeShippingThreshold, onToast: addToast }), product.description && (_jsxs("div", { className: "mb-8", children: [_jsx("h2", { className: "text-lg font-semibold text-gray-900 mb-3", children: "Description" }), _jsxs("div", { className: "prose prose-sm max-w-none text-gray-600 leading-relaxed", children: [_jsx(SafeRichHtml, { value: product.description, fallbackPlain: "", as: "div" }), _jsxs("ul", { className: "list-disc pl-5 space-y-1 mt-2", children: [_jsx("li", { children: "Premium quality material" }), _jsx("li", { children: "Comfortable fit for all-day wear" }), _jsx("li", { children: "Durable stitching and finish" })] })] })] })), product.specifications && Object.keys(product.specifications).length > 0 && (_jsxs("div", { className: "mb-8", children: [_jsx("h2", { className: "text-lg font-semibold text-gray-900 mb-4", children: "Specifications" }), _jsx("dl", { className: "grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-4", children: Object.entries(product.specifications).map(([key, value]) => (_jsxs("div", { className: "flex flex-col p-3 bg-gray-50 rounded-lg", children: [_jsx("dt", { className: "text-xs text-gray-500 font-medium uppercase tracking-wider mb-1", children: key }), _jsx("dd", { className: "text-sm font-bold text-gray-900", children: value })] }, key))) })] }))] })] }), _jsx("div", { className: "mt-20 pt-16 border-t border-gray-200", children: _jsxs("div", { className: "max-w-4xl", children: [_jsxs("div", { className: "flex flex-col sm:flex-row items-start sm:items-center justify-between gap-6 mb-10", children: [_jsxs("div", { className: "flex-1", children: [_jsx("h2", { className: "text-2xl lg:text-3xl font-bold text-gray-900 mb-4", children: "Customer Reviews" }), reviewCount > 0 && averageRating > 0 && (_jsxs("div", { className: "flex items-center gap-4", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(StarRating, { rating: averageRating, size: "lg" }), _jsx("span", { className: "text-2xl font-bold text-gray-900", children: averageRating.toFixed(1) }), _jsx("span", { className: "text-lg text-gray-500", children: "out of 5" })] }), _jsx("span", { className: "text-gray-300", children: "|" }), _jsxs("span", { className: "text-lg text-gray-600", children: [reviewCount, " ", reviewCount === 1 ? 'review' : 'reviews'] })] }))] }), reviewCount > 0 && (_jsx(Button, { onClick: () => {
|
|
406
|
+
if (!isAuthenticated) {
|
|
407
|
+
openLogin({ onSuccess: () => setIsReviewModalOpen(true) });
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
setIsReviewModalOpen(true);
|
|
411
|
+
}, className: "rounded-full shrink-0 bg-gray-900 hover:bg-gray-800 text-white", children: "Write a Review" }))] }), ratingDistribution.some(r => r.count > 0) && (_jsxs("div", { className: "mb-10 p-6 bg-gray-50 rounded-xl border border-gray-100", children: [_jsx("h3", { className: "text-sm font-semibold text-gray-900 mb-5", children: "Rating Breakdown" }), _jsx("div", { className: "space-y-3", children: ratingDistribution.map(({ rating, count, percentage }) => (_jsxs("div", { className: "flex items-center gap-4", children: [_jsxs("div", { className: "flex items-center gap-1.5 w-20", children: [_jsx("span", { className: "text-sm font-semibold text-gray-900", children: rating }), _jsx(Star, { className: "h-4 w-4 fill-gray-900 text-gray-900" })] }), _jsx("div", { className: "flex-1 h-2.5 bg-gray-200 rounded-full overflow-hidden", children: _jsx("div", { className: "h-full bg-gradient-to-r from-gray-700 to-gray-900 rounded-full transition-all duration-500", style: { width: `${percentage}%` } }) }), _jsx("span", { className: "text-sm font-medium text-gray-700 w-12 text-right", children: count })] }, rating))) })] })), reviews.length > 0 ? (_jsxs(_Fragment, { children: [_jsx("div", { className: "space-y-6", children: displayedReviews.map((review) => (_jsx(ReviewCard, { review: review }, review.id))) }), hasMoreReviews && !showAllReviews && (_jsx("div", { className: "mt-8 text-center", children: _jsxs(Button, { variant: "outline", onClick: () => setShowAllReviews(true), className: "px-8 rounded-full h-12 border-gray-300", children: ["Show All ", reviews.length, " Reviews"] }) }))] })) : (_jsxs("div", { className: "text-center py-12 bg-gray-50 rounded-xl border border-dashed border-gray-300", children: [_jsx("div", { className: "inline-flex items-center justify-center w-12 h-12 rounded-full bg-white shadow-sm mb-4", children: _jsx(Star, { className: "h-6 w-6 text-gray-400" }) }), _jsx("h3", { className: "text-lg font-semibold text-gray-900 mb-2", children: "No Reviews Yet" }), _jsx("p", { className: "text-gray-500 max-w-sm mx-auto mb-6", children: "Be the first to review this product and help other customers make informed decisions." }), _jsx(Button, { onClick: () => {
|
|
412
|
+
if (!isAuthenticated) {
|
|
413
|
+
openLogin({ onSuccess: () => setIsReviewModalOpen(true) });
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
setIsReviewModalOpen(true);
|
|
417
|
+
}, className: "bg-gray-900 hover:bg-gray-800 text-white", children: "Write a Review" })] }))] }) }), relatedProducts.length > 0 && (_jsxs("div", { className: "mt-20 pt-16 border-t border-gray-200", children: [_jsx("h2", { className: "text-2xl lg:text-3xl font-bold text-gray-900 mb-8", children: "You Might Also Like" }), _jsx("div", { className: "grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-6", children: relatedProducts.map((relatedProduct) => (_jsx("div", { className: "h-[400px]", children: _jsx(ProductCard, { product: relatedProduct, storeSlug: storeConfig.slug, onAddToCart: (p) => addToCart(p, 1), onQuickView: handleQuickView, className: "h-full" }) }, relatedProduct.id))) })] }))] }), _jsx(Modal, { isOpen: isReviewModalOpen, onClose: () => setIsReviewModalOpen(false), title: "Write a Review", children: _jsxs("form", { onSubmit: handleSubmitReview, className: "space-y-4", children: [_jsxs("div", { children: [_jsx("label", { className: "block text-sm font-medium text-gray-700 mb-2", children: "Rating" }), _jsxs("div", { className: "flex items-center gap-1", children: [[1, 2, 3, 4, 5].map((star) => (_jsxs("div", { className: "relative group", children: [_jsx("button", { type: "button", onClick: () => setNewReview({ ...newReview, rating: star - 0.5 }), className: "absolute top-0 left-0 w-1/2 h-full z-20 focus:outline-none", title: `${star - 0.5} stars` }), _jsx("button", { type: "button", onClick: () => setNewReview({ ...newReview, rating: star }), className: "absolute top-0 right-0 w-1/2 h-full z-20 focus:outline-none", title: `${star} stars` }), _jsxs("div", { className: "relative pointer-events-none transition-transform group-hover:scale-110", children: [_jsx(Star, { className: "h-8 w-8 text-gray-200 fill-gray-200" }), newReview.rating >= star - 0.5 && (_jsx("div", { className: "absolute inset-0 overflow-hidden", style: { width: newReview.rating === star - 0.5 ? '50%' : '100%' }, children: _jsx(Star, { className: "h-8 w-8 text-gray-900 fill-gray-900" }) }))] })] }, star))), _jsx("span", { className: "ml-3 text-lg font-medium text-gray-900 w-12", children: newReview.rating })] })] }), _jsxs("div", { children: [_jsx("label", { htmlFor: "title", className: "block text-sm font-medium text-gray-700 mb-1", children: "Review Title" }), _jsx("input", { type: "text", id: "title", required: true, className: "w-full rounded-md border border-gray-300 px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-black", placeholder: "Summarize your thoughts", value: newReview.title, onChange: (e) => setNewReview({ ...newReview, title: e.target.value }) })] }), _jsxs("div", { children: [_jsx("label", { htmlFor: "comment", className: "block text-sm font-medium text-gray-700 mb-1", children: "Review" }), _jsx("textarea", { id: "comment", required: true, rows: 4, className: "w-full rounded-md border border-gray-300 px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-black", placeholder: "What did you like or dislike?", value: newReview.comment, onChange: (e) => setNewReview({ ...newReview, comment: e.target.value }) })] }), _jsxs("div", { className: "pt-4 flex justify-end gap-3", children: [_jsx(Button, { type: "button", variant: "outline", onClick: () => setIsReviewModalOpen(false), children: "Cancel" }), _jsx(Button, { type: "submit", className: "bg-black text-white hover:bg-gray-800", children: "Submit Review" })] })] }) }), _jsx(GuestCheckoutModal, { isOpen: showGuestModal, onClose: () => setShowGuestModal(false), onSubmit: handleGuestInfoSubmit, initialData: getGuestUserInfo() || undefined })] }));
|
|
511
418
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClothingHomePage.d.ts","sourceRoot":"","sources":["../../../../src/layouts/clothing/components/ClothingHomePage.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"ClothingHomePage.d.ts","sourceRoot":"","sources":["../../../../src/layouts/clothing/components/ClothingHomePage.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAmBvD,UAAU,qBAAqB;IAC7B,WAAW,EAAE,WAAW,CAAC;CAC1B;AAaD,wBAAgB,gBAAgB,CAAC,EAAE,WAAW,EAAE,aAAa,EAAE,EAAE,qBAAqB,+BAqyBrF"}
|
|
@@ -5,8 +5,10 @@ import { Button } from '../../../components/ui/button';
|
|
|
5
5
|
import { ProductRating } from '../../../components/ui/product-rating';
|
|
6
6
|
import { ShoppingCart, Heart, ArrowRight, ChevronLeft, ChevronRight } from 'lucide-react';
|
|
7
7
|
import Link from 'next/link';
|
|
8
|
+
import { useRouter } from 'next/navigation';
|
|
8
9
|
import { ImageWithFallback } from '../../../components/ui/image-with-fallback';
|
|
9
10
|
import { useState, useEffect } from 'react';
|
|
11
|
+
import { useToast } from '../../../components/ui/toast';
|
|
10
12
|
import { formatCurrency, filterActiveProducts } from '../../../lib/utils';
|
|
11
13
|
import { getLayoutText, getBannerImage } from '../../../lib/utils/asset-helpers';
|
|
12
14
|
import { toStoreHref } from '../../../lib/utils/url-helpers';
|
|
@@ -17,7 +19,9 @@ import { SafeRichHtml } from '../../../components/rich-text/SafeRichHtml';
|
|
|
17
19
|
import { RichTextExcerpt } from '../../../components/rich-text/RichTextExcerpt';
|
|
18
20
|
export function ClothingHomePage({ storeConfig: initialConfig }) {
|
|
19
21
|
// Use the store from context which is updated in real-time by the editor
|
|
20
|
-
const { store } = useStore();
|
|
22
|
+
const { store, addToCart, toggleWishlist, isInWishlist, isWishlistLoading } = useStore();
|
|
23
|
+
const { addToast } = useToast();
|
|
24
|
+
const router = useRouter();
|
|
21
25
|
const storeConfig = store || initialConfig;
|
|
22
26
|
const layoutConfig = storeConfig.layoutConfig;
|
|
23
27
|
const categories = storeConfig.categories || [];
|
|
@@ -329,6 +333,40 @@ export function ClothingHomePage({ storeConfig: initialConfig }) {
|
|
|
329
333
|
};
|
|
330
334
|
const validImages = extractProductImages(product.images);
|
|
331
335
|
const firstImage = validImages.length > 0 ? validImages[0] : undefined;
|
|
332
|
-
|
|
336
|
+
const productHref = `/${storeConfig.slug}/products/${product.slug}`;
|
|
337
|
+
const hasVariationOptions = (product.variants?.length ?? 0) > 0;
|
|
338
|
+
const inWishlist = isInWishlist(product.id);
|
|
339
|
+
const handleWishlistClick = async (e) => {
|
|
340
|
+
e.preventDefault();
|
|
341
|
+
e.stopPropagation();
|
|
342
|
+
if (isWishlistLoading)
|
|
343
|
+
return;
|
|
344
|
+
try {
|
|
345
|
+
const wasInWishlist = inWishlist;
|
|
346
|
+
await toggleWishlist(product.id);
|
|
347
|
+
addToast(wasInWishlist
|
|
348
|
+
? `${product.name} removed from wishlist`
|
|
349
|
+
: `${product.name} added to wishlist`, 'success');
|
|
350
|
+
}
|
|
351
|
+
catch {
|
|
352
|
+
addToast('Failed to update wishlist', 'error');
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
const handleAddToCartClick = async (e) => {
|
|
356
|
+
e.preventDefault();
|
|
357
|
+
e.stopPropagation();
|
|
358
|
+
if (hasVariationOptions) {
|
|
359
|
+
router.push(productHref);
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
try {
|
|
363
|
+
await addToCart(product, 1);
|
|
364
|
+
addToast(`${product.name} added to cart`, 'success');
|
|
365
|
+
}
|
|
366
|
+
catch {
|
|
367
|
+
addToast('Failed to add to cart', 'error');
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
return (_jsxs("div", { className: "group", children: [_jsxs("div", { className: "relative aspect-[3/4] bg-gray-50 rounded-xl overflow-hidden mb-4", children: [_jsxs(Link, { href: productHref, className: "block w-full h-full", children: [_jsx(ImageWithFallback, { src: firstImage, alt: product.name, className: "w-full h-full object-cover transition-transform duration-700 group-hover:scale-105", skeletonAspectRatio: "3/4", lazy: true }), validImages[1] && (_jsx(ImageWithFallback, { src: validImages[1], alt: product.name, className: "absolute inset-0 w-full h-full object-cover opacity-0 group-hover:opacity-100 transition-opacity duration-500 pointer-events-none", skeletonAspectRatio: "3/4", lazy: true }))] }), _jsxs("div", { className: "hidden lg:flex absolute bottom-4 right-4 z-20 flex-col gap-2 opacity-0 transform translate-x-4 group-hover:opacity-100 group-hover:translate-x-0 transition-all duration-300", children: [storeConfig.features.wishlist && (_jsx(Button, { type: "button", variant: "secondary", size: "icon", onClick: handleWishlistClick, disabled: isWishlistLoading, className: "bg-white hover:bg-black hover:text-white shadow-md rounded-full transition-colors", "aria-label": inWishlist ? 'Remove from wishlist' : 'Add to wishlist', children: _jsx(Heart, { className: `h-4 w-4 ${inWishlist ? 'fill-current text-red-500' : ''}` }) })), _jsx(Button, { type: "button", variant: "secondary", size: "icon", onClick: handleAddToCartClick, className: "bg-white hover:bg-black hover:text-white shadow-md rounded-full transition-colors", "aria-label": "Add to cart", children: _jsx(ShoppingCart, { className: "h-4 w-4" }) })] }), _jsx(Button, { type: "button", variant: "secondary", size: "icon", onClick: handleAddToCartClick, className: "lg:hidden absolute bottom-3 right-3 z-20 bg-white text-black h-10 w-10 rounded-full shadow-lg active:scale-95 transition-transform", "aria-label": "Add to cart", children: _jsx(ShoppingCart, { className: "h-4 w-4" }) }), product.compareAtPrice != null && product.compareAtPrice > product.price && (_jsx("span", { className: "absolute top-3 left-3 z-10 bg-black text-white text-xs font-bold px-3 py-1 rounded-full uppercase tracking-wide", children: getLayoutText(storeConfig, 'common.sale', 'Sale') }))] }), _jsxs(Link, { href: productHref, className: "block space-y-1", children: [_jsx("h3", { className: "font-semibold text-gray-900 group-hover:text-gray-600 transition-colors text-lg", children: product.name }), _jsxs("div", { className: "flex items-center gap-2", children: [_jsx("span", { className: "font-medium text-gray-900", children: formatCurrency(product.price, product.currency || 'USD') }), product.compareAtPrice != null && product.compareAtPrice > product.price && (_jsx("span", { className: "text-sm text-gray-400 line-through", children: formatCurrency(product.compareAtPrice, product.currency || 'USD') }))] }), _jsx(ProductRating, { rating: product.rating, reviewCount: product.reviewCount, size: "sm", showReviewCount: false, className: "shrink-0" })] })] }, product.id));
|
|
333
371
|
}) }), layoutConfig?.sections?.featuredProducts?.showViewAll !== false && (_jsx("div", { className: "mt-16 text-center", children: _jsx(Link, { href: `/${storeConfig.slug}/products`, children: _jsx(Button, { variant: "outline", className: "rounded-full px-10 py-6 border-gray-200 hover:border-black hover:bg-black hover:text-white transition-all text-base font-medium", children: getLayoutText(storeConfig, 'sections.featuredProducts.viewAll', 'View All Products') }) }) }))] }) }))] }));
|
|
334
372
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProductDetailPage.d.ts","sourceRoot":"","sources":["../../../../src/layouts/clothing/pages/ProductDetailPage.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAA8C,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"ProductDetailPage.d.ts","sourceRoot":"","sources":["../../../../src/layouts/clothing/pages/ProductDetailPage.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAA8C,MAAM,0BAA0B,CAAC;AAiCnG,UAAU,sBAAsB;IAC9B,WAAW,EAAE,WAAW,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;CACrB;AAsHD,wBAAgB,iBAAiB,CAAC,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,EAAE,sBAAsB,+BA45BpG"}
|