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-31883)[PRO] feat: add params selected_offers for archivage events #14259

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
@@ -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,30 @@ 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 = []

for (const offer of selectedOffers) {
collectiveOfferIds.push(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
Loading