diff --git a/app/products/[slug]/page.tsx b/app/products/[slug]/page.tsx index f37c45a..6ceb5b3 100644 --- a/app/products/[slug]/page.tsx +++ b/app/products/[slug]/page.tsx @@ -248,7 +248,6 @@ export default async function ProductDetailPage({ params }: ProductDetailPagePro const { product, reviews = [], related_products = [], specifications = [] } = data; 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 additionalInfoRows: { label: string; value: string }[] = []; @@ -458,8 +457,8 @@ export default async function ProductDetailPage({ params }: ProductDetailPagePro {related.length > 0 && } - {comparisonProducts.length > 0 && ( - + {(product.variants?.length || 0) > 1 && ( + )} diff --git a/app/services/success/page.tsx b/app/services/success/page.tsx index 3f7e997..ec10fcb 100644 --- a/app/services/success/page.tsx +++ b/app/services/success/page.tsx @@ -28,6 +28,9 @@ import { Smartphone, Wrench, ArrowRight, + Calendar, + Download, + ExternalLink, } from 'lucide-react'; import { AnnouncementBar } from '@/layout/AnnouncementBar'; import { Header } from '@/layout/Header'; @@ -96,6 +99,7 @@ function BookingSuccessContent() { const needsVerify = searchParams.get('verify') === '1'; const [jobDetails, setJobDetails] = useState(null); + const [calendarInvite, setCalendarInvite] = useState(null); const [layoutCMS, setLayoutCMS] = useState([]); const [verifyState, setVerifyState] = useState<'idle' | 'verifying' | 'done'>( 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 payment = firstPayment(job); const isPaid = @@ -454,6 +468,45 @@ function BookingSuccessContent() { + {calendarInvite && ( +
+
+
+ +
+
+
Walk-In Calendar Invite
+

+ Slot: {new Date(calendarInvite.scheduled_start).toLocaleString('en-IN', { dateStyle: 'medium', timeStyle: 'short' })} +

+

+ Add this repair appointment to your personal calendar to receive automatic pre-service notifications and a reminder before your slot. +

+
+
+ +
+ )} +
diff --git a/app/services/tracking/[job_id]/page.tsx b/app/services/tracking/[job_id]/page.tsx index 3b8fd88..01ffaa2 100644 --- a/app/services/tracking/[job_id]/page.tsx +++ b/app/services/tracking/[job_id]/page.tsx @@ -25,6 +25,8 @@ import { Image as ImageIcon, Maximize2, KeyRound, + Download, + ExternalLink, } from 'lucide-react'; import { BlurHashImage } from '@/components/ui/BlurHashImage'; import { AnnouncementBar } from '@/layout/AnnouncementBar'; @@ -61,6 +63,7 @@ export default function ServiceJobTrackingPage({ const { isAuthenticated, accessToken, authReady, bootstrapAuth } = useAuthStore(); const [job, setJob] = useState(null); + const [calendarInvite, setCalendarInvite] = useState(null); const [loading, setLoading] = useState(true); const [errorMsg, setErrorMsg] = useState(null); const [actionLoading, setActionLoading] = useState(false); @@ -99,6 +102,13 @@ export default function ServiceJobTrackingPage({ job_id: item?.job_id || job_id, 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) { setErrorMsg(err.message || 'Failed to retrieve tracking details.'); } finally { @@ -533,10 +543,15 @@ export default function ServiceJobTrackingPage({ })()} {job.appointment && ( -
-

- Booking Schedule -

+
+
+

+ Booking Schedule +

+ + Walk-In + +
@@ -550,16 +565,46 @@ export default function ServiceJobTrackingPage({ })}
- Start:{' '} + Slot:{' '} {new Date( job.appointment.scheduled_start ).toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', + })}{' '} + –{' '} + {new Date( + job.appointment.scheduled_end + ).toLocaleTimeString('en-US', { + hour: '2-digit', + minute: '2-digit', })}
+ + {calendarInvite && ( + + )}
)} diff --git a/components/pdp/QuickComparisonTable.tsx b/components/pdp/QuickComparisonTable.tsx index 79154c9..b41e218 100644 --- a/components/pdp/QuickComparisonTable.tsx +++ b/components/pdp/QuickComparisonTable.tsx @@ -1,186 +1,213 @@ -'use client'; - -import Link from 'next/link'; -import Image from 'next/image'; -import { useState } from 'react'; -import { Check, ShoppingCart } from 'lucide-react'; -import BlurHashImage from '@/components/ui/BlurHashImage'; -import { ProductResponse } from '@/services/api/catalogService'; -import { useCartStore } from '@/store/cartStore'; -import { formatCatalogPriceLabel, formatCurrency, getImageUrl } from '@/lib/utils'; - -interface QuickComparisonTableProps { - products: ProductResponse[]; -} - -function priceLabel(product: ProductResponse): string { - const label = formatCatalogPriceLabel(product); - return label === formatCurrency(0) ? '—' : label; -} - -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 }> = {}; - - (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) - .map((item) => ({ - label: item.label, - values: Array.from(item.values), - })) - .slice(0, 3); -} - -function ctaKind(product: ProductResponse): 'view' | 'cart' { - return (product.variants?.length || 0) > 1 ? 'view' : 'cart'; -} - -export function QuickComparisonTable({ products }: QuickComparisonTableProps) { - const addToCart = useCartStore((state) => state.addToCart); - const [addedId, setAddedId] = useState(null); - - if (!products.length) return null; - - const handleAdd = async (product: ProductResponse) => { - const variant = product.variants?.[0]; - if (!variant) return; - await addToCart(product, variant, 1); - setAddedId(product.product_id); - setTimeout(() => setAddedId(null), 1800); - }; - - 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]'; - const cellCls = 'px-5 py-4 min-w-[170px] align-middle text-center'; - - return ( -
-

Quick Comparison

-
- - - - - ); - })} - - - - - - {products.map((prod) => ( - - ))} - - - - - {products.map((prod) => { - const kind = ctaKind(prod); - const justAdded = addedId === prod.product_id; - return ( - - ); - })} - - - - - {products.map((prod) => { - const attrs = extraAttributes(prod); - return ( - - ); - })} - - -
- {products.map((prod) => { - const img = productImage(prod); - return ( - - - {prod.name} - - - - -
Price - {priceLabel(prod)} -
Add to cart - {kind === 'view' ? ( - - View Products - - ) : ( - - )} -
Additional information - {attrs.length === 0 ? ( - — - ) : ( -
- {attrs.map((attr) => ( -
- {attr.label}: - {attr.values.map((value, i) => ( - - - {value} - - {i < attr.values.length - 1 ? , : null} - - ))} -
- ))} -
- )} -
-
-
- ); -} +'use client'; + +import { useState } from 'react'; +import { Check, ShoppingCart, ShieldCheck, FileText } from 'lucide-react'; +import BlurHashImage from '@/components/ui/BlurHashImage'; +import { ProductResponse, ProductVariantResponse } from '@/services/api/catalogService'; +import { useCartStore } from '@/store/cartStore'; +import { formatCurrency, getImageUrl } from '@/lib/utils'; + +interface QuickComparisonTableProps { + product: ProductResponse; +} + +function getVariantTitle(variant: ProductVariantResponse, fallbackIndex: number): string { + const validAttrs = (variant.attributes || []).filter((a) => { + const key = (a.attribute_name || a.attribute_code || '').toLowerCase().trim(); + return a.attribute_value && !['media_key', 'parent_media_key'].includes(key); + }); + + if (validAttrs.length > 0) { + return validAttrs + .map((a) => { + const name = a.attribute_name ? `${a.attribute_name}: ` : ''; + return `${name}${a.attribute_value}`; + }) + .join(' | '); + } + + return variant.sku || `Variant ${fallbackIndex + 1}`; +} + +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 [addedVariantId, setAddedVariantId] = useState(null); + + const variants = product?.variants || []; + // Strictly only show when the product has multiple variants (> 1) + if (variants.length <= 1) { + return null; + } + + const handleAdd = async (variant: ProductVariantResponse) => { + await addToCart(product, variant, 1); + setAddedVariantId(variant.variant_id); + setTimeout(() => setAddedVariantId(null), 1800); + }; + + const labelCls = + '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-[200px] align-middle text-center border-b border-gray-200'; + + return ( +
+
+

Variant Comparison

+ + {variants.length} Options + +
+ +
+ + {/* Variant Header Row */} + + + + {variants.map((v, idx) => { + const img = getVariantImage(product, v); + const title = getVariantTitle(v, idx); + return ( + + ); + })} + + + + + {/* 1. Name / Specifications Row */} + + + {variants.map((v, idx) => ( + + ))} + + + {/* 2. Price Row */} + + + {variants.map((v) => { + const price = Number(v.price) || 0; + 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 ( + + ); + })} + + + {/* 3. Warranty Type Row */} + + + {variants.map((v) => ( + + ))} + + + {/* 4. Summary Row */} + + + {variants.map((v) => ( + + ))} + + + {/* Action Row */} + + + {variants.map((v) => { + const justAdded = addedVariantId === v.variant_id; + const isOutOfStock = v.status === 'inactive' || (v.available_stock !== undefined && v.available_stock <= 0); + + return ( + + ); + })} + + +
Option +
+ +
+
+ {title} +
+
Name / Specification + {getVariantTitle(v, idx)} +
Price +
+ + {formatCurrency(price)} + + {hasDiscount && ( + <> + + {formatCurrency(comparePrice)} + + + {discountPercent}% OFF + + + )} +
+
+
+ + Warranty Type +
+
+ {product.warranty_type || 'Standard Warranty'} +
+
+ + Summary +
+
+ {product.warranty_summary || '100% Quality Tested & Brand Verified'} +
Action + +
+
+
+ ); +} diff --git a/services/api/catalogService.ts b/services/api/catalogService.ts index ea5f57a..e6ba0be 100644 --- a/services/api/catalogService.ts +++ b/services/api/catalogService.ts @@ -117,6 +117,8 @@ export interface ProductResponse { created_at: string; images: ProductImageResponse[]; variants: ProductVariantResponse[]; + warranty_type?: string | null; + warranty_summary?: string | null; rating?: number; review_count?: number; badge?: 'HOT' | 'NEW' | 'SALE' | null; diff --git a/services/api/serviceBooking.ts b/services/api/serviceBooking.ts index bcff09d..bb10261 100644 --- a/services/api/serviceBooking.ts +++ b/services/api/serviceBooking.ts @@ -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 { return apiFetch('/api/v1/storefront/layout/services'); },