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)
This commit is contained in:
parent
c90e033fcf
commit
7d530406f6
@ -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(() => {
|
||||
|
@ -18,7 +18,7 @@ const OffersRouteHandler: React.FC<OffersRouteHandlerProps> = ({route}) => {
|
||||
} else if (route.startsWith('offers/success/') && route.length > 'offers/success/'.length) {
|
||||
const offerId = route.split('/').pop();
|
||||
return <OfferSuccess id={offerId ? offerId : ''} />;
|
||||
} else {
|
||||
} else if (route === 'offers/edit') {
|
||||
return <OffersIndexModal />;
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user