From 7d530406f6119f93addd67c7022691f874bd178c Mon Sep 17 00:00:00 2001 From: Princi Vershwal Date: Wed, 13 Dec 2023 11:18:48 +0530 Subject: [PATCH] Add offer cancel button fix (#19348) Ref [PROD-213](https://linear.app/tryghost/issue/PROD-213/cancelling-should-act-two-ways-when-the-modal-is-opened-from-the-list) --- .../components/settings/growth/offers/AddOfferModal.tsx | 9 ++++++++- .../settings/growth/offers/OffersContainerModal.tsx | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) 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 b29560e085..0581e8fc57 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 @@ -8,6 +8,7 @@ import {getOfferPortalPreviewUrl, offerPortalPreviewUrlTypes} from '../../../../ import {getPaidActiveTiers, useBrowseTiers} from '@tryghost/admin-x-framework/api/tiers'; import {getTiersCadences} from '../../../../utils/getTiersCadences'; import {useAddOffer} from '@tryghost/admin-x-framework/api/offers'; +import {useBrowseOffers} from '@tryghost/admin-x-framework/api/offers'; import {useEffect, useMemo, useState} from 'react'; import {useGlobalData} from '../../../providers/GlobalDataProvider'; import {useModal} from '@ebay/nice-modal-react'; @@ -364,6 +365,8 @@ const AddOfferModal = () => { } }); + const {data: {offers: allOffers = []} = {}} = useBrowseOffers(); + const {formState, updateForm, handleSave, saveState, okProps, validate, errors, clearError} = useForm({ initialState: { disableBackground: false, @@ -592,7 +595,11 @@ const AddOfferModal = () => { }, [hasOffers, modal, updateRoute]); const cancelAddOffer = () => { - updateRoute('offers/edit'); + if (allOffers.length > 0) { + updateRoute('offers/edit'); + } else { + updateRoute('offers'); + } }; const overrides : offerPortalPreviewUrlTypes = useMemo(() => { diff --git a/apps/admin-x-settings/src/components/settings/growth/offers/OffersContainerModal.tsx b/apps/admin-x-settings/src/components/settings/growth/offers/OffersContainerModal.tsx index de729811ae..e5e6e046d1 100644 --- a/apps/admin-x-settings/src/components/settings/growth/offers/OffersContainerModal.tsx +++ b/apps/admin-x-settings/src/components/settings/growth/offers/OffersContainerModal.tsx @@ -18,7 +18,7 @@ const OffersRouteHandler: React.FC = ({route}) => { } else if (route.startsWith('offers/success/') && route.length > 'offers/success/'.length) { const offerId = route.split('/').pop(); return ; - } else { + } else if (route === 'offers/edit') { return ; } };