Skip to content

Commit

Permalink
Merge pull request #727 from open-formulieren/issue/4398-properly-pas…
Browse files Browse the repository at this point in the history
…s-initial-data-reference

🐛 [open-formulieren/open-forms#4546] Properly pass initial_data_reference
  • Loading branch information
sergei-maertens authored Nov 5, 2024
2 parents 6352de4 + 2eb4c6e commit 3fe8367
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/components/FormStart/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const FormStart = ({form, submission, onFormStart, onDestroySession, initialData
<LoginOptions
form={form}
onFormStart={onFormStart}
extraParams={{initial_data_reference: initialDataReference}}
extraNextParams={{initial_data_reference: initialDataReference}}
/>
)}
</Card>
Expand Down
2 changes: 1 addition & 1 deletion src/components/FormStart/tests.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,6 @@ it('Form start page with initial_data_reference', async () => {
const loginLink = await screen.findByRole('link', {name: 'Login with DigiD'});
expect(loginLink).toHaveAttribute(
'href',
'https://openforms.nl/auth/form-name/digid/start?initial_data_reference=1234&next=http%3A%2F%2Flocalhost%2F%3F_start%3D1'
'https://openforms.nl/auth/form-name/digid/start?next=http%3A%2F%2Flocalhost%2F%3F_start%3D1%26initial_data_reference%3D1234'
);
});
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, extraParams = {}}) => {
const LoginOptions = ({form, onFormStart, extraNextParams = {}}) => {
const config = useContext(ConfigContext);

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

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

export default LoginOptions;
4 changes: 2 additions & 2 deletions src/components/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ const isLastStep = (currentStepIndex, submission) => {
return currentStepIndex === submission.steps.length - 1;
};

const getLoginUrl = (loginOption, extraParams = {}) => {
const getLoginUrl = (loginOption, extraParams = {}, extraNextParams = {}) => {
if (loginOption.url === '#') return loginOption.url;

const nextUrl = new URL(window.location.href);

const queryParams = Array.from(nextUrl.searchParams.keys());
Expand All @@ -39,6 +38,7 @@ const getLoginUrl = (loginOption, extraParams = {}) => {
if (!loginUrl.searchParams.has('coSignSubmission')) {
nextUrl.searchParams.set(START_FORM_QUERY_PARAM, '1');
}
Object.entries(extraNextParams).map(([key, value]) => nextUrl.searchParams.set(key, value));
loginUrl.searchParams.set('next', nextUrl.toString());
return loginUrl.toString();
};
Expand Down

0 comments on commit 3fe8367

Please sign in to comment.