Skip to content

Commit

Permalink
(PC-33377)[PRO] feat: Removes wildcard + nested <Routes> inside venue…
Browse files Browse the repository at this point in the history
…s edition
  • Loading branch information
jclery-pass committed Jan 10, 2025
1 parent e23f1c7 commit c647d3a
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 38 deletions.
17 changes: 16 additions & 1 deletion pro/src/app/AppRouter/routesMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,24 @@ export const routes: RouteConfig[] = [
},
{
lazy: () => import('pages/VenueEdition/VenueEdition'),
path: '/structures/:offererId/lieux/:venueId/*',
path: '/structures/:offererId/lieux/:venueId',
title: 'Gérer ma page sur l’application',
},
{
lazy: () => import('pages/VenueEdition/VenueEdition'),
path: '/structures/:offererId/lieux/:venueId/edition',
title: 'Gérer ma page sur l’application',
},
{
lazy: () => import('pages/VenueEdition/VenueEdition'),
path: '/structures/:offererId/lieux/:venueId/collectif',
title: 'Gérer ma page sur ADAGE',
},
{
lazy: () => import('pages/VenueEdition/VenueEdition'),
path: '/structures/:offererId/lieux/:venueId/collectif/edition',
title: 'Gérer ma page sur ADAGE',
},
{
lazy: () => import('pages/VenueSettings/VenueSettings'),
path: '/structures/:offererId/lieux/:venueId/parametres',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ describe('IndividualOfferDetails', () => {
expect(
await screen.findByRole('heading', { name: 'À propos de votre offre' })
).toBeInTheDocument()
expect(await screen.findByText(/Ajouter un lieu/)).toBeInTheDocument()
expect(await screen.findByText(/Ajouter une structure/)).toBeInTheDocument()
})

it('should render the component', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { addDays, isBefore } from 'date-fns'
import { Route, Routes, useParams } from 'react-router-dom'
import { useLocation, useParams } from 'react-router-dom'
import useSWR from 'swr'

import { api } from 'apiClient/api'
Expand Down Expand Up @@ -61,6 +61,8 @@ export const CollectiveDataEdition = ({

const canCreateCollectiveOffer = venue?.managingOfferer.allowedOnAdage

const location = useLocation()

if (
!venueId ||
!offererId ||
Expand Down Expand Up @@ -117,28 +119,19 @@ export const CollectiveDataEdition = ({
<>
<hr className={styles['separator']} />

<Routes>
<Route
path=""
element={
<CollectiveDataEditionReadOnly
venue={venue}
culturalPartners={culturalPartners}
/>
}
{location.pathname.includes('/edition') ? (
<CollectiveDataForm
statuses={statuses}
domains={domains}
culturalPartners={culturalPartners}
venue={venue}
/>
<Route
path="/edition"
element={
<CollectiveDataForm
statuses={statuses}
domains={domains}
culturalPartners={culturalPartners}
venue={venue}
/>
}
) : (
<CollectiveDataEditionReadOnly
venue={venue}
culturalPartners={culturalPartners}
/>
</Routes>
)}
</>
)}
</>
Expand Down
13 changes: 4 additions & 9 deletions pro/src/pages/VenueEdition/VenueEdition.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { useSelector } from 'react-redux'
import {
generatePath,
Route,
Routes,
useLocation,
useNavigate,
useParams,
Expand Down Expand Up @@ -158,13 +156,10 @@ export const VenueEdition = (): JSX.Element | null => {
/>
)}

<Routes>
<Route
path="collectif/*"
element={<CollectiveDataEdition venue={venue} />}
/>
<Route path="*" element={<VenueEditionFormScreen venue={venue} />} />
</Routes>
{activeStep === 'collective' && <CollectiveDataEdition venue={venue} />}
{activeStep === 'individual' && (
<VenueEditionFormScreen venue={venue} />
)}
</div>
</Layout>
)
Expand Down
13 changes: 8 additions & 5 deletions pro/src/pages/VenueEdition/VenueEditionFormScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Route, Routes } from 'react-router-dom'
import { useLocation } from 'react-router-dom'

import { GetVenueResponseModel } from 'apiClient/v1'
import { useActiveFeature } from 'commons/hooks/useActiveFeature'
Expand All @@ -19,6 +19,8 @@ export const VenueEditionFormScreen = ({
}: VenueEditionProps): JSX.Element => {
const isOfferAddressEnabled = useActiveFeature('WIP_ENABLE_OFFER_ADDRESS')

const location = useLocation()

if (venue.isVirtual) {
return (
<Callout
Expand Down Expand Up @@ -52,10 +54,11 @@ export const VenueEditionFormScreen = ({
</>
)}

<Routes>
<Route path="" element={<VenueEditionReadOnly venue={venue} />} />
<Route path="/edition" element={<VenueEditionForm venue={venue} />} />
</Routes>
{location.pathname.includes('/edition') ? (
<VenueEditionForm venue={venue} />
) : (
<VenueEditionReadOnly venue={venue} />
)}

{venue.externalAccessibilityData && (
<>
Expand Down
7 changes: 6 additions & 1 deletion pro/src/pages/VenueEdition/__specs__/VenueEdition.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ describe('route VenueEdition', () => {
vi.spyOn(api, 'getVenueTypes').mockResolvedValue([])
vi.spyOn(api, 'fetchVenueLabels').mockResolvedValue([])
vi.spyOn(api, 'listOffers').mockResolvedValue([])
vi.spyOn(api, 'listEducationalDomains').mockResolvedValue([])
vi.spyOn(api, 'getVenuesEducationalStatuses').mockResolvedValue({
statuses: [],
})
vi.spyOn(api, 'getEducationalPartners').mockResolvedValue({ partners: [] })
})

it('should call getVenue and display Venue Form screen on success', async () => {
Expand All @@ -95,7 +100,7 @@ describe('route VenueEdition', () => {
it('should display the collective title', async () => {
renderVenueEdition({
initialRouterEntries: [
`/structures/${defaultGetOffererResponseModel.id}/lieux/${defaultGetVenue.id}/edition/collectif`,
`/structures/${defaultGetOffererResponseModel.id}/lieux/${defaultGetVenue.id}/collectif/edition`,
],
})

Expand Down

0 comments on commit c647d3a

Please sign in to comment.