diff --git a/pro/src/components/ArchiveConfirmationModal/ArchiveConfirmationModal.tsx b/pro/src/components/ArchiveConfirmationModal/ArchiveConfirmationModal.tsx index 809332432f9..55ae3f8c67a 100644 --- a/pro/src/components/ArchiveConfirmationModal/ArchiveConfirmationModal.tsx +++ b/pro/src/components/ArchiveConfirmationModal/ArchiveConfirmationModal.tsx @@ -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' @@ -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() } diff --git a/pro/src/pages/Offers/OffersTable/CollectiveOffersTable/CollectiveOffersActionsBar/CollectiveOffersActionsBar.tsx b/pro/src/pages/Offers/OffersTable/CollectiveOffersTable/CollectiveOffersActionsBar/CollectiveOffersActionsBar.tsx index c70d48716ae..23b97da7c25 100644 --- a/pro/src/pages/Offers/OffersTable/CollectiveOffersTable/CollectiveOffersActionsBar/CollectiveOffersActionsBar.tsx +++ b/pro/src/pages/Offers/OffersTable/CollectiveOffersTable/CollectiveOffersActionsBar/CollectiveOffersActionsBar.tsx @@ -301,6 +301,7 @@ export function CollectiveOffersActionsBar({ updateOfferStatus(CollectiveOfferDisplayedStatus.ARCHIVED) } hasMultipleOffers={selectedOffers.length > 1} + selectedOffers={selectedOffers} /> )} diff --git a/pro/src/pages/Offers/OffersTable/CollectiveOffersTable/CollectiveOffersActionsBar/__specs__/CollectiveOffersActionsBar.spec.tsx b/pro/src/pages/Offers/OffersTable/CollectiveOffersTable/CollectiveOffersActionsBar/__specs__/CollectiveOffersActionsBar.spec.tsx index 64be607b97b..5f8610b7fa0 100644 --- a/pro/src/pages/Offers/OffersTable/CollectiveOffersTable/CollectiveOffersActionsBar/__specs__/CollectiveOffersActionsBar.spec.tsx +++ b/pro/src/pages/Offers/OffersTable/CollectiveOffersTable/CollectiveOffersActionsBar/__specs__/CollectiveOffersActionsBar.spec.tsx @@ -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,