diff --git a/apps/admin-x-settings/src/components/settings/growth/Offers.tsx b/apps/admin-x-settings/src/components/settings/growth/Offers.tsx
index ec0efd5add..6bf4a3c7fc 100644
--- a/apps/admin-x-settings/src/components/settings/growth/Offers.tsx
+++ b/apps/admin-x-settings/src/components/settings/growth/Offers.tsx
@@ -2,22 +2,63 @@ import React from 'react';
import TopLevelGroup from '../../TopLevelGroup';
import {Button, withErrorBoundary} from '@tryghost/admin-x-design-system';
import {CopyLinkButton} from './offers/OffersIndex';
+import {Tier, getPaidActiveTiers, useBrowseTiers} from '@tryghost/admin-x-framework/api/tiers';
import {checkStripeEnabled} from '@tryghost/admin-x-framework/api/settings';
+import {createRedemptionFilterUrl, getOfferDiscount} from './offers/OffersIndex';
+import {useBrowseOffers} from '@tryghost/admin-x-framework/api/offers';
import {useGlobalData} from '../../providers/GlobalDataProvider';
import {useRouting} from '@tryghost/admin-x-framework/routing';
+const OfferContainer: React.FC<{offerTitle: string, tier: Tier, cadence: string, redemptions: number, type: string, amount: number, currency: string, offerId: string, offerCode: string, goToOfferEdit: (offerId: string) => void}> = (
+ {offerTitle, tier, cadence, redemptions, type, amount, currency, offerId, offerCode, goToOfferEdit}) => {
+ const {discountColor, discountOffer} = getOfferDiscount(type, amount, cadence, currency || 'USD', tier);
+ return
goToOfferEdit(offerId)}>
+
{offerTitle}
+
+
{discountOffer}
+
+ {tier.name}
+ {cadence}
+
+
+
+
;
+};
+
const Offers: React.FC<{ keywords: string[] }> = ({keywords}) => {
const {updateRoute} = useRouting();
const {settings, config} = useGlobalData();
+ const {data: {offers: allOffers = []} = {}} = useBrowseOffers();
+
+ const {data: {tiers: allTiers} = {}} = useBrowseTiers();
+ const paidActiveTiers = getPaidActiveTiers(allTiers || []);
+
+ const activeOffers = allOffers.filter(offer => offer.status === 'active');
+
+ activeOffers.sort((a, b) => {
+ const dateA = a.created_at ? new Date(a.created_at) : new Date(0);
+ const dateB = b.created_at ? new Date(b.created_at) : new Date(0);
+ return dateB.getTime() - dateA.getTime();
+ });
+
+ const latestThree = activeOffers.slice(0, 3);
+
const openModal = () => {
updateRoute('offers/edit');
};
+ const goToOfferEdit = (offerId: string) => {
+ updateRoute(`offers/edit/${offerId}`);
+ };
+
return (
}
- description={<>Grow your audience by providing fixed or percentage discounts. Learn more>}
+ description={<>Grow your audience by providing fixed or percentage discounts. {allOffers.length === 0 && Learn more}>}
keywords={keywords}
navid='offers'
testId='offers'
@@ -25,52 +66,31 @@ const Offers: React.FC<{ keywords: string[] }> = ({keywords}) => {
>
-
-
Black Friday
-
-
20% off
-
- Bronze
- monthly
-
-
-
-
-
-
Cyber Monday
-
-
7 days free
-
- Silver
- yearly
-
-
-
-
-
-
Great Deal
-
-
$20 off
-
- Bronze
- yearly
-
-
-
-
+ {
+ latestThree.map((offer) => {
+ const offerTier = paidActiveTiers.find(tier => tier.id === offer?.tier.id);
+ if (!offerTier) {
+ return null;
+ }
+ return
;
+ })
+ }
-
+ {allOffers.length > 3 &&
-
+
}
);
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 3719d91583..1b2b7e4e9a 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
@@ -21,15 +21,15 @@ export const createRedemptionFilterUrl = (id: string): string => {
return `${baseHref}?filter=${encodeURIComponent('offer_redemptions:' + id)}`;
};
-const getOfferCadence = (cadence: string): string => {
+export const getOfferCadence = (cadence: string): string => {
return cadence === 'month' ? 'monthly' : 'yearly';
};
-const getOfferDuration = (duration: string): string => {
+export const getOfferDuration = (duration: string): string => {
return (duration === 'once' ? 'First payment' : duration === 'repeating' ? 'Repeating' : 'Forever');
};
-const getOfferDiscount = (type: string, amount: number, cadence: string, currency: string, tier: Tier | undefined): {discountColor: string, discountOffer: string, originalPriceWithCurrency: string, updatedPriceWithCurrency: string} => {
+export const getOfferDiscount = (type: string, amount: number, cadence: string, currency: string, tier: Tier | undefined): {discountColor: string, discountOffer: string, originalPriceWithCurrency: string, updatedPriceWithCurrency: string} => {
let discountColor = '';
let discountOffer = '';
const originalPrice = cadence === 'month' ? tier?.monthly_price ?? 0 : tier?.yearly_price ?? 0;