feat(pdp): add rating review anchor shortcut, high visibility review tabs, smart related product image fallback and crisp placeholder
This commit is contained in:
parent
59453e809a
commit
a1c21fead2
5 changed files with 101 additions and 28 deletions
|
|
@ -25,6 +25,7 @@ import {
|
|||
Zap,
|
||||
MapPin,
|
||||
Clock,
|
||||
Star,
|
||||
} from 'lucide-react';
|
||||
import { requireLoginForCheckout } from '@/lib/requireLoginForCheckout';
|
||||
import { trackViewItem, trackAddToCart, trackBeginCheckout } from '@/lib/analytics';
|
||||
|
|
@ -545,6 +546,37 @@ export const ProductInteractiveGrid: React.FC<ProductInteractiveGridProps> = ({
|
|||
{product.name}
|
||||
</h1>
|
||||
|
||||
{/* Product Rating & Reviews Anchor Shortcut */}
|
||||
<div className="flex items-center gap-2.5 pt-0.5">
|
||||
<div className="flex items-center text-amber-400">
|
||||
{Array.from({ length: 5 }).map((_, i) => (
|
||||
<Star
|
||||
key={i}
|
||||
size={15}
|
||||
className={i < Math.round(product.rating || 5) ? 'fill-amber-400 text-amber-400' : 'text-gray-300'}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
<span className="text-[13px] font-bold text-gray-800">
|
||||
{Number(product.rating || 5.0).toFixed(1)}
|
||||
</span>
|
||||
<span className="text-gray-300 text-xs">•</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
const reviewsBtn = document.getElementById('tab-reviews-btn');
|
||||
if (reviewsBtn) reviewsBtn.click();
|
||||
const tabsContainer = document.getElementById('product-tabs');
|
||||
if (tabsContainer) {
|
||||
tabsContainer.scrollIntoView({ behavior: 'smooth' });
|
||||
}
|
||||
}}
|
||||
className="text-[13px] font-semibold text-primary hover:underline cursor-pointer flex items-center gap-1"
|
||||
>
|
||||
<span>{initialReviewsCount > 0 ? `${initialReviewsCount} Customer Review${initialReviewsCount > 1 ? 's' : ''}` : 'Customer Reviews (Write a review)'}</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-baseline gap-3">
|
||||
<span className="text-xl md:text-2xl font-extrabold text-gray-900 font-outfit">{priceLabel}</span>
|
||||
{selectedCompare > selectedPrice && (
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
"use client";
|
||||
|
||||
import React, { useState } from 'react';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { ProductReviewsSection } from './ProductReviewsSection';
|
||||
|
||||
interface ProductTabsWrapperProps {
|
||||
|
|
@ -14,8 +14,7 @@ interface ProductTabsWrapperProps {
|
|||
|
||||
type TabId = 'description' | 'specs' | 'reviews';
|
||||
|
||||
const TAB_LINE = 'border-[#e0e0e0]';
|
||||
const BOX = 'border border-[#e0e0e0]';
|
||||
const BOX = 'border border-gray-200 rounded-xl overflow-hidden';
|
||||
|
||||
export const ProductTabsWrapper: React.FC<ProductTabsWrapperProps> = ({
|
||||
productId,
|
||||
|
|
@ -28,33 +27,68 @@ export const ProductTabsWrapper: React.FC<ProductTabsWrapperProps> = ({
|
|||
const [activeTab, setActiveTab] = useState<TabId>('description');
|
||||
const [reviewsCount, setReviewsCount] = useState<number>(initialReviewsCount);
|
||||
|
||||
const tabs: { id: TabId; label: string }[] = [
|
||||
{ id: 'description', label: 'Description' },
|
||||
...(showSpecifications ? [{ id: 'specs' as TabId, label: 'Specifications' }] : []),
|
||||
{ id: 'reviews' as TabId, label: `Reviews (${reviewsCount})` },
|
||||
];
|
||||
useEffect(() => {
|
||||
if (typeof window !== 'undefined' && window.location.hash === '#reviews') {
|
||||
setActiveTab('reviews');
|
||||
setTimeout(() => {
|
||||
document.getElementById('product-tabs')?.scrollIntoView({ behavior: 'smooth' });
|
||||
}, 150);
|
||||
}
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div id="product-tabs" className="bg-white mb-10 text-left">
|
||||
{/* Tab Headers */}
|
||||
<div className={`flex justify-center items-end gap-8 md:gap-12 border-b ${TAB_LINE} overflow-x-auto no-scrollbar`}>
|
||||
{tabs.map((tab) => {
|
||||
const isActive = activeTab === tab.id;
|
||||
return (
|
||||
<button
|
||||
key={tab.id}
|
||||
type="button"
|
||||
onClick={() => setActiveTab(tab.id)}
|
||||
className={`-mb-px pb-[13px] text-[14px] leading-none whitespace-nowrap cursor-pointer border-b-2 transition-colors ${
|
||||
isActive
|
||||
? 'border-primary text-[#222] font-bold'
|
||||
: 'border-transparent text-[#9a9a9a] hover:text-[#555]'
|
||||
}`}
|
||||
>
|
||||
{tab.label}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
{/* Modern High-Visibility Tab Bar */}
|
||||
<div className="flex items-center justify-center border-b border-gray-200 gap-2 sm:gap-6 overflow-x-auto pb-px">
|
||||
<button
|
||||
id="tab-description-btn"
|
||||
type="button"
|
||||
onClick={() => setActiveTab('description')}
|
||||
className={`pb-3 px-3 text-[15px] sm:text-[16px] font-semibold cursor-pointer border-b-2 transition-all flex items-center gap-1.5 ${
|
||||
activeTab === 'description'
|
||||
? 'border-primary text-primary font-bold'
|
||||
: 'border-transparent text-gray-500 hover:text-gray-900'
|
||||
}`}
|
||||
>
|
||||
<span>Description</span>
|
||||
</button>
|
||||
|
||||
{showSpecifications && (
|
||||
<button
|
||||
id="tab-specs-btn"
|
||||
type="button"
|
||||
onClick={() => setActiveTab('specs')}
|
||||
className={`pb-3 px-3 text-[15px] sm:text-[16px] font-semibold cursor-pointer border-b-2 transition-all flex items-center gap-1.5 ${
|
||||
activeTab === 'specs'
|
||||
? 'border-primary text-primary font-bold'
|
||||
: 'border-transparent text-gray-500 hover:text-gray-900'
|
||||
}`}
|
||||
>
|
||||
<span>Specifications</span>
|
||||
</button>
|
||||
)}
|
||||
|
||||
<button
|
||||
id="tab-reviews-btn"
|
||||
type="button"
|
||||
onClick={() => setActiveTab('reviews')}
|
||||
className={`pb-3 px-3 text-[15px] sm:text-[16px] font-semibold cursor-pointer border-b-2 transition-all flex items-center gap-2 ${
|
||||
activeTab === 'reviews'
|
||||
? 'border-primary text-primary font-bold'
|
||||
: 'border-transparent text-gray-500 hover:text-gray-900'
|
||||
}`}
|
||||
>
|
||||
<span>Customer Reviews</span>
|
||||
<span
|
||||
className={`px-2 py-0.5 rounded-full text-xs font-bold transition-colors ${
|
||||
activeTab === 'reviews'
|
||||
? 'bg-primary text-white'
|
||||
: 'bg-gray-100 text-gray-700'
|
||||
}`}
|
||||
>
|
||||
{reviewsCount}
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Tab Panels */}
|
||||
|
|
|
|||
|
|
@ -101,7 +101,12 @@ export function YouMayAlsoLike({ products }: YouMayAlsoLikeProps) {
|
|||
style={{ gridTemplateColumns: `repeat(${Math.min(products.length, 5)}, minmax(168px, 1fr))` }}
|
||||
>
|
||||
{products.slice(0, 5).map((prod, index) => {
|
||||
const img = getImageUrl(prod.images?.[0]?.image_url || prod.variants?.[0]?.images?.[0]?.image_url);
|
||||
const img = getImageUrl(
|
||||
prod.thumbnail_url ||
|
||||
prod.images?.[0]?.image_url ||
|
||||
prod.variants?.[0]?.thumbnail_url ||
|
||||
prod.variants?.[0]?.images?.[0]?.image_url
|
||||
);
|
||||
const off = discountPct(prod);
|
||||
const pricing = priceLabel(prod);
|
||||
const onSale = off > 0;
|
||||
|
|
|
|||
Binary file not shown.
|
Before Width: | Height: | Size: 992 B After Width: | Height: | Size: 2.8 KiB |
|
|
@ -91,6 +91,7 @@ export interface ProductVariantResponse {
|
|||
low_stock_threshold: number;
|
||||
status: string;
|
||||
available_stock?: number;
|
||||
thumbnail_url?: string | null;
|
||||
attributes?: VariantAttributeResponse[];
|
||||
images?: VariantImageResponse[];
|
||||
}
|
||||
|
|
@ -116,6 +117,7 @@ export interface ProductResponse {
|
|||
description: string | null;
|
||||
status: string;
|
||||
created_at: string;
|
||||
thumbnail_url?: string | null;
|
||||
images: ProductImageResponse[];
|
||||
variants: ProductVariantResponse[];
|
||||
warranty_type?: string | null;
|
||||
|
|
|
|||
Loading…
Reference in a new issue