import { createFileRoute, useNavigate } from '@tanstack/react-router' import { useState } from 'react' import { trpc } from '../lib/trpc-client' import { Tag, Loader2, AlertCircle } from 'lucide-react' import { ProductCard } from '../components/ProductCard' import { AppLayout } from '../components/AppLayout' import type { OffersSectionProps } from '@packages/shared' export const Route = createFileRoute('/offers')({ component: OffersPage }) const SHOW_MORE_STEP = 6 function OffersSection({ title, subtitle, products, expanded, onExpand, onProductPress }: OffersSectionProps) { const visible = expanded ? products : products.slice(0, SHOW_MORE_STEP) const hasMore = products.length > SHOW_MORE_STEP && !expanded return ( {title} {subtitle} {products.length === 0 ? ( No {title.toLowerCase()} available right now ) : ( <> {visible.map((item: any) => ( onProductPress(item.id)} showDeliveryInfo={false} miniView={true} useAddToCartDialog={true} /> ))} {hasMore && ( Show More )} > )} ) } function OffersPage() { const navigate = useNavigate() const [expandedOffers, setExpandedOffers] = useState(false) const [expandedCombos, setExpandedCombos] = useState(false) const { data, isLoading, error } = trpc.user.product.getOffersPage.useQuery() const combos = data?.combos || [] const offers = data?.offers || [] const handleProductPress = (id: number) => { navigate({ to: '/home/product/$id', params: { id: String(id) } }) } if (isLoading) { return ( Loading offers... ) } if (error) { return ( Failed to load offers. Please try again. ) } return ( Deals & Bundles Offers Great prices on select items setExpandedOffers(true)} onProductPress={handleProductPress} /> setExpandedCombos(true)} onProductPress={handleProductPress} /> ) }
{subtitle}
No {title.toLowerCase()} available right now
Loading offers...
Failed to load offers. Please try again.
Deals & Bundles
Great prices on select items