feat(pdp): redesign variant comparison table for multi-variant products, exclude media keys, and add calendar invites
This commit is contained in:
parent
148ebceae4
commit
16dbaa0916
6 changed files with 335 additions and 194 deletions
|
|
@ -248,7 +248,6 @@ export default async function ProductDetailPage({ params }: ProductDetailPagePro
|
||||||
|
|
||||||
const { product, reviews = [], related_products = [], specifications = [] } = data;
|
const { product, reviews = [], related_products = [], specifications = [] } = data;
|
||||||
const related = related_products.slice(0, 5);
|
const related = related_products.slice(0, 5);
|
||||||
const comparisonProducts = [product, ...related_products.filter((p: any) => p.product_id !== product.product_id)].slice(0, 5);
|
|
||||||
const specGroups = groupSpecs(specifications, product);
|
const specGroups = groupSpecs(specifications, product);
|
||||||
|
|
||||||
const additionalInfoRows: { label: string; value: string }[] = [];
|
const additionalInfoRows: { label: string; value: string }[] = [];
|
||||||
|
|
@ -458,8 +457,8 @@ export default async function ProductDetailPage({ params }: ProductDetailPagePro
|
||||||
|
|
||||||
{related.length > 0 && <YouMayAlsoLike products={related} />}
|
{related.length > 0 && <YouMayAlsoLike products={related} />}
|
||||||
|
|
||||||
{comparisonProducts.length > 0 && (
|
{(product.variants?.length || 0) > 1 && (
|
||||||
<QuickComparisonTable products={comparisonProducts} />
|
<QuickComparisonTable product={product} />
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,9 @@ import {
|
||||||
Smartphone,
|
Smartphone,
|
||||||
Wrench,
|
Wrench,
|
||||||
ArrowRight,
|
ArrowRight,
|
||||||
|
Calendar,
|
||||||
|
Download,
|
||||||
|
ExternalLink,
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
import { AnnouncementBar } from '@/layout/AnnouncementBar';
|
import { AnnouncementBar } from '@/layout/AnnouncementBar';
|
||||||
import { Header } from '@/layout/Header';
|
import { Header } from '@/layout/Header';
|
||||||
|
|
@ -96,6 +99,7 @@ function BookingSuccessContent() {
|
||||||
const needsVerify = searchParams.get('verify') === '1';
|
const needsVerify = searchParams.get('verify') === '1';
|
||||||
|
|
||||||
const [jobDetails, setJobDetails] = useState<any | null>(null);
|
const [jobDetails, setJobDetails] = useState<any | null>(null);
|
||||||
|
const [calendarInvite, setCalendarInvite] = useState<any | null>(null);
|
||||||
const [layoutCMS, setLayoutCMS] = useState<any[]>([]);
|
const [layoutCMS, setLayoutCMS] = useState<any[]>([]);
|
||||||
const [verifyState, setVerifyState] = useState<'idle' | 'verifying' | 'done'>(
|
const [verifyState, setVerifyState] = useState<'idle' | 'verifying' | 'done'>(
|
||||||
needsVerify ? 'verifying' : 'idle'
|
needsVerify ? 'verifying' : 'idle'
|
||||||
|
|
@ -276,6 +280,16 @@ function BookingSuccessContent() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const target = jobId || (jobNoParam && jobNoParam !== 'SRV-BOOKING' ? jobNoParam : '');
|
||||||
|
if (target) {
|
||||||
|
serviceBookingService
|
||||||
|
.fetchCalendarInvite(target)
|
||||||
|
.then((data) => setCalendarInvite(data))
|
||||||
|
.catch(() => setCalendarInvite(null));
|
||||||
|
}
|
||||||
|
}, [jobId, jobNoParam]);
|
||||||
|
|
||||||
const job = unwrapJob(jobDetails);
|
const job = unwrapJob(jobDetails);
|
||||||
const payment = firstPayment(job);
|
const payment = firstPayment(job);
|
||||||
const isPaid =
|
const isPaid =
|
||||||
|
|
@ -454,6 +468,45 @@ function BookingSuccessContent() {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{calendarInvite && (
|
||||||
|
<div className="bg-gradient-to-r from-blue-50 to-indigo-50 border border-blue-200 p-5 rounded-lg flex flex-col md:flex-row md:items-center justify-between gap-4">
|
||||||
|
<div className="flex items-start gap-3.5">
|
||||||
|
<div className="w-10 h-10 rounded-full bg-blue-600 text-white flex items-center justify-center shrink-0 mt-0.5">
|
||||||
|
<Calendar className="w-5 h-5" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<div className="text-[11px] font-bold uppercase tracking-wider text-blue-700">Walk-In Calendar Invite</div>
|
||||||
|
<h4 className="text-[15px] font-bold text-gray-900 mt-0.5">
|
||||||
|
Slot: {new Date(calendarInvite.scheduled_start).toLocaleString('en-IN', { dateStyle: 'medium', timeStyle: 'short' })}
|
||||||
|
</h4>
|
||||||
|
<p className="text-[12px] text-gray-600 mt-1 max-w-xl">
|
||||||
|
Add this repair appointment to your personal calendar to receive automatic pre-service notifications and a reminder before your slot.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-wrap sm:flex-nowrap items-center gap-2 shrink-0">
|
||||||
|
<a
|
||||||
|
href={calendarInvite.google_calendar_url}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
className="px-4 py-2.5 bg-blue-600 hover:bg-blue-700 text-white text-[12px] font-bold rounded flex items-center gap-1.5 shadow-sm transition"
|
||||||
|
>
|
||||||
|
<Calendar className="w-3.5 h-3.5" />
|
||||||
|
Add to Google Calendar
|
||||||
|
<ExternalLink className="w-3 h-3 ml-0.5 opacity-80" />
|
||||||
|
</a>
|
||||||
|
<a
|
||||||
|
href={`http://localhost:8000${calendarInvite.ics_download_url}`}
|
||||||
|
download
|
||||||
|
className="px-4 py-2.5 bg-white hover:bg-gray-50 border border-gray-300 text-gray-800 text-[12px] font-semibold rounded flex items-center gap-1.5 shadow-sm transition"
|
||||||
|
>
|
||||||
|
<Download className="w-3.5 h-3.5" />
|
||||||
|
Download .ics Invite
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
<div className="grid grid-cols-1 lg:grid-cols-2 gap-5">
|
<div className="grid grid-cols-1 lg:grid-cols-2 gap-5">
|
||||||
<div className="border border-[#e5e5e5] p-5 space-y-4">
|
<div className="border border-[#e5e5e5] p-5 space-y-4">
|
||||||
<div className="flex items-center gap-2 text-[11px] font-semibold uppercase tracking-wider text-[#222] border-b border-[#e5e5e5] pb-2">
|
<div className="flex items-center gap-2 text-[11px] font-semibold uppercase tracking-wider text-[#222] border-b border-[#e5e5e5] pb-2">
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,8 @@ import {
|
||||||
Image as ImageIcon,
|
Image as ImageIcon,
|
||||||
Maximize2,
|
Maximize2,
|
||||||
KeyRound,
|
KeyRound,
|
||||||
|
Download,
|
||||||
|
ExternalLink,
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
import { BlurHashImage } from '@/components/ui/BlurHashImage';
|
import { BlurHashImage } from '@/components/ui/BlurHashImage';
|
||||||
import { AnnouncementBar } from '@/layout/AnnouncementBar';
|
import { AnnouncementBar } from '@/layout/AnnouncementBar';
|
||||||
|
|
@ -61,6 +63,7 @@ export default function ServiceJobTrackingPage({
|
||||||
const { isAuthenticated, accessToken, authReady, bootstrapAuth } = useAuthStore();
|
const { isAuthenticated, accessToken, authReady, bootstrapAuth } = useAuthStore();
|
||||||
|
|
||||||
const [job, setJob] = useState<any>(null);
|
const [job, setJob] = useState<any>(null);
|
||||||
|
const [calendarInvite, setCalendarInvite] = useState<any | null>(null);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [errorMsg, setErrorMsg] = useState<string | null>(null);
|
const [errorMsg, setErrorMsg] = useState<string | null>(null);
|
||||||
const [actionLoading, setActionLoading] = useState(false);
|
const [actionLoading, setActionLoading] = useState(false);
|
||||||
|
|
@ -99,6 +102,13 @@ export default function ServiceJobTrackingPage({
|
||||||
job_id: item?.job_id || job_id,
|
job_id: item?.job_id || job_id,
|
||||||
job_no: item?.job_no,
|
job_no: item?.job_no,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (item?.fulfillment_type === 'WALK_IN' || item?.appointment) {
|
||||||
|
serviceBookingService
|
||||||
|
.fetchCalendarInvite(item?.job_id || job_id)
|
||||||
|
.then((cal) => setCalendarInvite(cal))
|
||||||
|
.catch(() => setCalendarInvite(null));
|
||||||
|
}
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
setErrorMsg(err.message || 'Failed to retrieve tracking details.');
|
setErrorMsg(err.message || 'Failed to retrieve tracking details.');
|
||||||
} finally {
|
} finally {
|
||||||
|
|
@ -533,10 +543,15 @@ export default function ServiceJobTrackingPage({
|
||||||
})()}
|
})()}
|
||||||
|
|
||||||
{job.appointment && (
|
{job.appointment && (
|
||||||
<div className="bg-white border border-[#e5e5e5] p-5 space-y-3 text-[13px]">
|
<div className="bg-white border border-[#e5e5e5] p-5 space-y-4 text-[13px]">
|
||||||
<h4 className="font-semibold text-[#222] uppercase tracking-wider text-[11px] border-b border-[#e5e5e5] pb-2">
|
<div className="flex items-center justify-between border-b border-[#e5e5e5] pb-2">
|
||||||
|
<h4 className="font-semibold text-[#222] uppercase tracking-wider text-[11px]">
|
||||||
Booking Schedule
|
Booking Schedule
|
||||||
</h4>
|
</h4>
|
||||||
|
<span className="text-[11px] font-bold text-blue-600 bg-blue-50 px-2 py-0.5 rounded">
|
||||||
|
Walk-In
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
<div className="flex items-start gap-3">
|
<div className="flex items-start gap-3">
|
||||||
<Calendar className="w-5 h-5 text-primary shrink-0 mt-0.5" />
|
<Calendar className="w-5 h-5 text-primary shrink-0 mt-0.5" />
|
||||||
<div>
|
<div>
|
||||||
|
|
@ -550,16 +565,46 @@ export default function ServiceJobTrackingPage({
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
<div className="text-gray-500 font-mono text-[12px] mt-0.5">
|
<div className="text-gray-500 font-mono text-[12px] mt-0.5">
|
||||||
Start:{' '}
|
Slot:{' '}
|
||||||
{new Date(
|
{new Date(
|
||||||
job.appointment.scheduled_start
|
job.appointment.scheduled_start
|
||||||
).toLocaleTimeString('en-US', {
|
).toLocaleTimeString('en-US', {
|
||||||
hour: '2-digit',
|
hour: '2-digit',
|
||||||
minute: '2-digit',
|
minute: '2-digit',
|
||||||
|
})}{' '}
|
||||||
|
–{' '}
|
||||||
|
{new Date(
|
||||||
|
job.appointment.scheduled_end
|
||||||
|
).toLocaleTimeString('en-US', {
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit',
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{calendarInvite && (
|
||||||
|
<div className="pt-2 border-t border-[#f0f0f0] space-y-2">
|
||||||
|
<a
|
||||||
|
href={calendarInvite.google_calendar_url}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
className="w-full py-2 px-3 bg-blue-600 hover:bg-blue-700 text-white font-bold text-[12px] rounded flex items-center justify-center gap-1.5 transition shadow-sm"
|
||||||
|
>
|
||||||
|
<Calendar className="w-3.5 h-3.5" />
|
||||||
|
Add to Google Calendar
|
||||||
|
<ExternalLink className="w-3 h-3 ml-0.5 opacity-80" />
|
||||||
|
</a>
|
||||||
|
<a
|
||||||
|
href={`http://localhost:8000${calendarInvite.ics_download_url}`}
|
||||||
|
download
|
||||||
|
className="w-full py-2 px-3 bg-gray-50 hover:bg-gray-100 border border-gray-200 text-gray-700 font-semibold text-[12px] rounded flex items-center justify-center gap-1.5 transition"
|
||||||
|
>
|
||||||
|
<Download className="w-3.5 h-3.5" />
|
||||||
|
Download .ics Calendar File
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,179 +1,206 @@
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import Link from 'next/link';
|
|
||||||
import Image from 'next/image';
|
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { Check, ShoppingCart } from 'lucide-react';
|
import { Check, ShoppingCart, ShieldCheck, FileText } from 'lucide-react';
|
||||||
import BlurHashImage from '@/components/ui/BlurHashImage';
|
import BlurHashImage from '@/components/ui/BlurHashImage';
|
||||||
import { ProductResponse } from '@/services/api/catalogService';
|
import { ProductResponse, ProductVariantResponse } from '@/services/api/catalogService';
|
||||||
import { useCartStore } from '@/store/cartStore';
|
import { useCartStore } from '@/store/cartStore';
|
||||||
import { formatCatalogPriceLabel, formatCurrency, getImageUrl } from '@/lib/utils';
|
import { formatCurrency, getImageUrl } from '@/lib/utils';
|
||||||
|
|
||||||
interface QuickComparisonTableProps {
|
interface QuickComparisonTableProps {
|
||||||
products: ProductResponse[];
|
product: ProductResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
function priceLabel(product: ProductResponse): string {
|
function getVariantTitle(variant: ProductVariantResponse, fallbackIndex: number): string {
|
||||||
const label = formatCatalogPriceLabel(product);
|
const validAttrs = (variant.attributes || []).filter((a) => {
|
||||||
return label === formatCurrency(0) ? '—' : label;
|
const key = (a.attribute_name || a.attribute_code || '').toLowerCase().trim();
|
||||||
}
|
return a.attribute_value && !['media_key', 'parent_media_key'].includes(key);
|
||||||
|
|
||||||
function productImage(product: ProductResponse): string {
|
|
||||||
return getImageUrl(product.images?.[0]?.image_url || product.variants?.[0]?.images?.[0]?.image_url);
|
|
||||||
}
|
|
||||||
|
|
||||||
function extraAttributes(product: ProductResponse): { label: string; values: string[] }[] {
|
|
||||||
const buckets: Record<string, { label: string; values: Set<string> }> = {};
|
|
||||||
|
|
||||||
(product.variants || []).forEach((variant) => {
|
|
||||||
(variant.attributes || []).forEach((attr) => {
|
|
||||||
const raw = attr.attribute_name || attr.attribute_code || '';
|
|
||||||
const value = String(attr.attribute_value || '').trim();
|
|
||||||
if (!raw || !value) return;
|
|
||||||
const key = raw.trim().toLowerCase().replace(/[\s-]+/g, '_');
|
|
||||||
if (!buckets[key]) {
|
|
||||||
let label = raw.replace(/[_-]+/g, ' ').replace(/\b\w/g, (c) => c.toUpperCase());
|
|
||||||
if (['qul', 'qual'].includes(key)) label = 'Quality';
|
|
||||||
else if (['clr'].includes(key)) label = 'Color';
|
|
||||||
else if (['str'].includes(key)) label = 'Storage';
|
|
||||||
buckets[key] = {
|
|
||||||
label,
|
|
||||||
values: new Set(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
buckets[key].values.add(value);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return Object.values(buckets)
|
if (validAttrs.length > 0) {
|
||||||
.map((item) => ({
|
return validAttrs
|
||||||
label: item.label,
|
.map((a) => {
|
||||||
values: Array.from(item.values),
|
const name = a.attribute_name ? `${a.attribute_name}: ` : '';
|
||||||
}))
|
return `${name}${a.attribute_value}`;
|
||||||
.slice(0, 3);
|
})
|
||||||
|
.join(' | ');
|
||||||
}
|
}
|
||||||
|
|
||||||
function ctaKind(product: ProductResponse): 'view' | 'cart' {
|
return variant.sku || `Variant ${fallbackIndex + 1}`;
|
||||||
return (product.variants?.length || 0) > 1 ? 'view' : 'cart';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function QuickComparisonTable({ products }: QuickComparisonTableProps) {
|
function getVariantImage(product: ProductResponse, variant: ProductVariantResponse): string {
|
||||||
|
const img = variant.images?.[0]?.image_url || product.images?.[0]?.image_url;
|
||||||
|
return getImageUrl(img);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function QuickComparisonTable({ product }: QuickComparisonTableProps) {
|
||||||
const addToCart = useCartStore((state) => state.addToCart);
|
const addToCart = useCartStore((state) => state.addToCart);
|
||||||
const [addedId, setAddedId] = useState<string | null>(null);
|
const [addedVariantId, setAddedVariantId] = useState<string | null>(null);
|
||||||
|
|
||||||
if (!products.length) return null;
|
const variants = product?.variants || [];
|
||||||
|
// Strictly only show when the product has multiple variants (> 1)
|
||||||
|
if (variants.length <= 1) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const handleAdd = async (product: ProductResponse) => {
|
const handleAdd = async (variant: ProductVariantResponse) => {
|
||||||
const variant = product.variants?.[0];
|
|
||||||
if (!variant) return;
|
|
||||||
await addToCart(product, variant, 1);
|
await addToCart(product, variant, 1);
|
||||||
setAddedId(product.product_id);
|
setAddedVariantId(variant.variant_id);
|
||||||
setTimeout(() => setAddedId(null), 1800);
|
setTimeout(() => setAddedVariantId(null), 1800);
|
||||||
};
|
};
|
||||||
|
|
||||||
const labelCls =
|
const labelCls =
|
||||||
'sticky left-0 z-10 w-[150px] min-w-[150px] px-4 py-4 text-[13px] font-medium text-gray-500 text-left align-middle bg-[#f3f4f6]';
|
'sticky left-0 z-10 w-[160px] min-w-[160px] px-5 py-4 text-[13px] font-semibold text-gray-700 text-left align-middle bg-[#f3f4f6] border-b border-gray-200';
|
||||||
const cellCls = 'px-5 py-4 min-w-[170px] align-middle text-center';
|
const cellCls = 'px-5 py-4 min-w-[200px] align-middle text-center border-b border-gray-200';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className="mb-10">
|
<section className="mb-12">
|
||||||
<h3 className="text-[20px] font-semibold text-gray-800 mb-4 tracking-tight">Quick Comparison</h3>
|
<div className="flex items-center gap-2 mb-4">
|
||||||
<div className="overflow-x-auto rounded-md border border-gray-200">
|
<h3 className="text-[20px] font-bold text-gray-800 tracking-tight">Variant Comparison</h3>
|
||||||
<table className="w-full border-collapse min-w-[860px]">
|
<span className="text-[12px] font-medium text-gray-500 bg-gray-100 px-2.5 py-0.5 rounded-full">
|
||||||
|
{variants.length} Options
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="overflow-x-auto rounded-lg border border-gray-200 shadow-sm bg-white">
|
||||||
|
<table className="w-full border-collapse min-w-[700px]">
|
||||||
|
{/* Variant Header Row */}
|
||||||
<thead>
|
<thead>
|
||||||
<tr className="bg-white">
|
<tr className="bg-white">
|
||||||
<th className={labelCls} />
|
<th className={`${labelCls} bg-white text-gray-400 font-normal`}>Option</th>
|
||||||
{products.map((prod) => {
|
{variants.map((v, idx) => {
|
||||||
const img = productImage(prod);
|
const img = getVariantImage(product, v);
|
||||||
|
const title = getVariantTitle(v, idx);
|
||||||
return (
|
return (
|
||||||
<th key={prod.product_id} className={`${cellCls} font-normal bg-white`}>
|
<th key={v.variant_id} className={`${cellCls} font-normal bg-white`}>
|
||||||
<Link
|
<div className="w-[100px] h-[100px] mx-auto bg-gray-50 border border-gray-200 rounded-lg p-2 flex items-center justify-center mb-3">
|
||||||
href={`/products/${prod.slug}`}
|
|
||||||
className="block text-[13px] font-medium text-gray-700 leading-snug hover:text-primary line-clamp-2 min-h-[36px] mb-3"
|
|
||||||
>
|
|
||||||
{prod.name}
|
|
||||||
</Link>
|
|
||||||
<Link
|
|
||||||
href={`/products/${prod.slug}`}
|
|
||||||
className="w-[92px] h-[92px] mx-auto bg-white border border-gray-200 rounded-md p-2 flex items-center justify-center hover:border-primary/40 transition-colors"
|
|
||||||
>
|
|
||||||
<BlurHashImage
|
<BlurHashImage
|
||||||
src={img}
|
src={img}
|
||||||
alt={prod.name}
|
alt={title}
|
||||||
width={84}
|
width={90}
|
||||||
height={84}
|
height={90}
|
||||||
className="max-h-full max-w-full object-contain"
|
className="max-h-full max-w-full object-contain"
|
||||||
/>
|
/>
|
||||||
</Link>
|
</div>
|
||||||
|
<div className="text-[13px] font-semibold text-gray-800 leading-snug line-clamp-2 px-1 min-h-[36px]">
|
||||||
|
{title}
|
||||||
|
</div>
|
||||||
</th>
|
</th>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr className="bg-[#f8f8f8]">
|
{/* 1. Name / Specifications Row */}
|
||||||
<td className={labelCls}>Price</td>
|
<tr className="bg-[#fcfcfd]">
|
||||||
{products.map((prod) => (
|
<td className={labelCls}>Name / Specification</td>
|
||||||
<td key={prod.product_id} className={`${cellCls} text-[14px] font-bold text-gray-900`}>
|
{variants.map((v, idx) => (
|
||||||
{priceLabel(prod)}
|
<td key={v.variant_id} className={`${cellCls} text-[13px] font-medium text-gray-800`}>
|
||||||
|
{getVariantTitle(v, idx)}
|
||||||
</td>
|
</td>
|
||||||
))}
|
))}
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
{/* 2. Price Row */}
|
||||||
<tr className="bg-white">
|
<tr className="bg-white">
|
||||||
<td className={labelCls}>Add to cart</td>
|
<td className={labelCls}>Price</td>
|
||||||
{products.map((prod) => {
|
{variants.map((v) => {
|
||||||
const kind = ctaKind(prod);
|
const price = Number(v.price) || 0;
|
||||||
const justAdded = addedId === prod.product_id;
|
const comparePrice = v.compare_price ? Number(v.compare_price) : 0;
|
||||||
|
const hasDiscount = comparePrice > price;
|
||||||
|
const discountPercent = hasDiscount
|
||||||
|
? Math.round(((comparePrice - price) / comparePrice) * 100)
|
||||||
|
: 0;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<td key={prod.product_id} className={cellCls}>
|
<td key={v.variant_id} className={cellCls}>
|
||||||
{kind === 'view' ? (
|
<div className="flex items-center justify-center gap-2 flex-wrap">
|
||||||
<Link
|
<span className="text-[16px] font-bold text-gray-900">
|
||||||
href={`/products/${prod.slug}`}
|
{formatCurrency(price)}
|
||||||
className="inline-flex items-center justify-center min-w-[120px] bg-primary hover:bg-primary-hover text-white text-[13px] font-semibold px-4 py-2.5 rounded-md transition-colors"
|
</span>
|
||||||
>
|
{hasDiscount && (
|
||||||
View Products
|
<>
|
||||||
</Link>
|
<span className="text-[13px] text-gray-400 line-through">
|
||||||
) : (
|
{formatCurrency(comparePrice)}
|
||||||
<button
|
</span>
|
||||||
type="button"
|
<span className="text-[11px] font-semibold text-emerald-700 bg-emerald-50 border border-emerald-200 px-1.5 py-0.5 rounded">
|
||||||
onClick={() => void handleAdd(prod)}
|
{discountPercent}% OFF
|
||||||
className="inline-flex items-center justify-center gap-1.5 min-w-[120px] bg-primary hover:bg-primary-hover text-white text-[13px] font-semibold px-4 py-2.5 rounded-md transition-colors cursor-pointer"
|
</span>
|
||||||
>
|
</>
|
||||||
{justAdded ? <Check size={14} /> : <ShoppingCart size={14} />}
|
|
||||||
{justAdded ? 'Added' : 'Add To Cart'}
|
|
||||||
</button>
|
|
||||||
)}
|
)}
|
||||||
|
</div>
|
||||||
</td>
|
</td>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr className="bg-[#f8f8f8]">
|
{/* 3. Warranty Type Row */}
|
||||||
<td className={`${labelCls} align-top`}>Additional information</td>
|
<tr className="bg-[#fcfcfd]">
|
||||||
{products.map((prod) => {
|
<td className={labelCls}>
|
||||||
const attrs = extraAttributes(prod);
|
<div className="flex items-center gap-1.5">
|
||||||
|
<ShieldCheck size={15} className="text-primary flex-shrink-0" />
|
||||||
|
<span>Warranty Type</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
{variants.map((v) => (
|
||||||
|
<td key={v.variant_id} className={`${cellCls} text-[13px] text-gray-700 font-medium`}>
|
||||||
|
{product.warranty_type || 'Standard Warranty'}
|
||||||
|
</td>
|
||||||
|
))}
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
{/* 4. Summary Row */}
|
||||||
|
<tr className="bg-white">
|
||||||
|
<td className={labelCls}>
|
||||||
|
<div className="flex items-center gap-1.5">
|
||||||
|
<FileText size={15} className="text-primary flex-shrink-0" />
|
||||||
|
<span>Summary</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
{variants.map((v) => (
|
||||||
|
<td key={v.variant_id} className={`${cellCls} text-[13px] text-gray-600 leading-relaxed max-w-[280px]`}>
|
||||||
|
{product.warranty_summary || '100% Quality Tested & Brand Verified'}
|
||||||
|
</td>
|
||||||
|
))}
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
{/* Action Row */}
|
||||||
|
<tr className="bg-[#fcfcfd]">
|
||||||
|
<td className={labelCls}>Action</td>
|
||||||
|
{variants.map((v) => {
|
||||||
|
const justAdded = addedVariantId === v.variant_id;
|
||||||
|
const isOutOfStock = v.status === 'inactive' || (v.available_stock !== undefined && v.available_stock <= 0);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<td key={prod.product_id} className={`${cellCls} align-top text-[12px] leading-relaxed`}>
|
<td key={v.variant_id} className={cellCls}>
|
||||||
{attrs.length === 0 ? (
|
<button
|
||||||
<span className="text-gray-300">—</span>
|
type="button"
|
||||||
|
disabled={isOutOfStock}
|
||||||
|
onClick={() => void handleAdd(v)}
|
||||||
|
className={`inline-flex items-center justify-center gap-2 min-w-[130px] text-[13px] font-semibold px-4 py-2.5 rounded-md transition-all cursor-pointer shadow-sm ${
|
||||||
|
isOutOfStock
|
||||||
|
? 'bg-gray-200 text-gray-400 cursor-not-allowed'
|
||||||
|
: justAdded
|
||||||
|
? 'bg-emerald-600 text-white'
|
||||||
|
: 'bg-primary hover:bg-primary-hover text-white hover:shadow'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{isOutOfStock ? (
|
||||||
|
'Out of Stock'
|
||||||
|
) : justAdded ? (
|
||||||
|
<>
|
||||||
|
<Check size={14} className="stroke-[2.5]" />
|
||||||
|
<span>Added</span>
|
||||||
|
</>
|
||||||
) : (
|
) : (
|
||||||
<div className="space-y-1.5 text-left inline-block">
|
<>
|
||||||
{attrs.map((attr) => (
|
<ShoppingCart size={14} />
|
||||||
<div key={attr.label}>
|
<span>Add To Cart</span>
|
||||||
<span className="text-gray-700 font-medium">{attr.label}: </span>
|
</>
|
||||||
{attr.values.map((value, i) => (
|
|
||||||
<span key={value}>
|
|
||||||
<Link href={`/products/${prod.slug}`} className="text-primary hover:underline">
|
|
||||||
{value}
|
|
||||||
</Link>
|
|
||||||
{i < attr.values.length - 1 ? <span className="text-gray-400">, </span> : null}
|
|
||||||
</span>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
)}
|
)}
|
||||||
|
</button>
|
||||||
</td>
|
</td>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|
|
||||||
|
|
@ -117,6 +117,8 @@ export interface ProductResponse {
|
||||||
created_at: string;
|
created_at: string;
|
||||||
images: ProductImageResponse[];
|
images: ProductImageResponse[];
|
||||||
variants: ProductVariantResponse[];
|
variants: ProductVariantResponse[];
|
||||||
|
warranty_type?: string | null;
|
||||||
|
warranty_summary?: string | null;
|
||||||
rating?: number;
|
rating?: number;
|
||||||
review_count?: number;
|
review_count?: number;
|
||||||
badge?: 'HOT' | 'NEW' | 'SALE' | null;
|
badge?: 'HOT' | 'NEW' | 'SALE' | null;
|
||||||
|
|
|
||||||
|
|
@ -496,6 +496,21 @@ export const serviceBookingService = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
fetchCalendarInvite(jobId: string): Promise<{
|
||||||
|
job_id: string;
|
||||||
|
job_no: string;
|
||||||
|
appointment_id: string;
|
||||||
|
scheduled_start: string;
|
||||||
|
scheduled_end: string;
|
||||||
|
device_name: string;
|
||||||
|
google_calendar_url: string;
|
||||||
|
store_name: string;
|
||||||
|
store_address: string;
|
||||||
|
ics_download_url: string;
|
||||||
|
}> {
|
||||||
|
return apiFetch(`/api/v1/service/jobs/${jobId}/calendar-invite`);
|
||||||
|
},
|
||||||
|
|
||||||
fetchServicePageLayout(): Promise<any[]> {
|
fetchServicePageLayout(): Promise<any[]> {
|
||||||
return apiFetch<any[]>('/api/v1/storefront/layout/services');
|
return apiFetch<any[]>('/api/v1/storefront/layout/services');
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue