6d576bad40
Build all 8 primary screens for CAR-33 on top of the Phase 1 scaffold: - Auth: login, register, forgot password with JWT flow and mock fallback - Dashboard: triggered alerts banner, spending stats, price trend sparklines (Recharts), recent purchases - Purchase History: store filter chips, paginated list with item previews - Purchase Detail: receipt view with line items linking to product pages - Products: search with instant filter, store price comparison badges - Product Detail: 90-day price history chart (Recharts), store comparison table - Store Comparison: ranked store cards with savings banner - Price Alerts: triggered/watching sections, create form, progress bars, delete - Coupons: expiration warnings, copy-to-clipboard coupon codes - Account Linking: connect Meijer/Kroger/Target with status indicators - Settings: profile, connected stores, notification toggles, theme switcher, sign out Also adds: - Mock data layer (src/lib/mock-data.ts) for demo/screenshot use - StoreIcon component with store brand colors - Code-split Recharts chunk (initial JS: 117KB, Recharts lazy: 498KB) - All 48px+ touch targets, mobile-first Tailwind layout Co-Authored-By: Paperclip <noreply@paperclip.ing>
94 lines
3.4 KiB
TypeScript
94 lines
3.4 KiB
TypeScript
import { useParams, Link } from 'react-router-dom'
|
|
import { mockProducts } from '../lib/mock-data.ts'
|
|
import { StoreIcon } from '../components/StoreIcon.tsx'
|
|
|
|
export function StoreComparison() {
|
|
const { productId } = useParams<{ productId: string }>()
|
|
const product = mockProducts.find((p) => p.id === productId)
|
|
|
|
if (!product) {
|
|
return (
|
|
<div className="py-8 text-center">
|
|
<p className="text-sm text-gray-500">Product not found.</p>
|
|
<Link to="/products" className="mt-4 inline-block text-sm text-brand-blue">
|
|
Back to products
|
|
</Link>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
const sorted = product.prices.slice().sort((a, b) => a.price - b.price)
|
|
const lowestPrice = sorted[0]?.price ?? 0
|
|
const savings = sorted.length > 1 ? sorted[sorted.length - 1].price - sorted[0].price : 0
|
|
|
|
return (
|
|
<div>
|
|
{/* Back link */}
|
|
<Link to={`/products/${product.id}`} className="inline-flex items-center gap-1 text-sm text-brand-blue">
|
|
<svg className="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
|
|
<path strokeLinecap="round" strokeLinejoin="round" d="M15 19l-7-7 7-7" />
|
|
</svg>
|
|
{product.name}
|
|
</Link>
|
|
|
|
<h1 className="mt-4 text-2xl font-bold text-gray-900">Store Comparison</h1>
|
|
<p className="mt-1 text-sm text-gray-500">{product.name} · {product.brand}</p>
|
|
|
|
{/* Savings banner */}
|
|
{savings > 0 && (
|
|
<div className="mt-4 rounded-xl bg-green-50 p-4">
|
|
<p className="text-sm font-semibold text-green-800">
|
|
Save ${savings.toFixed(2)} by shopping at {sorted[0].storeName}
|
|
</p>
|
|
</div>
|
|
)}
|
|
|
|
{/* Store comparison cards */}
|
|
<div className="mt-4 space-y-3">
|
|
{sorted.map((pp, idx) => (
|
|
<div
|
|
key={pp.storeId}
|
|
className={`rounded-xl p-4 shadow-sm ${
|
|
idx === 0 ? 'border-2 border-green-400 bg-white' : 'bg-white'
|
|
}`}
|
|
>
|
|
<div className="flex items-center gap-3">
|
|
<StoreIcon storeId={pp.storeId} />
|
|
<div className="min-w-0 flex-1">
|
|
<p className="text-sm font-medium text-gray-900">{pp.storeName}</p>
|
|
<p className="text-xs text-gray-500">
|
|
Updated{' '}
|
|
{new Date(pp.lastUpdated).toLocaleDateString('en-US', {
|
|
month: 'short',
|
|
day: 'numeric',
|
|
})}
|
|
</p>
|
|
</div>
|
|
<div className="text-right">
|
|
<p
|
|
className={`text-lg font-bold ${
|
|
pp.price === lowestPrice ? 'text-green-700' : 'text-gray-900'
|
|
}`}
|
|
>
|
|
${pp.price.toFixed(2)}
|
|
</p>
|
|
{pp.price === lowestPrice ? (
|
|
<span className="text-xs font-medium text-green-600">Best price</span>
|
|
) : (
|
|
<span className="text-xs text-gray-400">
|
|
+${(pp.price - lowestPrice).toFixed(2)}
|
|
</span>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
|
|
<p className="mt-6 text-center text-xs text-gray-400">
|
|
Prices last verified from store loyalty card data. Map view coming soon.
|
|
</p>
|
|
</div>
|
|
)
|
|
}
|