feat(pdp): add rating review anchor shortcut, high visibility review tabs, smart related product image fallback and crisp placeholder

This commit is contained in:
iFixKart Dev 2026-11-17 13:52:38 +05:30
parent 59453e809a
commit a1c21fead2
5 changed files with 101 additions and 28 deletions

View file

@ -25,6 +25,7 @@ import {
Zap, Zap,
MapPin, MapPin,
Clock, Clock,
Star,
} from 'lucide-react'; } from 'lucide-react';
import { requireLoginForCheckout } from '@/lib/requireLoginForCheckout'; import { requireLoginForCheckout } from '@/lib/requireLoginForCheckout';
import { trackViewItem, trackAddToCart, trackBeginCheckout } from '@/lib/analytics'; import { trackViewItem, trackAddToCart, trackBeginCheckout } from '@/lib/analytics';
@ -545,6 +546,37 @@ export const ProductInteractiveGrid: React.FC<ProductInteractiveGridProps> = ({
{product.name} {product.name}
</h1> </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"> <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> <span className="text-xl md:text-2xl font-extrabold text-gray-900 font-outfit">{priceLabel}</span>
{selectedCompare > selectedPrice && ( {selectedCompare > selectedPrice && (

View file

@ -1,6 +1,6 @@
"use client"; "use client";
import React, { useState } from 'react'; import React, { useState, useEffect } from 'react';
import { ProductReviewsSection } from './ProductReviewsSection'; import { ProductReviewsSection } from './ProductReviewsSection';
interface ProductTabsWrapperProps { interface ProductTabsWrapperProps {
@ -14,8 +14,7 @@ interface ProductTabsWrapperProps {
type TabId = 'description' | 'specs' | 'reviews'; type TabId = 'description' | 'specs' | 'reviews';
const TAB_LINE = 'border-[#e0e0e0]'; const BOX = 'border border-gray-200 rounded-xl overflow-hidden';
const BOX = 'border border-[#e0e0e0]';
export const ProductTabsWrapper: React.FC<ProductTabsWrapperProps> = ({ export const ProductTabsWrapper: React.FC<ProductTabsWrapperProps> = ({
productId, productId,
@ -28,33 +27,68 @@ export const ProductTabsWrapper: React.FC<ProductTabsWrapperProps> = ({
const [activeTab, setActiveTab] = useState<TabId>('description'); const [activeTab, setActiveTab] = useState<TabId>('description');
const [reviewsCount, setReviewsCount] = useState<number>(initialReviewsCount); const [reviewsCount, setReviewsCount] = useState<number>(initialReviewsCount);
const tabs: { id: TabId; label: string }[] = [ useEffect(() => {
{ id: 'description', label: 'Description' }, if (typeof window !== 'undefined' && window.location.hash === '#reviews') {
...(showSpecifications ? [{ id: 'specs' as TabId, label: 'Specifications' }] : []), setActiveTab('reviews');
{ id: 'reviews' as TabId, label: `Reviews (${reviewsCount})` }, setTimeout(() => {
]; document.getElementById('product-tabs')?.scrollIntoView({ behavior: 'smooth' });
}, 150);
}
}, []);
return ( return (
<div id="product-tabs" className="bg-white mb-10 text-left"> <div id="product-tabs" className="bg-white mb-10 text-left">
{/* Tab Headers */} {/* Modern High-Visibility Tab Bar */}
<div className={`flex justify-center items-end gap-8 md:gap-12 border-b ${TAB_LINE} overflow-x-auto no-scrollbar`}> <div className="flex items-center justify-center border-b border-gray-200 gap-2 sm:gap-6 overflow-x-auto pb-px">
{tabs.map((tab) => {
const isActive = activeTab === tab.id;
return (
<button <button
key={tab.id} id="tab-description-btn"
type="button" type="button"
onClick={() => setActiveTab(tab.id)} onClick={() => setActiveTab('description')}
className={`-mb-px pb-[13px] text-[14px] leading-none whitespace-nowrap cursor-pointer border-b-2 transition-colors ${ 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 ${
isActive activeTab === 'description'
? 'border-primary text-[#222] font-bold' ? 'border-primary text-primary font-bold'
: 'border-transparent text-[#9a9a9a] hover:text-[#555]' : 'border-transparent text-gray-500 hover:text-gray-900'
}`} }`}
> >
{tab.label} <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> </button>
);
})}
</div> </div>
{/* Tab Panels */} {/* Tab Panels */}

View file

@ -101,7 +101,12 @@ export function YouMayAlsoLike({ products }: YouMayAlsoLikeProps) {
style={{ gridTemplateColumns: `repeat(${Math.min(products.length, 5)}, minmax(168px, 1fr))` }} style={{ gridTemplateColumns: `repeat(${Math.min(products.length, 5)}, minmax(168px, 1fr))` }}
> >
{products.slice(0, 5).map((prod, index) => { {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 off = discountPct(prod);
const pricing = priceLabel(prod); const pricing = priceLabel(prod);
const onSale = off > 0; const onSale = off > 0;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 992 B

After

Width:  |  Height:  |  Size: 2.8 KiB

View file

@ -91,6 +91,7 @@ export interface ProductVariantResponse {
low_stock_threshold: number; low_stock_threshold: number;
status: string; status: string;
available_stock?: number; available_stock?: number;
thumbnail_url?: string | null;
attributes?: VariantAttributeResponse[]; attributes?: VariantAttributeResponse[];
images?: VariantImageResponse[]; images?: VariantImageResponse[];
} }
@ -116,6 +117,7 @@ export interface ProductResponse {
description: string | null; description: string | null;
status: string; status: string;
created_at: string; created_at: string;
thumbnail_url?: string | null;
images: ProductImageResponse[]; images: ProductImageResponse[];
variants: ProductVariantResponse[]; variants: ProductVariantResponse[];
warranty_type?: string | null; warranty_type?: string | null;