Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(PC-32750)[PRO] feat: do not show create bookable offer button when offer is pending #15188

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export const CollectiveOfferNavigation = ({
offer,
CollectiveOfferTemplateAllowedAction.CAN_CREATE_BOOKABLE_OFFER
)
: isTemplate
: isTemplate && offer.displayedStatus !== CollectiveOfferDisplayedStatus.PENDING
: false

return isEditingExistingOffer ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
100 changes: 58 additions & 42 deletions pro/src/pages/Offers/OffersTable/Cells/CollectiveActionsCells.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { getErrorCode, isErrorAPIError } from 'apiClient/helpers'
import {
CollectiveBookingStatus,
CollectiveOfferAllowedAction,
CollectiveOfferDisplayedStatus,
CollectiveOfferResponseModel,
CollectiveOfferStatus,
CollectiveOfferTemplateAllowedAction,
Expand Down Expand Up @@ -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(
Expand All @@ -287,23 +297,27 @@ 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)
: offer.isEditable &&
!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'
Expand Down Expand Up @@ -403,13 +417,18 @@ export const CollectiveActionsCells = ({
className={styles['menu-item']}
onSelect={handleCreateOfferClick}
>
<Button
icon={offer.isShowcase ? fullPlusIcon : fullCopyIcon}
variant={ButtonVariant.TERNARY}
>
{offer.isShowcase
? 'Créer une offre réservable'
: 'Dupliquer'}
<Button icon={fullCopyIcon} variant={ButtonVariant.TERNARY}>
Dupliquer
</Button>
</DropdownMenu.Item>
)}
{canCreateBookableOffer && (
<DropdownMenu.Item
className={styles['menu-item']}
onSelect={handleCreateOfferClick}
>
<Button icon={fullPlusIcon} variant={ButtonVariant.TERNARY}>
Créer une offre réservable
</Button>
</DropdownMenu.Item>
)}
Expand Down Expand Up @@ -451,28 +470,25 @@ export const CollectiveActionsCells = ({
</DropdownMenu.Item>
)}
{isBookingCancellable && (
<>
<DropdownMenu.Separator
className={cn(
styles['separator'],
styles['tablet-only']
)}
/>
<DropdownMenu.Item
className={cn(styles['menu-item'])}
onSelect={() => setIsCancelledBookingModalOpen(true)}
asChild
<>
<DropdownMenu.Separator
className={cn(styles['separator'], styles['tablet-only'])}
/>
<DropdownMenu.Item
className={cn(styles['menu-item'])}
onSelect={() => setIsCancelledBookingModalOpen(true)}
asChild
>
<Button
icon={fullClearIcon}
variant={ButtonVariant.QUATERNARYPINK}
className={styles['button-cancel-booking']}
>
<Button
icon={fullClearIcon}
variant={ButtonVariant.QUATERNARYPINK}
className={styles['button-cancel-booking']}
>
Annuler la réservation
</Button>
</DropdownMenu.Item>
</>
)}
Annuler la réservation
</Button>
</DropdownMenu.Item>
</>
)}
{canArchiveOffer && (
<>
<DropdownMenu.Separator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,22 @@ describe('CollectiveActionsCells', () => {
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,
}),
})

Expand All @@ -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,
}),
})

Expand Down
Loading