Skip to content

Commit

Permalink
Revert "(PC-30088)[PRO] feat: clean summary page eac link"
Browse files Browse the repository at this point in the history
This reverts commit 3c24aea.
  • Loading branch information
gmeigniez-pass authored and smokhtari-passculture committed Jul 2, 2024
1 parent dddd480 commit f971185
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import cn from 'classnames'
import { useNavigate } from 'react-router-dom'
import { useLocation, useNavigate } from 'react-router-dom'

import { useAnalytics } from 'app/App/analytics/firebase'
import { Step, Stepper } from 'components/Stepper/Stepper'
Expand All @@ -11,6 +11,8 @@ import { computeURLCollectiveOfferId } from 'core/OfferEducational/utils/compute
import { createOfferFromTemplate } from 'core/OfferEducational/utils/createOfferFromTemplate'
import { useActiveFeature } from 'hooks/useActiveFeature'
import { useNotification } from 'hooks/useNotification'
import { useOfferStockEditionURL } from 'hooks/useOfferEditionURL'
import fullEditIcon from 'icons/full-edit.svg'
import fullMoreIcon from 'icons/full-more.svg'
import fullShowIcon from 'icons/full-show.svg'
import { Button } from 'ui-kit/Button/Button'
Expand Down Expand Up @@ -52,21 +54,45 @@ export const CollectiveOfferNavigation = ({
const { logEvent } = useAnalytics()
const notify = useNotification()
const navigate = useNavigate()

const location = useLocation()
const isMarseilleActive = useActiveFeature('WIP_ENABLE_MARSEILLE')

const offerEditLink = `/offre/${computeURLCollectiveOfferId(
offerId,
isTemplate
)}/collectif/edition`

const previewLink = `/offre/${computeURLCollectiveOfferId(
offerId,
isTemplate
)}/collectif${isTemplate ? '/vitrine' : ''}/apercu`

const stockEditionUrl = useOfferStockEditionURL(true, offerId)
const isEditingExistingOffer = !(isCreatingOffer || isCompletingDraft)

const stepList: { [key in CollectiveOfferStep]?: Step } = {}

const requestIdUrl = requestId ? `?requete=${requestId}` : ''

if (!isEditingExistingOffer) {
if (isEditingExistingOffer) {
if (!isTemplate) {
stepList[CollectiveOfferStep.DETAILS] = {
id: CollectiveOfferStep.DETAILS,
label: 'Détails de l’offre',
url: `/offre/${offerId}/collectif/edition`,
}
stepList[CollectiveOfferStep.STOCKS] = {
id: CollectiveOfferStep.STOCKS,
label: 'Dates et prix',
url: stockEditionUrl,
}
stepList[CollectiveOfferStep.VISIBILITY] = {
id: CollectiveOfferStep.VISIBILITY,
label: 'Établissement et enseignant',
url: `/offre/${offerId}/collectif/visibilite/edition`,
}
}
} else {
stepList[CollectiveOfferStep.DETAILS] = {
id: CollectiveOfferStep.DETAILS,
label: 'Détails de l’offre',
Expand Down Expand Up @@ -94,55 +120,49 @@ export const CollectiveOfferNavigation = ({
id: CollectiveOfferStep.CONFIRMATION,
label: 'Confirmation',
}
}

// Steps witout url will be displayed as disabeld in the stepper,
// that's why we need to add url only to the current step and the previeous steps
// Steps witout url will be displayed as disabeld in the stepper,
// that's why we need to add url only to the current step and the previeous steps

// Add clickable urls depending on current completion
// Switch fallthrough is intended, this is precisely the kind of use case for it
/* eslint-disable no-fallthrough */
switch (activeStep) {
// @ts-expect-error switch fallthrough
case CollectiveOfferStep.CONFIRMATION:
if (stepList[CollectiveOfferStep.PREVIEW]) {
// Add clickable urls depending on current completion
// Switch fallthrough is intended, this is precisely the kind of use case for it
/* eslint-disable no-fallthrough */
switch (activeStep) {
// @ts-expect-error switch fallthrough
case CollectiveOfferStep.CONFIRMATION:
stepList[CollectiveOfferStep.PREVIEW].url = isTemplate
? `/offre/${offerId}/collectif/vitrine/creation/apercu`
: `/offre/${offerId}/collectif/creation/apercu`
}

// @ts-expect-error switch fallthrough
case CollectiveOfferStep.PREVIEW:
if (stepList[CollectiveOfferStep.SUMMARY]) {
// @ts-expect-error switch fallthrough
case CollectiveOfferStep.PREVIEW:
stepList[CollectiveOfferStep.SUMMARY].url = isTemplate
? `/offre/${offerId}/collectif/vitrine/creation/recapitulatif`
: `/offre/${offerId}/collectif/creation/recapitulatif`
}

// @ts-expect-error switch fallthrough
case CollectiveOfferStep.SUMMARY:
if (!isTemplate && stepList[CollectiveOfferStep.VISIBILITY]) {
stepList[CollectiveOfferStep.VISIBILITY].url =
`/offre/${offerId}/collectif/visibilite`
}

// @ts-expect-error switch fallthrough
case CollectiveOfferStep.VISIBILITY:
if (!isTemplate && stepList[CollectiveOfferStep.STOCKS]) {
stepList[CollectiveOfferStep.STOCKS].url =
`/offre/${offerId}/collectif/stocks`
}

// @ts-expect-error switch fallthrough
case CollectiveOfferStep.STOCKS:
if (stepList[CollectiveOfferStep.DETAILS]) {
// @ts-expect-error switch fallthrough
case CollectiveOfferStep.SUMMARY:
if (!isTemplate && stepList[CollectiveOfferStep.VISIBILITY]) {
stepList[CollectiveOfferStep.VISIBILITY].url =
`/offre/${offerId}/collectif/visibilite`
}

// @ts-expect-error switch fallthrough
case CollectiveOfferStep.VISIBILITY:
if (!isTemplate && stepList[CollectiveOfferStep.STOCKS]) {
stepList[CollectiveOfferStep.STOCKS].url =
`/offre/${offerId}/collectif/stocks`
}

// @ts-expect-error switch fallthrough
case CollectiveOfferStep.STOCKS:
stepList[CollectiveOfferStep.DETAILS].url = isTemplate
? `/offre/collectif/vitrine/${offerId}/creation`
: `/offre/collectif/${offerId}/creation${requestIdUrl}`
}

case CollectiveOfferStep.DETAILS:
// Nothing to do here
case CollectiveOfferStep.DETAILS:
// Nothing to do here
}
}

const steps = Object.values(stepList)
Expand All @@ -155,6 +175,17 @@ export const CollectiveOfferNavigation = ({
return isEditingExistingOffer ? (
<>
<div className={styles['duplicate-offer']}>
{!location.pathname.includes('edition') && (
<ButtonLink
link={{
to: offerEditLink,
isExternal: false,
}}
icon={fullEditIcon}
>
Modifier l’offre
</ButtonLink>
)}
<ButtonLink
link={{
to: previewLink,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,28 @@ describe('CollectiveOfferNavigation', () => {
props.isCreatingOffer = false
renderCollectiveOfferNavigation(props)

expect(
screen.getByRole('link', { name: 'Dates et prix' })
).toBeInTheDocument()

const linkItems = await screen.findAllByRole('link')

expect(linkItems).toHaveLength(5)
expect(linkItems[0].getAttribute('href')).toBe(
`/offre/${offerId}/collectif/edition`
)
expect(linkItems[1].getAttribute('href')).toBe(
`/offre/${offerId}/collectif/apercu`
)
expect(linkItems[2].getAttribute('href')).toBe(
`/offre/${offerId}/collectif/edition`
)
expect(linkItems[3].getAttribute('href')).toBe(
`/offre/${offerId}/collectif/stocks/edition`
)
expect(linkItems[4].getAttribute('href')).toBe(
`/offre/${offerId}/collectif/visibilite/edition`
)
})

it('should log event when clicking duplicate offer button', async () => {
Expand Down

0 comments on commit f971185

Please sign in to comment.