Skip to main content

Sponsor & Ads Components

The Sponsor module manages sponsored item placements and user sponsorship management. It spans two component directories: sponsor-ads/ for display components and the context provider, and sponsorships/ for the user-facing sponsorship dashboard.

Architecture Overview

Source Files

FileDescription
sponsor-ads/index.tsBarrel exports
sponsor-ads/sponsor-ads-context.tsxProvider and context hook for active sponsors
sponsor-ads/sponsor-card.tsxRotating sponsor card with default/compact variants
sponsor-ads/sidebar-sponsor.tsxSidebar-optimised sponsor display
sponsor-ads/sponsor-badge.tsx"Sponsored" label badge
sponsor-ads/sponsor-form.tsxThree-step sponsor creation form

sponsorships/

FileDescription
sponsorships/index.tsBarrel exports
sponsorships/sponsorship-list.tsxSponsorship list with skeletons and empty state
sponsorships/sponsorship-item.tsxSingle sponsorship row with status and actions
sponsorships/sponsorship-stats-cards.tsxStats overview (total, active, pending, expired)
sponsorships/sponsorship-filters.tsxStatus tabs and search
sponsorships/sponsorship-detail-modal.tsxRead-only detail view
sponsorships/cancel-dialog.tsxCancellation confirmation
sponsorships/renew-dialog.tsxRenewal confirmation
sponsorships/constants.tsStatus config and helper functions

Components

SponsorAdsProvider

React context provider that fetches active sponsor ads and makes them available to child components.

import { SponsorAdsProvider } from "@/components/sponsor-ads";

<SponsorAdsProvider limit={10}>
<ItemDetailWrapper ... />
</SponsorAdsProvider>

Props:

PropTypeDefaultDescription
childrenReactNode--Child components
limitnumber10Maximum sponsors to fetch

The useSponsorAdsContext() hook returns { sponsors, isLoading, isError }. It gracefully returns empty data when used outside the provider.

SponsorCard

Displays a sponsored item card with automatic rotation when multiple sponsors are active.

import { SponsorCard } from "@/components/sponsor-ads";

<SponsorCard
sponsors={sponsors}
rotationInterval={5000}
variant="default"
/>

Props:

PropTypeDefaultDescription
sponsorsSponsorWithItem[]--Active sponsors with item data
rotationIntervalnumber5000Rotation interval in milliseconds
variant"default" | "compact""default"Card size variant
classNamestring?--Additional CSS classes

Features:

  • Time-based rotation through multiple sponsors.
  • Dot indicators for manual navigation between sponsors.
  • Icon with fallback, category badge, description, and tags.
  • Gradient backgrounds with hover animations.

SidebarSponsor

A sidebar-optimised sponsor display with a header, sponsor content card, and rotation dots.

<SidebarSponsor
sponsors={sponsors}
title="Featured Partner"
/>

Similar to SponsorCard but with a vertical layout designed for narrow sidebar columns. Includes a "Learn More" link with animated arrow.

SponsorBadge

A "Sponsored" label badge with three visual variants.

<SponsorBadge variant="default" size="md" showIcon={true} />
VariantVisual style
defaultFilled badge using the Badge component
compactSmall inline label with background
outlineBorder-only style

Sizes: sm, md, lg. The badge text is internationalised via sponsor.AD_LABEL.

SponsorForm

A three-step form for creating a new sponsorship:

StepContent
1. Select ItemSearchable dropdown of user's submitted items
2. Select DurationWeekly or monthly pricing cards
3. Summary & SubmitOrder summary with approval notice
<SponsorForm
items={userItems}
locale="en"
pricingConfig={{ weeklyPrice: 25, monthlyPrice: 75, currency: "USD" }}
onSuccess={handleSuccess}
/>

SponsorshipList / SponsorshipItem

Dashboard components for managing existing sponsorships. SponsorshipItem displays status, pricing, dates, and action buttons (Pay Now, Cancel, Renew, View Details).

Status configuration:

StatusColourAvailable actions
activeGreenCancel, Renew
pendingYellowCancel
pending_paymentOrangePay Now, Cancel
expiredGrayRenew
cancelledRed--

SponsorshipStatsCards

Four summary cards showing total, active, pending, and expired counts with colour-coded icons.

Data Flow

Integration Notes

  • SponsorAdsProvider is placed in ItemDetailWrapper so that sponsor cards appear in item detail sidebars.
  • The sponsor form requires the user to have at least one submitted item to sponsor.
  • All monetary values use formatCurrencyAmount for consistent locale-aware formatting.
  • Sponsorship management pages are typically mounted at /[locale]/client/sponsorships.
  • The constants.ts file contains SPONSOR_STATUS_CONFIG with icon, colour, and label mappings for each status.