Skip to content

Commit

Permalink
(PC-31883)[PRO] feat: add params selected_offers for archivage events
Browse files Browse the repository at this point in the history
  • Loading branch information
smokhtari-passculture committed Sep 23, 2024
1 parent db40516 commit 47c3dda
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useLocation } from 'react-router-dom'

import { CollectiveOfferResponseModel } from 'apiClient/v1'
import { useAnalytics } from 'app/App/analytics/firebase'
import { ConfirmDialog } from 'components/Dialog/ConfirmDialog/ConfirmDialog'
import { Events } from 'core/FirebaseEvents/constants'
Expand All @@ -9,20 +10,28 @@ interface OfferEducationalModalProps {
onDismiss(): void
onValidate(): void
hasMultipleOffers?: boolean
selectedOffers?: CollectiveOfferResponseModel[]
}

export const ArchiveConfirmationModal = ({
onDismiss,
onValidate,
hasMultipleOffers = false,
selectedOffers = [],
}: OfferEducationalModalProps): JSX.Element => {
const location = useLocation()
const { logEvent } = useAnalytics()

function onConfirmArchive() {
const collectiveOfferIds = selectedOffers.map((offer) =>
offer.id.toString()
)

logEvent(Events.CLICKED_ARCHIVE_COLLECTIVE_OFFER, {
from: location.pathname,
selected_offers: collectiveOfferIds,
})

onValidate()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ export function CollectiveOffersActionsBar({
updateOfferStatus(CollectiveOfferDisplayedStatus.ARCHIVED)
}
hasMultipleOffers={selectedOffers.length > 1}
selectedOffers={selectedOffers}
/>
)}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,41 @@ describe('ActionsBar', () => {
})
})

it('should call tracker event when archiving an offer', async () => {
renderActionsBar({
...props,
selectedOffers: [
collectiveOfferFactory({
id: 1,
status: CollectiveOfferStatus.ACTIVE,
stocks,
}),
collectiveOfferFactory({
id: 2,
status: CollectiveOfferStatus.ACTIVE,
stocks,
isShowcase: true,
}),
],
})

const archivingButton = screen.getByText('Archiver')
await userEvent.click(archivingButton)

const confirmArchivingButton = screen.getByText('Archiver les offres')
await userEvent.click(confirmArchivingButton)

expect(mockLogEvent).toHaveBeenCalledTimes(1)
expect(mockLogEvent).toHaveBeenNthCalledWith(
1,
Events.CLICKED_ARCHIVE_COLLECTIVE_OFFER,
{
from: '/offres/collectives',
selected_offers: ['1', '2'],
}
)
})

it('should archive offers on click on "Archiver"', async () => {
renderActionsBar({
...props,
Expand Down

0 comments on commit 47c3dda

Please sign in to comment.