Skip to content

Commit

Permalink
♻️ [#4398] Pass initial data ref to backend via login URL
Browse files Browse the repository at this point in the history
previously it was attempted to grab this from the query params, but the parameter was not set anymore at the time it was actually needed (when sending the submission create request, after authentication)
  • Loading branch information
stevenbal committed Oct 14, 2024
1 parent 06d6ac1 commit 70b1a66
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
7 changes: 6 additions & 1 deletion src/components/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,11 @@ const Form = () => {
element={<Navigate replace to={introductionPageContent ? 'introductie' : 'startpagina'} />}
/>

<Route path="introductie" element={<IntroductionPage />} />
<Route
path="introductie"
// Ensure the initialDataReference is preserved when continuing to the Form start
element={<IntroductionPage extraParams={{initial_data_reference: initialDataReference}} />}
/>

<Route
path="startpagina"
Expand All @@ -370,6 +374,7 @@ const Form = () => {
submission={state.submission}
onFormStart={onFormStart}
onDestroySession={onDestroySession}
initialDataReference={initialDataReference}
/>
</ErrorBoundary>
}
Expand Down
8 changes: 6 additions & 2 deletions src/components/FormStart/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const FormStartMessage = ({form}) => {
* This is shown when the form is initially loaded and provides the explicit user
* action to start the form, or present the login button (DigiD, eHerkenning...)
*/
const FormStart = ({form, submission, onFormStart, onDestroySession}) => {
const FormStart = ({form, submission, onFormStart, onDestroySession, initialDataReference}) => {
const hasActiveSubmission = !!submission;
const isAuthenticated = hasActiveSubmission && submission.isAuthenticated;
const doStart = useStartSubmission();
Expand Down Expand Up @@ -121,7 +121,11 @@ const FormStart = ({form, submission, onFormStart, onDestroySession}) => {
isAuthenticated={isAuthenticated}
/>
) : (
<LoginOptions form={form} onFormStart={onFormStart} />
<LoginOptions
form={form}
onFormStart={onFormStart}
extraParams={{initial_data_reference: initialDataReference}}
/>
)}
</Card>
</LiteralsProvider>
Expand Down
6 changes: 4 additions & 2 deletions src/components/IntroductionPage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import Card from 'components/Card';
import FAIcon from 'components/FAIcon';
import Link from 'components/Link';

const IntroductionPage = () => {
const IntroductionPage = ({extraParams = {}}) => {
const {name, introductionPageContent = ''} = useContext(FormContext);
if (!introductionPageContent) {
return <Navigate replace to="startpagina" />;
}
let startUrl = '/startpagina';

Check warning on line 17 in src/components/IntroductionPage/index.js

View check run for this annotation

Codecov / codecov/patch

src/components/IntroductionPage/index.js#L17

Added line #L17 was not covered by tests
if (extraParams) startUrl = `${startUrl}?${new URLSearchParams(extraParams).toString()}`;
return (
<Card title={name}>
<Body
Expand All @@ -23,7 +25,7 @@ const IntroductionPage = () => {
/>

<Link
to="/startpagina"
to={startUrl}
component={ButtonLink}
appearance="primary-action-button"
className="openforms-start-link"
Expand Down
5 changes: 3 additions & 2 deletions src/components/LoginOptions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Types from 'types';

import LoginOptionsDisplay from './LoginOptionsDisplay';

const LoginOptions = ({form, onFormStart}) => {
const LoginOptions = ({form, onFormStart, extraParams = {}}) => {
const config = useContext(ConfigContext);

const loginAsYourselfOptions = [];
Expand All @@ -18,7 +18,7 @@ const LoginOptions = ({form, onFormStart}) => {

form.loginOptions.forEach(option => {
let readyOption = {...option};
readyOption.url = getLoginUrl(option);
readyOption.url = getLoginUrl(option, extraParams);
readyOption.label = (
<FormattedMessage
description="Login button label"
Expand Down Expand Up @@ -81,6 +81,7 @@ const LoginOptions = ({form, onFormStart}) => {
LoginOptions.propTypes = {
form: Types.Form.isRequired,
onFormStart: PropTypes.func.isRequired,
extraParams: PropTypes.object,
};

export default LoginOptions;

0 comments on commit 70b1a66

Please sign in to comment.