diff --git a/apps/admin-x-settings/src/components/settings/growth/offers/OffersIndex.tsx b/apps/admin-x-settings/src/components/settings/growth/offers/OffersIndex.tsx index f3a9a5b5d2..7e94314f87 100644 --- a/apps/admin-x-settings/src/components/settings/growth/offers/OffersIndex.tsx +++ b/apps/admin-x-settings/src/components/settings/growth/offers/OffersIndex.tsx @@ -132,14 +132,30 @@ export const OffersIndexModal = () => { ]; const [selectedTab, setSelectedTab] = useState('active'); const [selectedLayout, setSelectedLayout] = useState('card'); + const [sortOption, setSortOption] = useState('date-added'); + const [sortDirection, setSortDirection] = useState('desc'); const handleOfferEdit = (id:string) => { // TODO: implement updateRoute(`offers/edit/${id}`); }; + const sortedOffers = allOffers + .sort((offer1, offer2) => { + const multiplier = sortDirection === 'desc' ? -1 : 1; + switch (sortOption) { + case 'name': + return multiplier * offer1.name.localeCompare(offer2.name); + case 'redemptions': + return multiplier * (offer1.redemption_count - offer2.redemption_count); + default: + // 'date-added' or unknown option, use default sorting + return multiplier * ((offer1.created_at ? new Date(offer1.created_at).getTime() : 0) - (offer2.created_at ? new Date(offer2.created_at).getTime() : 0)); + } + }); + const cardLayoutOutput =
{allOffers.length} {allOffers.length > 1 ? 'offers' : 'offer'} | +{sortedOffers.length} {sortedOffers.length > 1 ? 'offers' : 'offer'} | Tier | Terms | Price | Redemptions |
---|