diff --git a/apps/admin-x-settings/src/components/providers/SettingsRouter.tsx b/apps/admin-x-settings/src/components/providers/SettingsRouter.tsx index 2586869c59..2dabecea8f 100644 --- a/apps/admin-x-settings/src/components/providers/SettingsRouter.tsx +++ b/apps/admin-x-settings/src/components/providers/SettingsRouter.tsx @@ -33,7 +33,7 @@ export const modalPaths: {[key: string]: ModalName} = { 'embed-signup-form/show': 'EmbedSignupFormModal', 'offers/edit': 'OffersModal', 'offers/new': 'AddOfferModal', - 'offers/success': 'OfferSuccess', + 'offers/success/:id': 'OfferSuccess', 'offers/:id': 'EditOfferModal', about: 'AboutModal' }; diff --git a/apps/admin-x-settings/src/components/settings/growth/offers/AddOfferModal.tsx b/apps/admin-x-settings/src/components/settings/growth/offers/AddOfferModal.tsx index b758d46246..08e410fa1a 100644 --- a/apps/admin-x-settings/src/components/settings/growth/offers/AddOfferModal.tsx +++ b/apps/admin-x-settings/src/components/settings/growth/offers/AddOfferModal.tsx @@ -260,7 +260,7 @@ const AddOfferModal = () => { cadence: formState.cadence, amount: formState.type === 'trial' ? Number(getDiscountAmount(formState.trialAmount, formState.amountType)) : Number(getDiscountAmount(formState.discountAmount, formState.amountType)), duration: formState.type === 'trial' ? 'trial' : formState.duration, - duration_in_months: formState.durationInMonths, + duration_in_months: Number(formState.durationInMonths), currency: formState.currency, status: formState.status, tier: { @@ -274,7 +274,7 @@ const AddOfferModal = () => { if (response && response.offers && response.offers.length > 0) { modal.remove(); - updateRoute(`offers/${response.offers[0].id}`); + updateRoute(`offers/success/${response.offers[0].id}`); } }, onSaveError: () => {}, diff --git a/apps/admin-x-settings/src/components/settings/growth/offers/OfferSuccess.tsx b/apps/admin-x-settings/src/components/settings/growth/offers/OfferSuccess.tsx index ce2f873313..2a5f85875f 100644 --- a/apps/admin-x-settings/src/components/settings/growth/offers/OfferSuccess.tsx +++ b/apps/admin-x-settings/src/components/settings/growth/offers/OfferSuccess.tsx @@ -1,8 +1,40 @@ import NiceModal from '@ebay/nice-modal-react'; import {Button} from '@tryghost/admin-x-design-system'; import {Modal} from '@tryghost/admin-x-design-system'; +import {RoutingModalProps} from '@tryghost/admin-x-framework/routing'; +import {getHomepageUrl} from '@tryghost/admin-x-framework/api/site'; +import {useBrowseOffersById} from '@tryghost/admin-x-framework/api/offers'; +import {useEffect, useState} from 'react'; +import {useGlobalData} from '../../../providers/GlobalDataProvider'; +const OfferSuccess: React.FC = ({params}) => { + // const {updateRoute} = useRouting(); + const {data: {offers: offerById = []} = {}} = useBrowseOffersById(params?.id ? params?.id : ''); -const OfferSuccess = () => { + const [offerLink, setOfferLink] = useState(''); + + const {siteData} = useGlobalData(); + + useEffect(() => { + if (offerById.length > 0) { + const offer = offerById[0]; + const offerUrl = `${getHomepageUrl(siteData!)}${offer?.code}`; + setOfferLink(offerUrl); + } + }, [offerById, siteData]); + + const [isCopied, setIsCopied] = useState(false); + + const handleCopyClick = async () => { + try { + await navigator.clipboard.writeText(offerLink); + setIsCopied(true); + setTimeout(() => setIsCopied(false), 1000); // reset after 1 seconds + } catch (err) { + // eslint-disable-next-line no-console + console.error('Failed to copy text: ', err); + } + }; + return {

Your new offer is live!

You can share the link anywhere. In your newsletter, social media, a podcast, or in-person. It all just works.

-