-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚡ [#76] Lazy load appointment routes/components
Most forms won't need this code, so we can lazy load it instead.
- Loading branch information
1 parent
71a688b
commit 0cd6fcf
Showing
8 changed files
with
111 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/components/appointments/CreateAppointment/LandingPage.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {Navigate, useSearchParams} from 'react-router-dom'; | ||
|
||
import {APPOINTMENT_STEP_PATHS} from './steps'; | ||
|
||
// TODO: replace with loader that redirects at the route level | ||
export const LandingPage = () => { | ||
const [params] = useSearchParams(); | ||
return ( | ||
<Navigate | ||
replace | ||
to={{ | ||
pathname: APPOINTMENT_STEP_PATHS[0], | ||
search: `?${params}`, | ||
}} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,21 @@ | ||
export {default as CreateAppointment} from './CreateAppointment'; | ||
/** | ||
* This module acts as the (lazy loaded) entry point for the appointments chunk. | ||
*/ | ||
import CreateAppointment from './CreateAppointment'; | ||
import Confirmation from './CreateAppointment/Confirmation'; | ||
import {LandingPage} from './CreateAppointment/LandingPage'; | ||
import Summary from './CreateAppointment/Summary'; | ||
import {CancelAppointment, CancelAppointmentSuccess} from './cancel'; | ||
import {ChooseProductStep, ContactDetailsStep, LocationAndTimeStep} from './steps'; | ||
|
||
export { | ||
CreateAppointment, | ||
Confirmation, | ||
LandingPage, | ||
Summary, | ||
CancelAppointment, | ||
CancelAppointmentSuccess, | ||
ChooseProductStep, | ||
ContactDetailsStep, | ||
LocationAndTimeStep, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,89 @@ | ||
import ErrorBoundary from 'components/Errors/ErrorBoundary'; | ||
import Confirmation from 'components/appointments/CreateAppointment/Confirmation'; | ||
import Summary from 'components/appointments/CreateAppointment/Summary'; | ||
import {APPOINTMENT_STEPS, LandingPage} from 'components/appointments/CreateAppointment/steps'; | ||
import {CancelAppointment, CancelAppointmentSuccess} from 'components/appointments/cancel'; | ||
|
||
/** | ||
* Route subtree for appointment forms. | ||
*/ | ||
const createAppointmentRoutes = [ | ||
{ | ||
path: '', | ||
element: <LandingPage />, | ||
lazy: async () => { | ||
const {LandingPage} = await import('components/appointments'); | ||
return {element: <LandingPage />}; | ||
}, | ||
}, | ||
{ | ||
path: 'producten', | ||
lazy: async () => { | ||
const {ChooseProductStep} = await import('components/appointments'); | ||
return {element: <ChooseProductStep navigateTo="../kalender" />}; | ||
}, | ||
}, | ||
{ | ||
path: 'kalender', | ||
lazy: async () => { | ||
const {LocationAndTimeStep} = await import('components/appointments'); | ||
return {element: <LocationAndTimeStep navigateTo="../contactgegevens" />}; | ||
}, | ||
}, | ||
{ | ||
path: 'contactgegevens', | ||
lazy: async () => { | ||
const {ContactDetailsStep} = await import('components/appointments'); | ||
return {element: <ContactDetailsStep navigateTo="../overzicht" />}; | ||
}, | ||
}, | ||
...APPOINTMENT_STEPS.map(({path, element}) => ({path, element})), | ||
{ | ||
path: 'overzicht', | ||
element: <Summary />, | ||
lazy: async () => { | ||
const {Summary} = await import('components/appointments'); | ||
return {element: <Summary />}; | ||
}, | ||
}, | ||
{ | ||
path: 'bevestiging', | ||
element: <Confirmation />, | ||
lazy: async () => { | ||
const {Confirmation} = await import('components/appointments'); | ||
return {element: <Confirmation />}; | ||
}, | ||
}, | ||
]; | ||
|
||
const manageAppointmentRoutes = [ | ||
{ | ||
path: '', | ||
element: ( | ||
<ErrorBoundary> | ||
<CancelAppointment /> | ||
</ErrorBoundary> | ||
), | ||
lazy: async () => { | ||
const {CancelAppointment} = await import('components/appointments'); | ||
return { | ||
element: ( | ||
<ErrorBoundary> | ||
<CancelAppointment /> | ||
</ErrorBoundary> | ||
), | ||
}; | ||
}, | ||
}, | ||
{ | ||
path: 'succes', | ||
element: <CancelAppointmentSuccess />, | ||
lazy: async () => { | ||
const {CancelAppointmentSuccess} = await import('components/appointments'); | ||
return {element: <CancelAppointmentSuccess />}; | ||
}, | ||
}, | ||
]; | ||
|
||
const appointmentRoutes = [ | ||
{ | ||
path: 'afspraak-annuleren/*', | ||
children: manageAppointmentRoutes, | ||
}, | ||
{ | ||
path: 'afspraak-maken/*', | ||
children: createAppointmentRoutes, | ||
lazy: async () => { | ||
const {CreateAppointment} = await import('components/appointments'); | ||
return {element: <CreateAppointment />}; | ||
}, | ||
}, | ||
]; | ||
|
||
export {createAppointmentRoutes, manageAppointmentRoutes}; | ||
export default appointmentRoutes; |