diff --git a/package.json b/package.json index 4798bdfd66..fb8587bbb2 100644 --- a/package.json +++ b/package.json @@ -254,4 +254,4 @@ "webpack-merge": "^4.1.3", "worker-loader": "^2.0.0" } -} \ No newline at end of file +} diff --git a/src/public/modules/forms/config/forms.client.routes.js b/src/public/modules/forms/config/forms.client.routes.js index 07bb491756..6a098605af 100644 --- a/src/public/modules/forms/config/forms.client.routes.js +++ b/src/public/modules/forms/config/forms.client.routes.js @@ -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) }, ], }, diff --git a/src/public/modules/forms/services/form-api.client.factory.js b/src/public/modules/forms/services/form-api.client.factory.js index c26de14407..9f6ef1c0fd 100644 --- a/src/public/modules/forms/services/form-api.client.factory.js +++ b/src/public/modules/forms/services/form-api.client.factory.js @@ -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. @@ -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 @@ -115,7 +102,11 @@ function FormApi(FormErrorService, FormFields) { AdminViewFormService.getAdminFormView, null, injectMyInfo, - { redirectOnError: true, errorTargetState: 'viewForm' }, + { + redirectOnError: true, + errorTargetState: 'viewForm', + targetFormId: formId, + }, formId, ), getPublicForm: (formId) => @@ -123,7 +114,7 @@ function FormApi(FormErrorService, FormFields) { PublicFormService.getPublicFormView, null, injectMyInfo, - { redirectOnError: true }, + { redirectOnError: true, targetFormId: formId }, formId, ), updateForm: (formId, update) => @@ -165,7 +156,11 @@ function FormApi(FormErrorService, FormFields) { ExamplesService.queryTemplate, null, injectMyInfo, - { redirectOnError: true, errorTargetState: 'templateForm' }, + { + redirectOnError: true, + errorTargetState: 'templateForm', + targetFormId: formId, + }, formId, ), previewForm: (formId) => @@ -173,7 +168,11 @@ function FormApi(FormErrorService, FormFields) { AdminViewFormService.previewForm, null, injectMyInfo, - { redirectOnError: true, errorTargetState: 'previewForm' }, + { + redirectOnError: true, + errorTargetState: 'previewForm', + targetFormId: formId, + }, formId, ), useTemplate: (formId, overrideParams) => @@ -181,7 +180,11 @@ function FormApi(FormErrorService, FormFields) { ExamplesService.useTemplate, null, null, - { redirectOnError: true, errorTargetState: 'useTemplate' }, + { + redirectOnError: true, + errorTargetState: 'useTemplate', + targetFormId: formId, + }, formId, overrideParams, ),