-
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.
🐛 [open-formulieren/open-forms#3362] Handle server side redirects
The backend is now agnostic to URL routing/hash based routing - it will always redirect back to the URL that was used to start the form and provide action & action params query arguments that specify the target for the frontend. The frontend parses this action & the params and maps it to the intended client side routes, effectively decoupling implementation details between backend and frontend. Note that this requires the SDK to operate correctly in two of the tree main steps in this flow: 1. SDK must correctly derive the 'base URL' for the form, irrespective of whether hash based routing is used or not. Fragments should *not* be sent to the backend, since they are ignored anyway. 2. The backend uses the URL supplied from 1. and append the action/action params from the context of the backend action/validation that was performed. 3. The SDK must correctly interpret the action and its params and route to the appropriate part of the application. TODO: using this pattern, we can probably refactor the _start=1 flow from the backend too, this can likely be converted to _of_action=startSubmission.
- Loading branch information
1 parent
dd342fd
commit 54d1198
Showing
3 changed files
with
195 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Get the correct redirect path for an action. | ||
* @param {string} action The action to be performed. | ||
* @param {Record<string, string>} actionParams The params linked to the action. | ||
* @returns {{path: string, query?: URLSearchParams}} An object containing the pathname to be used, | ||
* alongside with optional query parameters. | ||
*/ | ||
export const getRedirectParams = (action, actionParams) => { | ||
switch (action) { | ||
case 'cosign': | ||
return { | ||
path: 'cosign/check', | ||
query: new URLSearchParams(actionParams), | ||
}; | ||
case 'afspraak-annuleren': | ||
return { | ||
path: 'afspraak-annuleren', | ||
query: new URLSearchParams(actionParams), | ||
}; | ||
case 'afspraak-maken': | ||
return {path: 'afspraak-maken'}; | ||
case 'resume': | ||
return {path: `stap/${actionParams.next_step}`}; | ||
default: | ||
return {}; | ||
} | ||
}; |
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