Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 [open-formulieren/open-forms#4546] Properly pass initial_data_reference #727

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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