Skip to content

Commit

Permalink
♻️ [open-formulieren/open-forms#4929] Move cosign start and done page…
Browse files Browse the repository at this point in the history
…s to routes object

State/props are moved into a context provider that wraps around the
outlet, taking care of the data loading. Once we're no longer the
<Routes> approach, we can investigate what we can do with loaders
to pass information/state around.
  • Loading branch information
sergei-maertens committed Jan 7, 2025
1 parent 28223b4 commit 3ba5902
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 35 deletions.
3 changes: 2 additions & 1 deletion src/components/App.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Navigate, Outlet, useMatch} from 'react-router-dom';

import {Cosign} from 'components/CoSign';
import {Cosign, cosignRoutes} from 'components/CoSign';
import ErrorBoundary from 'components/Errors/ErrorBoundary';
import Form from 'components/Form';
import SessionExpired from 'components/Sessions/SessionExpired';
Expand All @@ -26,6 +26,7 @@ export const routes = [
{
path: 'cosign/*',
element: <Cosign />,
children: cosignRoutes,
},
{
path: 'sessie-verlopen',
Expand Down
26 changes: 26 additions & 0 deletions src/components/CoSign/Context.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import PropTypes from 'prop-types';
import React, {useContext} from 'react';

const CosignContext = React.createContext({
reportDownloadUrl: '',
});

CosignContext.displayName = 'CosignContext';

const CosignProvider = ({reportDownloadUrl = '', children}) => (
<CosignContext.Provider
value={{
reportDownloadUrl,
}}
>
{children}
</CosignContext.Provider>
);

CosignProvider.propTypes = {
reportDownloadUrl: PropTypes.string,
};

const useCosignContext = () => useContext(CosignContext);

export {CosignProvider, useCosignContext};
56 changes: 28 additions & 28 deletions src/components/CoSign/Cosign.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {useContext} from 'react';
import {Route, Routes, useNavigate} from 'react-router-dom';
import {Outlet, Route, Routes, useNavigate} from 'react-router-dom';
import {useImmerReducer} from 'use-immer';

import {ConfigContext} from 'Context';
Expand All @@ -8,8 +8,7 @@ import ErrorBoundary from 'components/Errors/ErrorBoundary';
import {CosignSummary} from 'components/Summary';
import useFormContext from 'hooks/useFormContext';

import CosignDone from './CosignDone';
import CosignStart from './CosignStart';
import {CosignProvider} from './Context';

const initialState = {
submission: null,
Expand Down Expand Up @@ -60,31 +59,32 @@ const Cosign = () => {

return (
<ErrorBoundary useCard>
<Routes>
{/*<Route path="start" element={<CosignStart />} />*/}
<Route
path="check"
element={
<CosignSummary
form={form}
submission={state.submission}
summaryData={state.summaryData}
onSubmissionLoaded={submission =>
dispatch({
type: 'SUBMISSION_LOADED',
payload: submission,
})
}
onDataLoaded={({summaryData}) =>
dispatch({type: 'LOADED_SUMMARY_DATA', payload: summaryData})
}
onCosignComplete={onCosignComplete}
onDestroySession={onDestroySession}
/>
}
/>
<Route path="done" element={<CosignDone reportDownloadUrl={state.reportUrl} />} />
</Routes>
<CosignProvider reportDownloadUrl={state.reportUrl}>
<Outlet />
<Routes>
<Route
path="check"
element={
<CosignSummary
form={form}
submission={state.submission}
summaryData={state.summaryData}
onSubmissionLoaded={submission =>
dispatch({
type: 'SUBMISSION_LOADED',
payload: submission,
})
}
onDataLoaded={({summaryData}) =>
dispatch({type: 'LOADED_SUMMARY_DATA', payload: summaryData})
}
onCosignComplete={onCosignComplete}
onDestroySession={onDestroySession}
/>
}
/>
</Routes>
</CosignProvider>
</ErrorBoundary>
);
};
Expand Down
10 changes: 5 additions & 5 deletions src/components/CoSign/CosignDone.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {Paragraph} from '@utrecht/component-library-react';
import PropTypes from 'prop-types';
import {FormattedMessage} from 'react-intl';

import Anchor from 'components/Anchor';
Expand All @@ -8,7 +7,10 @@ import Card from 'components/Card';
import FAIcon from 'components/FAIcon';
import useFormContext from 'hooks/useFormContext';

const CosignDone = ({reportDownloadUrl}) => {
import {useCosignContext} from './Context';

const CosignDone = () => {
const {reportDownloadUrl} = useCosignContext();
const {name, sendConfirmationEmail} = useFormContext();

return (
Expand Down Expand Up @@ -54,8 +56,6 @@ const CosignDone = ({reportDownloadUrl}) => {
);
};

CosignDone.propTypes = {
reportDownloadUrl: PropTypes.string.isRequired,
};
CosignDone.propTypes = {};

export default CosignDone;
3 changes: 2 additions & 1 deletion src/components/CoSign/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import CoSignOld from './CoSignOld';
import Cosign from './Cosign';
import CosignDone from './CosignDone';
import cosignRoutes from './routes';

export default CoSignOld;
export {Cosign, CosignDone};
export {Cosign, CosignDone, cosignRoutes};
15 changes: 15 additions & 0 deletions src/components/CoSign/routes.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import CosignDone from './CosignDone';
import CosignStart from './CosignStart';

const routes = [
{
path: 'start',
element: <CosignStart />,
},
{
path: 'done',
element: <CosignDone />,
},
];

export default routes;

0 comments on commit 3ba5902

Please sign in to comment.