From f86d76ce5e0e0faee194e0d5993f94763bd1179e Mon Sep 17 00:00:00 2001 From: ahello-pass <185243577+ahello-pass@users.noreply.github.com> Date: Fri, 22 Nov 2024 12:42:04 +0100 Subject: [PATCH] (PC-32750)[PRO] feat: do not show create bookable offer button when offer is pending --- .../CollectiveOfferNavigation.tsx | 2 +- .../CollectiveOfferNavigation.spec.tsx | 18 +++- .../Cells/CollectiveActionsCells.tsx | 100 ++++++++++-------- .../__specs__/CollectiveActionsCells.spec.tsx | 19 +++- 4 files changed, 92 insertions(+), 47 deletions(-) diff --git a/pro/src/pages/CollectiveOffer/CollectiveOfferLayout/CollectiveOfferNavigation/CollectiveOfferNavigation.tsx b/pro/src/pages/CollectiveOffer/CollectiveOfferLayout/CollectiveOfferNavigation/CollectiveOfferNavigation.tsx index 835ba573499..77c3dbf039c 100644 --- a/pro/src/pages/CollectiveOffer/CollectiveOfferLayout/CollectiveOfferNavigation/CollectiveOfferNavigation.tsx +++ b/pro/src/pages/CollectiveOffer/CollectiveOfferLayout/CollectiveOfferNavigation/CollectiveOfferNavigation.tsx @@ -268,7 +268,7 @@ export const CollectiveOfferNavigation = ({ offer, CollectiveOfferTemplateAllowedAction.CAN_CREATE_BOOKABLE_OFFER ) - : isTemplate + : isTemplate && offer.displayedStatus !== CollectiveOfferDisplayedStatus.PENDING : false return isEditingExistingOffer ? ( diff --git a/pro/src/pages/CollectiveOffer/CollectiveOfferLayout/CollectiveOfferNavigation/__specs__/CollectiveOfferNavigation.spec.tsx b/pro/src/pages/CollectiveOffer/CollectiveOfferLayout/CollectiveOfferNavigation/__specs__/CollectiveOfferNavigation.spec.tsx index 12c6c1eca49..6f266433f33 100644 --- a/pro/src/pages/CollectiveOffer/CollectiveOfferLayout/CollectiveOfferNavigation/__specs__/CollectiveOfferNavigation.spec.tsx +++ b/pro/src/pages/CollectiveOffer/CollectiveOfferLayout/CollectiveOfferNavigation/__specs__/CollectiveOfferNavigation.spec.tsx @@ -363,11 +363,25 @@ describe('CollectiveOfferNavigation', () => { isCreatingOffer: false, }) - const duplicateOffer = screen.getByRole('button', { + const duplicateOfferButton = screen.getByRole('button', { name: 'Créer une offre réservable', }) - expect(duplicateOffer).toBeInTheDocument() + expect(duplicateOfferButton).toBeInTheDocument() + }) + + it('should not show create bookable offer button if template offer has pending status', () => { + renderCollectiveOfferNavigation({ + ...props, + isTemplate: true, + offer: { ...offer, displayedStatus: CollectiveOfferDisplayedStatus.PENDING } + }) + + const duplicateOffer = screen.queryByRole('button', { + name: 'Créer une offre réservable', + }) + + expect(duplicateOffer).not.toBeInTheDocument() }) it('should show create bookable offer if offer is template and ff is active', () => { diff --git a/pro/src/pages/Offers/OffersTable/Cells/CollectiveActionsCells.tsx b/pro/src/pages/Offers/OffersTable/Cells/CollectiveActionsCells.tsx index 102670ebb69..f8622e6070f 100644 --- a/pro/src/pages/Offers/OffersTable/Cells/CollectiveActionsCells.tsx +++ b/pro/src/pages/Offers/OffersTable/Cells/CollectiveActionsCells.tsx @@ -10,6 +10,7 @@ import { getErrorCode, isErrorAPIError } from 'apiClient/helpers' import { CollectiveBookingStatus, CollectiveOfferAllowedAction, + CollectiveOfferDisplayedStatus, CollectiveOfferResponseModel, CollectiveOfferStatus, CollectiveOfferTemplateAllowedAction, @@ -256,11 +257,20 @@ export const CollectiveActionsCells = ({ const canDuplicateOffer = areCollectiveNewStatusesEnabled ? isActionAllowedOnCollectiveOffer( offer, - offer.isShowcase - ? CollectiveOfferTemplateAllowedAction.CAN_CREATE_BOOKABLE_OFFER - : CollectiveOfferAllowedAction.CAN_DUPLICATE + CollectiveOfferAllowedAction.CAN_DUPLICATE + ) + : offer.displayedStatus !== CollectiveOfferDisplayedStatus.DRAFT + + const canCreateBookableOffer = areCollectiveNewStatusesEnabled + ? isActionAllowedOnCollectiveOffer( + offer, + CollectiveOfferTemplateAllowedAction.CAN_CREATE_BOOKABLE_OFFER ) - : offer.status !== CollectiveOfferStatus.DRAFT + : offer.isShowcase && + ![ + CollectiveOfferDisplayedStatus.DRAFT, + CollectiveOfferDisplayedStatus.PENDING, + ].includes(offer.displayedStatus) const canArchiveOffer = areCollectiveNewStatusesEnabled ? isActionAllowedOnCollectiveOffer( @@ -287,7 +297,11 @@ export const CollectiveActionsCells = ({ const noActionsAllowed = areCollectiveNewStatusesEnabled ? offer.allowedActions.length === 0 - : offer.isShowcase && offer.status === CollectiveOfferStatus.ARCHIVED + : offer.isShowcase && + [ + CollectiveOfferDisplayedStatus.ARCHIVED, + CollectiveOfferDisplayedStatus.PENDING, + ].includes(offer.displayedStatus) const canEditOffer = areCollectiveNewStatusesEnabled ? hasOfferAnyEditionActionAllowed(offer) @@ -295,15 +309,15 @@ export const CollectiveActionsCells = ({ !offer.isPublicApi && offer.status !== CollectiveOfferStatus.ARCHIVED - const isBookingCancellable = - areCollectiveNewStatusesEnabled ? - isActionAllowedOnCollectiveOffer(offer,CollectiveOfferAllowedAction.CAN_CANCEL) - : offer.status === CollectiveOfferStatus.SOLD_OUT && - offer.booking && - (offer.booking.booking_status === - CollectiveBookingStatus.PENDING || - offer.booking.booking_status === - CollectiveBookingStatus.CONFIRMED) + const isBookingCancellable = areCollectiveNewStatusesEnabled + ? isActionAllowedOnCollectiveOffer( + offer, + CollectiveOfferAllowedAction.CAN_CANCEL + ) + : offer.status === CollectiveOfferStatus.SOLD_OUT && + offer.booking && + (offer.booking.booking_status === CollectiveBookingStatus.PENDING || + offer.booking.booking_status === CollectiveBookingStatus.CONFIRMED) const offerActivationWording = 'Votre offre est maintenant active et visible dans ADAGE' @@ -403,13 +417,18 @@ export const CollectiveActionsCells = ({ className={styles['menu-item']} onSelect={handleCreateOfferClick} > - + + )} + {canCreateBookableOffer && ( + + )} @@ -451,28 +470,25 @@ export const CollectiveActionsCells = ({ )} {isBookingCancellable && ( - <> - - setIsCancelledBookingModalOpen(true)} - asChild + <> + + setIsCancelledBookingModalOpen(true)} + asChild + > + - - - )} + Annuler la réservation + + + + )} {canArchiveOffer && ( <> { renderCollectiveActionsCell({ offer: collectiveOfferFactory({ isShowcase: true, - status: CollectiveOfferStatus.DRAFT, + displayedStatus: CollectiveOfferDisplayedStatus.DRAFT, + }), + }) + + await userEvent.click(screen.getByTitle('Action')) + + expect( + screen.queryByText('Créer une offre réservable') + ).not.toBeInTheDocument() + }) + + it('should not display duplicate button for pending template offer', async () => { + renderCollectiveActionsCell({ + offer: collectiveOfferFactory({ + isShowcase: true, + displayedStatus: CollectiveOfferDisplayedStatus.PENDING, }), }) @@ -185,7 +200,7 @@ describe('CollectiveActionsCells', () => { it('should not display duplicate button for draft bookable offer', async () => { renderCollectiveActionsCell({ offer: collectiveOfferFactory({ - status: CollectiveOfferStatus.DRAFT, + displayedStatus: CollectiveOfferDisplayedStatus.DRAFT, }), })