@ukhomeoffice/cop-react-form-renderer 4.67.0 → 4.68.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (315) hide show
  1. package/dist/components/CheckYourAnswers/Answer.js +6 -16
  2. package/dist/components/CheckYourAnswers/Answer.test.js +104 -129
  3. package/dist/components/CheckYourAnswers/CheckYourAnswers.js +26 -64
  4. package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +428 -555
  5. package/dist/components/CheckYourAnswers/index.js +0 -3
  6. package/dist/components/CollectionPage/CollectionPage.js +13 -42
  7. package/dist/components/CollectionPage/CollectionPage.test.js +160 -206
  8. package/dist/components/CollectionPage/index.js +0 -3
  9. package/dist/components/FormComponent/Collection.js +35 -79
  10. package/dist/components/FormComponent/Collection.test.js +340 -391
  11. package/dist/components/FormComponent/Container.js +10 -31
  12. package/dist/components/FormComponent/Container.test.js +304 -357
  13. package/dist/components/FormComponent/FormComponent.js +17 -60
  14. package/dist/components/FormComponent/FormComponent.test.js +190 -228
  15. package/dist/components/FormComponent/helpers/addLabel.js +4 -7
  16. package/dist/components/FormComponent/helpers/getComponentDisabled.js +0 -4
  17. package/dist/components/FormComponent/helpers/getComponentDisabled.test.js +0 -2
  18. package/dist/components/FormComponent/helpers/getComponentError.js +0 -6
  19. package/dist/components/FormComponent/helpers/getComponentError.test.js +0 -2
  20. package/dist/components/FormComponent/helpers/index.js +0 -4
  21. package/dist/components/FormComponent/index.js +0 -3
  22. package/dist/components/FormPage/FormPage.js +21 -53
  23. package/dist/components/FormPage/FormPage.test.js +122 -160
  24. package/dist/components/FormPage/index.js +0 -3
  25. package/dist/components/FormRenderer/FormRenderer.js +106 -296
  26. package/dist/components/FormRenderer/FormRenderer.test.js +820 -1058
  27. package/dist/components/FormRenderer/handlers/cyaAction.js +0 -5
  28. package/dist/components/FormRenderer/handlers/getPageId.js +0 -2
  29. package/dist/components/FormRenderer/handlers/getPageId.test.js +1 -2
  30. package/dist/components/FormRenderer/handlers/handlers.test.js +1 -18
  31. package/dist/components/FormRenderer/handlers/index.js +0 -5
  32. package/dist/components/FormRenderer/handlers/navigate.js +0 -5
  33. package/dist/components/FormRenderer/handlers/submissionError.js +0 -2
  34. package/dist/components/FormRenderer/helpers/canActionProceed.js +0 -3
  35. package/dist/components/FormRenderer/helpers/canActionProceed.test.js +1 -3
  36. package/dist/components/FormRenderer/helpers/canCYASubmit.js +0 -2
  37. package/dist/components/FormRenderer/helpers/canCYASubmit.test.js +1 -5
  38. package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.js +4 -12
  39. package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.test.js +1 -2
  40. package/dist/components/FormRenderer/helpers/getCYA.js +0 -9
  41. package/dist/components/FormRenderer/helpers/getCYA.test.js +1 -3
  42. package/dist/components/FormRenderer/helpers/getFormState.js +0 -5
  43. package/dist/components/FormRenderer/helpers/getFormState.test.js +1 -3
  44. package/dist/components/FormRenderer/helpers/getNextPageId.js +0 -25
  45. package/dist/components/FormRenderer/helpers/getNextPageId.test.js +1 -4
  46. package/dist/components/FormRenderer/helpers/getPage.js +0 -5
  47. package/dist/components/FormRenderer/helpers/getPage.test.js +1 -3
  48. package/dist/components/FormRenderer/helpers/getRelevantPages.js +0 -6
  49. package/dist/components/FormRenderer/helpers/getRelevantPages.test.js +1 -3
  50. package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +0 -10
  51. package/dist/components/FormRenderer/helpers/getSubmissionStatus.test.js +4 -7
  52. package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.js +32 -41
  53. package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.test.js +122 -8
  54. package/dist/components/FormRenderer/helpers/index.js +1 -11
  55. package/dist/components/FormRenderer/index.js +0 -3
  56. package/dist/components/FormRenderer/onCYAAction.js +8 -30
  57. package/dist/components/FormRenderer/onCYAAction.test.js +54 -79
  58. package/dist/components/FormRenderer/onPageAction.js +123 -0
  59. package/dist/components/FormRenderer/onPageAction.test.js +632 -0
  60. package/dist/components/PageActions/ActionButton.js +2 -17
  61. package/dist/components/PageActions/ActionButton.test.js +58 -81
  62. package/dist/components/PageActions/PageActions.js +3 -10
  63. package/dist/components/PageActions/PageActions.test.js +95 -120
  64. package/dist/components/PageActions/index.js +0 -3
  65. package/dist/components/SummaryList/GroupAction.js +5 -26
  66. package/dist/components/SummaryList/GroupAction.test.js +14 -28
  67. package/dist/components/SummaryList/RowAction.js +5 -25
  68. package/dist/components/SummaryList/RowAction.test.js +14 -28
  69. package/dist/components/SummaryList/SummaryList.js +7 -31
  70. package/dist/components/SummaryList/SummaryList.test.js +69 -126
  71. package/dist/components/SummaryList/SummaryListHeadingRow.js +3 -8
  72. package/dist/components/SummaryList/SummaryListRow.js +4 -8
  73. package/dist/components/SummaryList/SummaryListTitleRow.js +2 -7
  74. package/dist/components/SummaryList/helpers/getGroupActionAttributes.js +0 -3
  75. package/dist/components/SummaryList/helpers/getGroupActionAttributes.test.js +0 -6
  76. package/dist/components/SummaryList/helpers/getRowActionAttributes.js +0 -3
  77. package/dist/components/SummaryList/helpers/getRowActionAttributes.test.js +0 -6
  78. package/dist/components/SummaryList/helpers/index.js +0 -2
  79. package/dist/components/SummaryList/index.js +0 -3
  80. package/dist/components/TaskList/Task.js +9 -31
  81. package/dist/components/TaskList/Task.test.js +32 -59
  82. package/dist/components/TaskList/TaskList.js +32 -59
  83. package/dist/components/TaskList/TaskList.test.js +52 -90
  84. package/dist/components/TaskList/TaskState.js +2 -10
  85. package/dist/components/TaskList/TaskState.test.js +23 -41
  86. package/dist/components/TaskList/index.js +0 -3
  87. package/dist/components/index.js +0 -7
  88. package/dist/context/HooksContext/HooksContext.js +21 -39
  89. package/dist/context/HooksContext/HooksContext.test.js +18 -34
  90. package/dist/context/HooksContext/index.js +0 -5
  91. package/dist/context/ValidationContext/ValidationContext.js +26 -56
  92. package/dist/context/ValidationContext/ValidationContext.test.js +43 -64
  93. package/dist/context/ValidationContext/index.js +0 -5
  94. package/dist/context/index.js +0 -3
  95. package/dist/hooks/index.js +0 -9
  96. package/dist/hooks/useAxios.js +17 -36
  97. package/dist/hooks/useGetRequest.js +57 -93
  98. package/dist/hooks/useHooks.js +2 -4
  99. package/dist/hooks/useRefData.js +14 -41
  100. package/dist/hooks/useValidation.js +2 -4
  101. package/dist/index.js +0 -9
  102. package/dist/models/PageAction.js +4 -4
  103. package/dist/models/TaskStates.js +4 -4
  104. package/dist/models/index.js +1 -10
  105. package/dist/setupTests.js +0 -13
  106. package/dist/utils/CheckYourAnswers/getCYAAction.js +1 -9
  107. package/dist/utils/CheckYourAnswers/getCYAAction.test.js +1 -19
  108. package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.js +4 -11
  109. package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.test.js +4 -9
  110. package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.js +4 -9
  111. package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.test.js +4 -8
  112. package/dist/utils/CheckYourAnswers/getCYARow.js +1 -10
  113. package/dist/utils/CheckYourAnswers/getCYARow.test.js +8 -23
  114. package/dist/utils/CheckYourAnswers/getCYARowForGroup.js +6 -21
  115. package/dist/utils/CheckYourAnswers/getCYARowForGroup.test.js +2 -9
  116. package/dist/utils/CheckYourAnswers/getCYARowsForCollection.js +4 -20
  117. package/dist/utils/CheckYourAnswers/getCYARowsForCollection.test.js +7 -22
  118. package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.js +4 -32
  119. package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +4 -34
  120. package/dist/utils/CheckYourAnswers/getCYARowsForContainer.js +4 -15
  121. package/dist/utils/CheckYourAnswers/getCYARowsForContainer.test.js +4 -22
  122. package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +2 -22
  123. package/dist/utils/CheckYourAnswers/getCYARowsForPage.test.js +7 -25
  124. package/dist/utils/CheckYourAnswers/index.js +1 -3
  125. package/dist/utils/CheckYourAnswers/showComponentCYA.js +2 -15
  126. package/dist/utils/CheckYourAnswers/showComponentCYA.test.js +1 -3
  127. package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.js +4 -12
  128. package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.test.js +5 -6
  129. package/dist/utils/CollectionPage/getCollectionPageActiveIndex.js +0 -6
  130. package/dist/utils/CollectionPage/getCollectionPageActiveIndex.test.js +1 -2
  131. package/dist/utils/CollectionPage/index.js +1 -5
  132. package/dist/utils/CollectionPage/mergeCollectionPages.js +5 -11
  133. package/dist/utils/CollectionPage/mergeCollectionPages.test.js +1 -2
  134. package/dist/utils/Component/addShowWhen.js +4 -10
  135. package/dist/utils/Component/addShowWhen.test.js +1 -2
  136. package/dist/utils/Component/applyToComponentTree.js +4 -18
  137. package/dist/utils/Component/applyToComponentTree.test.js +4 -8
  138. package/dist/utils/Component/cleanAttributes.js +1 -8
  139. package/dist/utils/Component/cleanAttributes.test.js +15 -16
  140. package/dist/utils/Component/elevateNestedComponents.js +0 -6
  141. package/dist/utils/Component/elevateNestedComponents.test.js +0 -2
  142. package/dist/utils/Component/getComponent.js +7 -86
  143. package/dist/utils/Component/getComponentTests/getComponent.autocomplete.test.js +6 -10
  144. package/dist/utils/Component/getComponentTests/getComponent.calculation.test.js +33 -51
  145. package/dist/utils/Component/getComponentTests/getComponent.checkboxes.test.js +8 -35
  146. package/dist/utils/Component/getComponentTests/getComponent.date.test.js +12 -29
  147. package/dist/utils/Component/getComponentTests/getComponent.details.test.js +4 -10
  148. package/dist/utils/Component/getComponentTests/getComponent.email.test.js +6 -23
  149. package/dist/utils/Component/getComponentTests/getComponent.file.test.js +6 -24
  150. package/dist/utils/Component/getComponentTests/getComponent.heading.test.js +3 -7
  151. package/dist/utils/Component/getComponentTests/getComponent.html.test.js +4 -10
  152. package/dist/utils/Component/getComponentTests/getComponent.insetText.test.js +3 -7
  153. package/dist/utils/Component/getComponentTests/getComponent.list.test.js +4 -10
  154. package/dist/utils/Component/getComponentTests/getComponent.multifile.test.js +5 -22
  155. package/dist/utils/Component/getComponentTests/getComponent.nested.test.js +156 -175
  156. package/dist/utils/Component/getComponentTests/getComponent.paragraph.test.js +4 -10
  157. package/dist/utils/Component/getComponentTests/getComponent.phoneNumber.test.js +6 -23
  158. package/dist/utils/Component/getComponentTests/getComponent.radios.test.js +8 -35
  159. package/dist/utils/Component/getComponentTests/getComponent.select.test.js +6 -23
  160. package/dist/utils/Component/getComponentTests/getComponent.text.test.js +6 -23
  161. package/dist/utils/Component/getComponentTests/getComponent.textArea.test.js +10 -34
  162. package/dist/utils/Component/getComponentTests/getComponent.time.test.js +12 -31
  163. package/dist/utils/Component/getComponentTests/getComponent.unknown.test.js +1 -2
  164. package/dist/utils/Component/getComponentTests/getComponent.warningText.test.js +3 -7
  165. package/dist/utils/Component/getDefaultValue.js +4 -8
  166. package/dist/utils/Component/getDefaultValue.test.js +0 -3
  167. package/dist/utils/Component/index.js +0 -10
  168. package/dist/utils/Component/isEditable.js +1 -4
  169. package/dist/utils/Component/isEditable.test.js +1 -5
  170. package/dist/utils/Component/setupContainerComponentsPath.js +4 -9
  171. package/dist/utils/Component/setupContainerComponentsPath.test.js +0 -3
  172. package/dist/utils/Component/showComponent.js +1 -8
  173. package/dist/utils/Component/showComponent.test.js +1 -2
  174. package/dist/utils/Component/wrapInFormGroup.js +0 -7
  175. package/dist/utils/Condition/index.js +0 -5
  176. package/dist/utils/Condition/meetsAllConditions.js +0 -9
  177. package/dist/utils/Condition/meetsAllConditions.test.js +1 -2
  178. package/dist/utils/Condition/meetsCondition.js +9 -34
  179. package/dist/utils/Condition/meetsCondition.test.js +21 -14
  180. package/dist/utils/Condition/meetsOneCondition.js +1 -9
  181. package/dist/utils/Condition/meetsOneCondition.test.js +1 -2
  182. package/dist/utils/Condition/setupConditions.js +4 -13
  183. package/dist/utils/Condition/setupConditions.test.js +0 -2
  184. package/dist/utils/Container/getEditableComponents.js +0 -7
  185. package/dist/utils/Container/getEditableComponents.test.js +1 -12
  186. package/dist/utils/Container/index.js +0 -5
  187. package/dist/utils/Container/setupNesting.js +4 -12
  188. package/dist/utils/Container/setupNesting.test.js +4 -10
  189. package/dist/utils/Container/showContainer.js +9 -18
  190. package/dist/utils/Container/showContainer.test.js +1 -2
  191. package/dist/utils/Data/applyFormula.js +6 -29
  192. package/dist/utils/Data/applyFormula.test.js +1 -2
  193. package/dist/utils/Data/getAutocompleteSource.js +1 -5
  194. package/dist/utils/Data/getAutocompleteSource.test.js +1 -2
  195. package/dist/utils/Data/getDataPath.js +3 -17
  196. package/dist/utils/Data/getDataPath.test.js +0 -4
  197. package/dist/utils/Data/getOptions.js +4 -14
  198. package/dist/utils/Data/getOptions.test.js +1 -2
  199. package/dist/utils/Data/getSourceData.js +6 -21
  200. package/dist/utils/Data/getSourceData.test.js +4 -6
  201. package/dist/utils/Data/index.js +1 -11
  202. package/dist/utils/Data/refDataToOptions.js +5 -13
  203. package/dist/utils/Data/refDataToOptions.test.js +1 -2
  204. package/dist/utils/Data/setDataItem.js +0 -5
  205. package/dist/utils/Data/setDataItem.test.js +0 -2
  206. package/dist/utils/Data/setupFormData.js +6 -25
  207. package/dist/utils/Data/setupFormData.test.js +8 -11
  208. package/dist/utils/Data/setupRefDataUrlForComponent.js +4 -15
  209. package/dist/utils/Data/setupRefDataUrlForComponent.test.js +1 -3
  210. package/dist/utils/FormPage/applyConditionalProperties.js +4 -11
  211. package/dist/utils/FormPage/applyConditionalProperties.test.js +4 -6
  212. package/dist/utils/FormPage/getFormPage.js +4 -16
  213. package/dist/utils/FormPage/getFormPage.test.js +10 -9
  214. package/dist/utils/FormPage/getFormPages.js +4 -9
  215. package/dist/utils/FormPage/getFormPages.test.js +6 -7
  216. package/dist/utils/FormPage/getPageActions.js +6 -19
  217. package/dist/utils/FormPage/getPageActions.test.js +1 -3
  218. package/dist/utils/FormPage/getParagraphFromText.js +0 -3
  219. package/dist/utils/FormPage/getParagraphFromText.test.js +1 -3
  220. package/dist/utils/FormPage/index.js +0 -7
  221. package/dist/utils/FormPage/showFormPage.js +9 -18
  222. package/dist/utils/FormPage/showFormPage.test.js +0 -2
  223. package/dist/utils/FormPage/showFormPageCYA.js +0 -5
  224. package/dist/utils/FormPage/showFormPageCYA.test.js +0 -2
  225. package/dist/utils/FormPage/useComponent.js +7 -19
  226. package/dist/utils/FormPage/useComponent.test.js +4 -7
  227. package/dist/utils/Format/formatData.js +0 -5
  228. package/dist/utils/Format/formatData.test.js +1 -2
  229. package/dist/utils/Format/formatDataForComponent.js +1 -6
  230. package/dist/utils/Format/formatDataForComponent.test.js +28 -47
  231. package/dist/utils/Format/formatDataForForm.js +4 -9
  232. package/dist/utils/Format/formatDataForForm.test.js +14 -11
  233. package/dist/utils/Format/formatDataForPage.js +1 -5
  234. package/dist/utils/Format/formatDataForPage.test.js +15 -12
  235. package/dist/utils/Format/index.js +1 -6
  236. package/dist/utils/Hub/getFormHub.js +0 -8
  237. package/dist/utils/Hub/getFormHub.test.js +6 -8
  238. package/dist/utils/Hub/index.js +1 -3
  239. package/dist/utils/Meta/documents/getDocuments.js +1 -4
  240. package/dist/utils/Meta/documents/getDocuments.test.js +4 -10
  241. package/dist/utils/Meta/documents/index.js +1 -5
  242. package/dist/utils/Meta/documents/setDocumentsForField.js +4 -11
  243. package/dist/utils/Meta/documents/setDocumentsForField.test.js +4 -16
  244. package/dist/utils/Meta/index.js +1 -4
  245. package/dist/utils/Operate/checkValueIsTruthy.js +1 -7
  246. package/dist/utils/Operate/checkValueIsTruthy.test.js +0 -2
  247. package/dist/utils/Operate/getFirstOf.js +2 -9
  248. package/dist/utils/Operate/getFirstOf.test.js +0 -2
  249. package/dist/utils/Operate/getIndexOfMatchingValueIn.js +7 -21
  250. package/dist/utils/Operate/getIndexOfMatchingValueIn.test.js +6 -2
  251. package/dist/utils/Operate/index.js +0 -3
  252. package/dist/utils/Operate/persistValueInFormData.js +1 -8
  253. package/dist/utils/Operate/persistValueInFormData.test.js +0 -4
  254. package/dist/utils/Operate/runPageOperations.js +3 -19
  255. package/dist/utils/Operate/runPageOperations.test.js +4 -6
  256. package/dist/utils/Operate/setValueInFormData.js +2 -7
  257. package/dist/utils/Operate/setValueInFormData.test.js +0 -2
  258. package/dist/utils/Operate/shouldRun.js +1 -14
  259. package/dist/utils/Operate/shouldRun.test.js +5 -8
  260. package/dist/utils/Validate/additional/conditionallyRequired.js +0 -3
  261. package/dist/utils/Validate/additional/conditionallyRequired.test.js +0 -2
  262. package/dist/utils/Validate/additional/index.js +1 -22
  263. package/dist/utils/Validate/additional/index.test.js +0 -6
  264. package/dist/utils/Validate/additional/mustBeAfter.js +3 -8
  265. package/dist/utils/Validate/additional/mustBeAfter.test.js +0 -4
  266. package/dist/utils/Validate/additional/mustBeBefore.js +3 -8
  267. package/dist/utils/Validate/additional/mustBeBefore.test.js +0 -4
  268. package/dist/utils/Validate/additional/mustBeEarlierDateTime.js +5 -16
  269. package/dist/utils/Validate/additional/mustBeEarlierDateTime.test.js +4 -8
  270. package/dist/utils/Validate/additional/mustBeGreaterThan.js +0 -3
  271. package/dist/utils/Validate/additional/mustBeGreaterThan.test.js +0 -2
  272. package/dist/utils/Validate/additional/mustBeInTheFuture.js +3 -12
  273. package/dist/utils/Validate/additional/mustBeInTheFuture.test.js +0 -3
  274. package/dist/utils/Validate/additional/mustBeInThePast.js +5 -13
  275. package/dist/utils/Validate/additional/mustBeInThePast.test.js +0 -3
  276. package/dist/utils/Validate/additional/mustBeLessThan.js +0 -3
  277. package/dist/utils/Validate/additional/mustBeLessThan.test.js +0 -2
  278. package/dist/utils/Validate/additional/mustBeLongerThan.js +0 -3
  279. package/dist/utils/Validate/additional/mustBeLongerThan.test.js +0 -2
  280. package/dist/utils/Validate/additional/mustBeNumbersOnly.js +0 -3
  281. package/dist/utils/Validate/additional/mustBeNumbersOnly.test.js +0 -2
  282. package/dist/utils/Validate/additional/mustBeShorterThan.js +0 -3
  283. package/dist/utils/Validate/additional/mustBeShorterThan.test.js +0 -2
  284. package/dist/utils/Validate/additional/mustEnterAtLeastOne.js +0 -5
  285. package/dist/utils/Validate/additional/mustEnterAtLeastOne.test.js +4 -5
  286. package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.js +0 -3
  287. package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.test.js +0 -2
  288. package/dist/utils/Validate/additional/mustSelectOnlyOne.js +0 -6
  289. package/dist/utils/Validate/additional/mustSelectOnlyOne.test.js +4 -7
  290. package/dist/utils/Validate/additional/utils.js +10 -26
  291. package/dist/utils/Validate/index.js +1 -11
  292. package/dist/utils/Validate/validateCollection.js +4 -10
  293. package/dist/utils/Validate/validateCollection.test.js +4 -6
  294. package/dist/utils/Validate/validateComponent.js +2 -39
  295. package/dist/utils/Validate/validateComponent.test.js +4 -22
  296. package/dist/utils/Validate/validateContainer.js +4 -14
  297. package/dist/utils/Validate/validateContainer.test.js +4 -10
  298. package/dist/utils/Validate/validateDate.js +6 -38
  299. package/dist/utils/Validate/validateDate.test.js +0 -4
  300. package/dist/utils/Validate/validateEmail.js +1 -8
  301. package/dist/utils/Validate/validateEmail.test.js +5 -4
  302. package/dist/utils/Validate/validateMultifile.js +0 -7
  303. package/dist/utils/Validate/validateMultifile.test.js +5 -6
  304. package/dist/utils/Validate/validatePage.js +4 -16
  305. package/dist/utils/Validate/validatePage.test.js +30 -25
  306. package/dist/utils/Validate/validateRegex.js +0 -10
  307. package/dist/utils/Validate/validateRegex.test.js +5 -4
  308. package/dist/utils/Validate/validateRequired.js +0 -8
  309. package/dist/utils/Validate/validateRequired.test.js +5 -4
  310. package/dist/utils/Validate/validateTextArea.js +0 -8
  311. package/dist/utils/Validate/validateTextArea.test.js +0 -2
  312. package/dist/utils/Validate/validateTime.js +5 -22
  313. package/dist/utils/Validate/validateTime.test.js +0 -2
  314. package/dist/utils/index.js +4 -20
  315. package/package.json +2 -2
@@ -1,86 +1,59 @@
1
1
  "use strict";
2
2
 
3
3
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = exports.DEFAULT_CLASS = void 0;
9
-
10
8
  var _copReactComponents = require("@ukhomeoffice/cop-react-components");
11
-
12
9
  var _propTypes = _interopRequireDefault(require("prop-types"));
13
-
14
10
  var _react = _interopRequireWildcard(require("react"));
15
-
16
11
  var _context = require("../../context");
17
-
18
12
  var _hooks = require("../../hooks");
19
-
20
13
  var _models = require("../../models");
21
-
22
14
  var _utils = _interopRequireDefault(require("../../utils"));
23
-
24
15
  var _CheckYourAnswers = _interopRequireDefault(require("../CheckYourAnswers"));
25
-
26
16
  var _CollectionPage = _interopRequireDefault(require("../CollectionPage"));
27
-
28
17
  var _FormPage = _interopRequireDefault(require("../FormPage"));
29
-
30
18
  var _TaskList = _interopRequireDefault(require("../TaskList"));
31
-
32
19
  var _handlers = _interopRequireDefault(require("./handlers"));
33
-
34
20
  var _helpers = _interopRequireDefault(require("./helpers"));
35
-
36
21
  var _onCYAAction = _interopRequireDefault(require("./onCYAAction"));
37
-
22
+ var _onPageAction = _interopRequireDefault(require("./onPageAction"));
38
23
  require("./FormRenderer.scss");
39
-
40
24
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
41
-
42
25
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
43
-
44
26
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
45
-
46
27
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
47
-
48
28
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
49
-
50
29
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
51
-
52
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
53
-
30
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
31
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
32
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
54
33
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
55
-
56
34
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
57
-
58
35
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
59
-
60
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
61
-
62
- function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
63
-
36
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
37
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
64
38
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
65
-
66
39
  var FormRenderer = function FormRenderer(_ref) {
67
40
  var title = _ref.title,
68
- type = _ref.type,
69
- components = _ref.components,
70
- pages = _ref.pages,
71
- hub = _ref.hub,
72
- cya = _ref.cya,
73
- data = _ref.data,
74
- hashLink = _ref.hashLink,
75
- hooks = _ref.hooks,
76
- classBlock = _ref.classBlock,
77
- classModifiers = _ref.classModifiers,
78
- className = _ref.className,
79
- hide_title = _ref.hide_title,
80
- summaryListClassModifiers = _ref.summaryListClassModifiers,
81
- noChangeAction = _ref.noChangeAction,
82
- newPageId = _ref.newPageId,
83
- viewOnly = _ref.viewOnly;
41
+ type = _ref.type,
42
+ components = _ref.components,
43
+ pages = _ref.pages,
44
+ hub = _ref.hub,
45
+ cya = _ref.cya,
46
+ data = _ref.data,
47
+ hashLink = _ref.hashLink,
48
+ hooks = _ref.hooks,
49
+ classBlock = _ref.classBlock,
50
+ classModifiers = _ref.classModifiers,
51
+ className = _ref.className,
52
+ hide_title = _ref.hide_title,
53
+ summaryListClassModifiers = _ref.summaryListClassModifiers,
54
+ noChangeAction = _ref.noChangeAction,
55
+ newPageId = _ref.newPageId,
56
+ viewOnly = _ref.viewOnly;
84
57
  return /*#__PURE__*/_react.default.createElement(_context.HooksContextProvider, {
85
58
  overrides: hooks
86
59
  }, /*#__PURE__*/_react.default.createElement(_context.ValidationContextProvider, null, /*#__PURE__*/_react.default.createElement(InternalFormRenderer, {
@@ -102,175 +75,158 @@ var FormRenderer = function FormRenderer(_ref) {
102
75
  viewOnly: viewOnly
103
76
  })));
104
77
  };
105
-
106
78
  var DEFAULT_CLASS = 'hods-form';
107
79
  exports.DEFAULT_CLASS = DEFAULT_CLASS;
108
-
109
80
  var InternalFormRenderer = function InternalFormRenderer(_ref2) {
110
81
  var _formState$page4, _formState$page$actio, _formState$cya$hideCh, _formState$cya$hideGr;
111
-
112
82
  var title = _ref2.title,
113
- type = _ref2.type,
114
- components = _ref2.components,
115
- _pages = _ref2.pages,
116
- _hub = _ref2.hub,
117
- cya = _ref2.cya,
118
- _data = _ref2.data,
119
- classBlock = _ref2.classBlock,
120
- classModifiers = _ref2.classModifiers,
121
- className = _ref2.className,
122
- hashLink = _ref2.hashLink,
123
- hide_title = _ref2.hide_title,
124
- summaryListClassModifiers = _ref2.summaryListClassModifiers,
125
- noChangeAction = _ref2.noChangeAction,
126
- newPageId = _ref2.newPageId,
127
- viewOnly = _ref2.viewOnly;
128
-
83
+ type = _ref2.type,
84
+ components = _ref2.components,
85
+ _pages = _ref2.pages,
86
+ _hub = _ref2.hub,
87
+ cya = _ref2.cya,
88
+ _data = _ref2.data,
89
+ classBlock = _ref2.classBlock,
90
+ classModifiers = _ref2.classModifiers,
91
+ className = _ref2.className,
92
+ hashLink = _ref2.hashLink,
93
+ hide_title = _ref2.hide_title,
94
+ summaryListClassModifiers = _ref2.summaryListClassModifiers,
95
+ noChangeAction = _ref2.noChangeAction,
96
+ newPageId = _ref2.newPageId,
97
+ viewOnly = _ref2.viewOnly;
129
98
  // Set up the initial states.
130
99
  var _useState = (0, _react.useState)({}),
131
- _useState2 = _slicedToArray(_useState, 2),
132
- data = _useState2[0],
133
- setData = _useState2[1];
134
-
100
+ _useState2 = _slicedToArray(_useState, 2),
101
+ data = _useState2[0],
102
+ setData = _useState2[1];
135
103
  var _useState3 = (0, _react.useState)(),
136
- _useState4 = _slicedToArray(_useState3, 2),
137
- submitted = _useState4[0],
138
- setSubmitted = _useState4[1];
139
-
104
+ _useState4 = _slicedToArray(_useState3, 2),
105
+ submitted = _useState4[0],
106
+ setSubmitted = _useState4[1];
140
107
  var _useState5 = (0, _react.useState)([]),
141
- _useState6 = _slicedToArray(_useState5, 2),
142
- pages = _useState6[0],
143
- setPages = _useState6[1];
144
-
108
+ _useState6 = _slicedToArray(_useState5, 2),
109
+ pages = _useState6[0],
110
+ setPages = _useState6[1];
145
111
  var _useState7 = (0, _react.useState)(undefined),
146
- _useState8 = _slicedToArray(_useState7, 2),
147
- hub = _useState8[0],
148
- setHub = _useState8[1];
149
-
112
+ _useState8 = _slicedToArray(_useState7, 2),
113
+ hub = _useState8[0],
114
+ setHub = _useState8[1];
150
115
  var _useState9 = (0, _react.useState)(_helpers.default.getNextPageId(type, _pages, null, null, _data)),
151
- _useState10 = _slicedToArray(_useState9, 2),
152
- pageId = _useState10[0],
153
- setPageId = _useState10[1];
154
-
116
+ _useState10 = _slicedToArray(_useState9, 2),
117
+ pageId = _useState10[0],
118
+ setPageId = _useState10[1];
155
119
  var _useState11 = (0, _react.useState)(_helpers.default.getFormState(pageId, pages, hub)),
156
- _useState12 = _slicedToArray(_useState11, 2),
157
- formState = _useState12[0],
158
- setFormState = _useState12[1];
159
-
120
+ _useState12 = _slicedToArray(_useState11, 2),
121
+ formState = _useState12[0],
122
+ setFormState = _useState12[1];
160
123
  var _useState13 = (0, _react.useState)({}),
161
- _useState14 = _slicedToArray(_useState13, 2),
162
- currentTask = _useState14[0],
163
- setCurrentTask = _useState14[1];
164
-
124
+ _useState14 = _slicedToArray(_useState13, 2),
125
+ currentTask = _useState14[0],
126
+ setCurrentTask = _useState14[1];
165
127
  var _useState15 = (0, _react.useState)({}),
166
- _useState16 = _slicedToArray(_useState15, 2),
167
- hubDetails = _useState16[0],
168
- setHubDetails = _useState16[1];
169
-
128
+ _useState16 = _slicedToArray(_useState15, 2),
129
+ hubDetails = _useState16[0],
130
+ setHubDetails = _useState16[1];
170
131
  var _useState17 = (0, _react.useState)('load'),
171
- _useState18 = _slicedToArray(_useState17, 2),
172
- pagePoint = _useState18[0],
173
- setPagePoint = _useState18[1];
174
-
132
+ _useState18 = _slicedToArray(_useState17, 2),
133
+ pagePoint = _useState18[0],
134
+ setPagePoint = _useState18[1];
175
135
  var _useState19 = (0, _react.useState)(false),
176
- _useState20 = _slicedToArray(_useState19, 2),
177
- goingBack = _useState20[0],
178
- setGoingBack = _useState20[1]; // Set up hooks.
179
-
136
+ _useState20 = _slicedToArray(_useState19, 2),
137
+ goingBack = _useState20[0],
138
+ setGoingBack = _useState20[1];
180
139
 
140
+ // Set up hooks.
181
141
  var _useHooks = (0, _hooks.useHooks)(),
182
- hooks = _useHooks.hooks; // Set up the useValidation hook.
183
-
142
+ hooks = _useHooks.hooks;
184
143
 
144
+ // Set up the useValidation hook.
185
145
  var _useValidation = (0, _hooks.useValidation)(),
186
- addErrors = _useValidation.addErrors,
187
- clearErrors = _useValidation.clearErrors,
188
- validate = _useValidation.validate; // Need to set submission data when going back
189
-
146
+ addErrors = _useValidation.addErrors,
147
+ clearErrors = _useValidation.clearErrors,
148
+ validate = _useValidation.validate;
190
149
 
150
+ // Need to set submission data when going back
191
151
  window.onpopstate = function (e) {
192
152
  var _formState$page;
193
-
194
153
  if (document.location.hash) {
195
154
  return;
196
155
  }
197
-
198
156
  if (e.state && e.state.fullPages !== undefined) {
199
157
  setCurrentTask(function (prev) {
200
158
  var _e$state;
201
-
202
159
  return _objectSpread(_objectSpread({}, prev), {}, {
203
160
  fullPages: (_e$state = e.state) === null || _e$state === void 0 ? void 0 : _e$state.fullPages
204
161
  });
205
162
  });
206
163
  }
207
-
208
164
  setGoingBack(true);
209
165
  hooks.onGoingBack();
210
166
  clearErrors();
211
-
212
167
  if (components && pages && data && (_formState$page = formState.page) !== null && _formState$page !== void 0 && _formState$page.formData && pagePoint === undefined) {
213
168
  var submissionData = _utils.default.Format.form({
214
169
  pages: pages,
215
170
  components: components
216
171
  }, _objectSpread(_objectSpread({}, data), formState.page.formData), _models.EventTypes.SUBMIT);
217
-
218
172
  setData(submissionData);
219
173
  }
220
- }; // Setup data.
221
-
174
+ };
222
175
 
176
+ // Setup data.
223
177
  (0, _react.useEffect)(function () {
224
178
  if (components && _pages && _data && (pagePoint === 'load' || viewOnly)) {
225
179
  var _data$formStatus;
226
-
227
180
  setData(_utils.default.Data.setupForm(_pages, components, _data));
228
-
229
181
  if ((_data$formStatus = _data.formStatus) !== null && _data$formStatus !== void 0 && _data$formStatus.page) {
230
182
  setPageId(_data.formStatus.page);
231
183
  }
232
184
  }
233
- }, [components, _pages, _data, setData, pagePoint, viewOnly]); // Setup pages.
185
+ }, [components, _pages, _data, setData, pagePoint, viewOnly]);
234
186
 
187
+ // Setup pages.
235
188
  (0, _react.useEffect)(function () {
236
189
  setPages(_utils.default.FormPage.getAll(_pages, components, _objectSpread({}, data)));
237
- }, [components, _pages, data, setPages]); // Setup initial pageId.
190
+ }, [components, _pages, data, setPages]);
238
191
 
192
+ // Setup initial pageId.
239
193
  (0, _react.useEffect)(function () {
240
194
  setPageId(function (prev) {
241
195
  return prev || _helpers.default.getNextPageId(type, pages);
242
196
  });
243
- }, [type, pages, setPageId]); // Setup hub.
197
+ }, [type, pages, setPageId]);
244
198
 
199
+ // Setup hub.
245
200
  (0, _react.useEffect)(function () {
246
201
  setHub(_utils.default.Hub.get(type, _hub, components, _objectSpread({}, data)));
247
- }, [type, _hub, data, components, setHub]); // Form state.
202
+ }, [type, _hub, data, components, setHub]);
248
203
 
204
+ // Form state.
249
205
  (0, _react.useEffect)(function () {
250
206
  var _formState$page2;
251
-
252
207
  // revert formData changes if going back in hub-and-spoke
253
208
  if (type === _models.FormTypes.HUB && goingBack && data && (_formState$page2 = formState.page) !== null && _formState$page2 !== void 0 && _formState$page2.formData) {
254
209
  formState.page.formData = _objectSpread({}, data);
255
210
  }
256
-
257
211
  setGoingBack(false);
258
212
  setFormState(_helpers.default.getFormState(pageId, pages, hub));
259
- }, [pages, hub, pageId, setFormState, type, goingBack, data, formState.page]); // Call the onFormLoad hook just when this component first renders.
213
+ }, [pages, hub, pageId, setFormState, type, goingBack, data, formState.page]);
260
214
 
215
+ // Call the onFormLoad hook just when this component first renders.
261
216
  (0, _react.useEffect)(function () {
262
- setPagePoint(undefined); // In case of refresh the current task needs to be reset
263
-
217
+ setPagePoint(undefined);
218
+ // In case of refresh the current task needs to be reset
264
219
  hooks.onFormLoad(function (currentTask) {
265
220
  return setCurrentTask(currentTask);
266
221
  });
267
222
  }, [hooks]);
268
223
  (0, _react.useEffect)(function () {
269
224
  setHubDetails(_hub);
270
- }, [_hub]); // Calling setData directly within the hooks.onSubmit success handler
225
+ }, [_hub]);
226
+
227
+ // Calling setData directly within the hooks.onSubmit success handler
271
228
  // resulted in a sychronisation error. Handling it in a useEffect appears
272
229
  // to be the way to deal with this... and it certainly seems to work.
273
-
274
230
  (0, _react.useEffect)(function () {
275
231
  if (submitted !== null && submitted !== void 0 && submitted.data) {
276
232
  setData(submitted.data);
@@ -278,11 +234,10 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
278
234
  }
279
235
  }, [submitted, setData, setSubmitted]);
280
236
  var theSections = _hub === null || _hub === void 0 ? void 0 : _hub.sections;
281
- var nonSequential = _hub === null || _hub === void 0 ? void 0 : _hub.nonSequential; // Update task list pages with form data and update states
282
-
237
+ var nonSequential = _hub === null || _hub === void 0 ? void 0 : _hub.nonSequential;
238
+ // Update task list pages with form data and update states
283
239
  (0, _react.useEffect)(function () {
284
240
  var pages = currentTask.fullPages;
285
-
286
241
  if (pages) {
287
242
  pages.forEach(function (page) {
288
243
  if (page) {
@@ -295,14 +250,10 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
295
250
  });
296
251
  });
297
252
  }
298
-
299
253
  if (theSections) {
300
254
  var _data$formStatus2;
301
-
302
255
  var tasks = (data === null || data === void 0 ? void 0 : (_data$formStatus2 = data.formStatus) === null || _data$formStatus2 === void 0 ? void 0 : _data$formStatus2.tasks) || {};
303
-
304
256
  var updatedSections = _helpers.default.getUpdatedSectionStates(theSections, tasks, nonSequential, data);
305
-
306
257
  setHubDetails(function (prev) {
307
258
  return _objectSpread(_objectSpread({}, prev), {}, {
308
259
  sections: [].concat(updatedSections)
@@ -310,165 +261,33 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
310
261
  });
311
262
  }
312
263
  }, [currentTask.fullPages, data, theSections, nonSequential]);
313
-
314
264
  var onPageChange = function onPageChange(newPageId) {
315
265
  var state = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
316
266
  clearErrors();
317
267
  setPageId(newPageId);
318
268
  hooks.onPageChange(newPageId, state);
319
269
  };
320
-
321
270
  (0, _react.useEffect)(function () {
322
271
  if (newPageId !== undefined) setPageId(newPageId);
323
- }, [newPageId]); // Handle change to form data in pages.
272
+ }, [newPageId]);
324
273
 
274
+ // Handle change to form data in pages.
325
275
  var onChange = function onChange(data) {
326
276
  hooks.onChange(data);
327
- }; // Handle actions from pages.
328
- // (patch captures payload-ready field name and value,
329
- // patchLabel captures non-ID values
330
- // for display purposes after submission.)
331
-
332
-
333
- var onPageAction = function onPageAction(action, patch, patchLabel) {
334
- if (action.type === _models.PageAction.TYPES.CANCEL) {
335
- hooks.onCancel();
336
- return;
337
- } // Save a copy of data in case submit errors and we need to revert
338
-
339
-
340
- var preSubmitData = _objectSpread({}, data); // Re-apply the patch to the page's formData.
341
- // This should normally have no effect but will prevent issues
342
- // with validation if formData happens to have been wiped.
343
-
344
-
345
- formState.page.formData = _objectSpread(_objectSpread({}, formState.page.formData), patch); // Check to see whether the action is able to proceed, which in
346
- // in the case of a submission will validate the fields in the page.
347
-
348
- if (_helpers.default.canActionProceed(action, formState.page, validate.page)) {
349
- patch = _helpers.default.cleanHiddenNestedData(patch, formState.page);
350
-
351
- if (action.addToFormData) {
352
- formState.page.formData[action.addToFormData.field] = action.addToFormData.value;
353
- }
354
-
355
- if (action.type === _models.PageAction.TYPES.NAVIGATE) {
356
- _handlers.default.navigate(action, pageId, onPageChange);
357
- } else {
358
- var pageUpdate = function pageUpdate(next) {
359
- return onPageChange(_helpers.default.getNextPageId(type, pages, pageId, action, next));
360
- };
361
-
362
- switch (action.type) {
363
- case _models.PageAction.TYPES.SUBMIT:
364
- setPagePoint('submit');
365
- break;
366
-
367
- case _models.PageAction.TYPES.SAVE_AND_NAVIGATE:
368
- var state = _objectSpread({}, currentTask);
369
-
370
- pageUpdate = function pageUpdate() {
371
- return _handlers.default.navigate(action, pageId, onPageChange, state);
372
- };
373
-
374
- break;
375
-
376
- case _models.PageAction.TYPES.COLLECTION_ADD:
377
- formState.page.formData["".concat(action.collection, "ActiveId")] = Date.now().toString();
378
-
379
- pageUpdate = function pageUpdate() {
380
- return _handlers.default.navigate(action, pageId, onPageChange);
381
- };
382
-
383
- break;
384
-
385
- case _models.PageAction.TYPES.COLLECTION_DUPLICATE:
386
- if (_utils.default.CollectionPage.duplicateActiveEntry(action.collection, formState.page.formData)) {
387
- pageUpdate = function pageUpdate() {
388
- return _handlers.default.navigate(action, pageId, onPageChange);
389
- };
390
- }
391
-
392
- break;
393
-
394
- case _models.PageAction.TYPES.COLLECTION_REMOVE:
395
- var activeId = formState.page.formData["".concat(action.collection, "ActiveId")];
396
- formState.page.formData["".concat(action.collection)] = formState.page.formData["".concat(action.collection)].map(function (entry) {
397
- if (entry.id === activeId) {
398
- // Store the entry.
399
- if (action.recordRemoval) {
400
- formState.page.formData["".concat(action.collection, "LastRemoved")] = _objectSpread({}, entry);
401
- }
402
-
403
- return null;
404
- }
405
-
406
- return entry;
407
- }).filter(function (e) {
408
- return !!e;
409
- });
410
- break;
411
-
412
- default:
413
- break;
414
- } // Save draft or submit.
415
-
416
-
417
- var submissionData = _utils.default.Format.form({
418
- pages: pages,
419
- components: components
420
- }, _objectSpread(_objectSpread(_objectSpread({}, data), patch), formState.page.formData), _models.EventTypes.SUBMIT);
421
-
422
- submissionData.formStatus = _helpers.default.getSubmissionStatus(type, pages, pageId, action, submissionData, currentTask, true, hubDetails === null || hubDetails === void 0 ? void 0 : hubDetails.sections);
423
-
424
- if (patch) {
425
- setData(submissionData);
426
- } // In case of hub-and-spoke if patchLabel has changed then
427
- // save name and value to variables for call to onSubmit hook
428
-
429
-
430
- var changedFieldName;
431
- var changedFieldValue;
432
-
433
- if (type === _models.FormTypes.HUB && patchLabel && Object.keys(patchLabel).length > 0) {
434
- changedFieldName = Object.keys(patchLabel)[0];
435
- changedFieldValue = Object.values(patchLabel)[0];
436
- } // Now submit the data to the backend...
437
-
438
-
439
- hooks.onSubmit(action.type, submissionData, function (response) {
440
- // The backend response may well contain data we need so apply it...
441
- // ... but this needs to happen in a useEffect, not right away.
442
- var sData = _objectSpread(_objectSpread({}, submissionData), response);
443
-
444
- setSubmitted({
445
- data: sData
446
- });
447
- pageUpdate(sData);
448
- }, function (errors) {
449
- _handlers.default.submissionError(errors, addErrors);
277
+ };
450
278
 
451
- setData(_objectSpread({}, preSubmitData));
452
- }, changedFieldName, changedFieldValue);
453
- }
454
- }
455
- }; // Handle navigation from "Check your answers".
279
+ // Handle navigation from "Check your answers".
456
280
  // Passing a dataCallback allows changes to formData from the
457
281
  // CYA screen. This is necessary to allow changing the active
458
282
  // entry in page collections.
459
-
460
-
461
283
  var onCYARowAction = function onCYARowAction(page, dataCallback) {
462
284
  var _formState$page3;
463
-
464
285
  if (typeof dataCallback === 'function') {
465
286
  var newData = dataCallback(_objectSpread({}, data));
466
-
467
287
  if (newData) {
468
288
  setData(newData);
469
289
  }
470
290
  }
471
-
472
291
  if (((_formState$page3 = formState.page) === null || _formState$page3 === void 0 ? void 0 : _formState$page3.type) === _models.FormPages.PARTIAL_CYA) {
473
292
  hubDetails.sections.every(function (section) {
474
293
  return section.tasks.every(function (task) {
@@ -476,18 +295,16 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
476
295
  onTaskAction(task);
477
296
  return false;
478
297
  }
479
-
480
298
  return true;
481
299
  });
482
300
  });
483
301
  }
484
-
485
302
  if (page) {
486
303
  _handlers.default.cyaAction(page, pageId, onPageChange);
487
304
  }
488
- }; //Kick off a task, gather required pages and move to the correct point
489
-
305
+ };
490
306
 
307
+ //Kick off a task, gather required pages and move to the correct point
491
308
  var onTaskAction = function onTaskAction(currentTask) {
492
309
  if (currentTask) {
493
310
  currentTask.fullPages = [];
@@ -495,9 +312,7 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
495
312
  currentTask.fullPages.push(_helpers.default.getPage(page, pages));
496
313
  });
497
314
  setCurrentTask(currentTask);
498
-
499
315
  var state = _objectSpread({}, currentTask);
500
-
501
316
  if (currentTask.state === _models.TaskStates.TYPES.COMPLETE) {
502
317
  if (hubDetails !== null && hubDetails !== void 0 && hubDetails.noTaskCYAs) {
503
318
  // If the task is complete and there are no CYA's then show user first page
@@ -519,13 +334,10 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
519
334
  }
520
335
  }
521
336
  };
522
-
523
337
  var classes = _utils.default.classBuilder(classBlock, classModifiers, className);
524
-
525
338
  if (hub === _models.HubFormats.TASK) {
526
339
  cya.actions = [_models.PageAction.TYPES.SAVE_AND_CONTINUE, _models.PageAction.TYPES.SAVE_AND_RETURN];
527
340
  }
528
-
529
341
  return /*#__PURE__*/_react.default.createElement("div", {
530
342
  className: classes()
531
343
  }, title && !hide_title && pageId === _models.FormPages.HUB && /*#__PURE__*/_react.default.createElement(_copReactComponents.LargeHeading, null, title), formState.cya && /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, _extends({
@@ -551,22 +363,20 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
551
363
  formData: data
552
364
  })), formState.page && !formState.cya && !formState.page.collection && /*#__PURE__*/_react.default.createElement(_FormPage.default, {
553
365
  page: formState.page,
554
- onAction: onPageAction,
366
+ onAction: function onAction(action, patch, patchLabel) {
367
+ (0, _onPageAction.default)(action, patch, patchLabel, hooks, data, formState, validate, onPageChange, type, pages, components, pageId, setPagePoint, currentTask, setData, hubDetails, setSubmitted, addErrors);
368
+ },
555
369
  onChange: onChange,
556
- hashLink: hashLink,
557
- classModifiers: formState.page.classModifiers,
558
- className: formState.page.className
370
+ hashLink: hashLink
559
371
  }), formState.page && !formState.cya && formState.page.collection && /*#__PURE__*/_react.default.createElement(_CollectionPage.default, {
560
372
  page: formState.page,
561
- onAction: onPageAction,
562
- classModifiers: formState.page.classModifiers,
563
- className: formState.page.className
373
+ onAction: function onAction(action, patch, patchLabel) {
374
+ (0, _onPageAction.default)(action, patch, patchLabel, hooks, data, formState, validate, onPageChange, type, pages, components, pageId, setPagePoint, currentTask, setData, hubDetails, setSubmitted, addErrors);
375
+ }
564
376
  }));
565
377
  };
566
-
567
378
  FormRenderer.propTypes = InternalFormRenderer.propTypes = {
568
379
  title: _propTypes.default.string,
569
-
570
380
  /** See <a href="/?path=/docs/f-json--page#formtypes">FormTypes</a>. */
571
381
  type: _propTypes.default.oneOf([_models.FormTypes.CYA, _models.FormTypes.FORM, _models.FormTypes.HUB, _models.FormTypes.TASK, _models.FormTypes.WIZARD, _models.FormTypes.TASK_CYA, _models.FormTypes.FORM_WITH_TASK]).isRequired,
572
382
  components: _propTypes.default.arrayOf(_propTypes.default.object).isRequired,