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

fix: correctly retrieve targetFormId for redirect state #2261

Merged
merged 1 commit into from
Jun 29, 2021
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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,4 @@
"webpack-merge": "^4.1.3",
"worker-loader": "^2.0.0"
}
}
}
6 changes: 3 additions & 3 deletions src/public/modules/forms/config/forms.client.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ angular.module('forms').config([
resolve: {
FormData: [
'FormApi',
'$transition$',
function (FormApi, $transition$) {
return FormApi.getAdminForm($transition$.params().formId)
'$stateParams',
function (FormApi, $stateParams) {
return FormApi.getAdminForm($stateParams.formId)
},
],
},
Expand Down
43 changes: 23 additions & 20 deletions src/public/modules/forms/services/form-api.client.factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,6 @@ angular
.module('forms')
.factory('FormApi', ['FormErrorService', 'FormFields', FormApi])

// Helper function for getting formID from path starting with /:formId/.
// If form ID is not found, returns an empty string.
const extractFormId = (path) => {
if (!path) {
return ''
}
const formId = path.substring(1, 25)
if (formId.length !== 24) {
return ''
}
return formId
}

/**
* Service for making API calls to /:formId/:accessMode endpoint, which is used
* for all CRUD operations for forms.
Expand Down Expand Up @@ -75,12 +62,12 @@ function FormApi(FormErrorService, FormFields) {
* If redirectOnError is true, this is the redirect state which will be passed to FormErrorService
*/
const handleError = (err, errorParams) => {
const { redirectOnError, errorTargetState } = errorParams
const { redirectOnError, errorTargetState, targetFormId } = errorParams
if (redirectOnError) {
FormErrorService.redirect({
response: err.response,
targetState: errorTargetState,
targetFormId: extractFormId(get(err.response, 'config.url')),
targetFormId,
})
} else {
throw err // just pass error on
Expand Down Expand Up @@ -115,15 +102,19 @@ function FormApi(FormErrorService, FormFields) {
AdminViewFormService.getAdminFormView,
null,
injectMyInfo,
{ redirectOnError: true, errorTargetState: 'viewForm' },
{
redirectOnError: true,
errorTargetState: 'viewForm',
targetFormId: formId,
},
formId,
),
getPublicForm: (formId) =>
generateService(
PublicFormService.getPublicFormView,
null,
injectMyInfo,
{ redirectOnError: true },
{ redirectOnError: true, targetFormId: formId },
formId,
),
updateForm: (formId, update) =>
Expand Down Expand Up @@ -165,23 +156,35 @@ function FormApi(FormErrorService, FormFields) {
ExamplesService.queryTemplate,
null,
injectMyInfo,
{ redirectOnError: true, errorTargetState: 'templateForm' },
{
redirectOnError: true,
errorTargetState: 'templateForm',
targetFormId: formId,
},
formId,
),
previewForm: (formId) =>
generateService(
AdminViewFormService.previewForm,
null,
injectMyInfo,
{ redirectOnError: true, errorTargetState: 'previewForm' },
{
redirectOnError: true,
errorTargetState: 'previewForm',
targetFormId: formId,
},
formId,
),
useTemplate: (formId, overrideParams) =>
generateService(
ExamplesService.useTemplate,
null,
null,
{ redirectOnError: true, errorTargetState: 'useTemplate' },
{
redirectOnError: true,
errorTargetState: 'useTemplate',
targetFormId: formId,
},
formId,
overrideParams,
),
Expand Down