@ukhomeoffice/cop-react-form-renderer 2.8.1 → 2.8.3

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.
@@ -208,7 +208,7 @@ var FormRenderer = function FormRenderer(_ref) {
208
208
  components: components
209
209
  }, _objectSpread(_objectSpread({}, data), patch), _models.EventTypes.SUBMIT);
210
210
 
211
- submissionData.formStatus = _helpers.default.getSubmissionStatus(type, pages, pageId, action, submissionData, currentTask);
211
+ submissionData.formStatus = _helpers.default.getSubmissionStatus(type, pages, pageId, action, submissionData, currentTask, true);
212
212
 
213
213
  if (patch) {
214
214
  setData(submissionData);
@@ -256,6 +256,9 @@ var FormRenderer = function FormRenderer(_ref) {
256
256
 
257
257
  if (currentTask.state === _models.TaskStates.TYPES.COMPLETE) {
258
258
  onPageChange(_models.FormPages.CYA);
259
+ } else if (currentTask.state === _models.TaskStates.TYPES.IN_PROGRESS) {
260
+ var currentPage = data.formStatus.tasks[currentTask.name].currentPage;
261
+ onPageChange(currentPage || currentTask.pages[0]);
259
262
  } else {
260
263
  onPageChange(currentTask.pages[0]);
261
264
  }
@@ -274,7 +277,7 @@ var FormRenderer = function FormRenderer(_ref) {
274
277
  components: components
275
278
  }, _objectSpread({}, data), _models.EventTypes.SUBMIT);
276
279
 
277
- submissionData.formStatus = _helpers.default.getSubmissionStatus(type, pages, pageId, action);
280
+ submissionData.formStatus = _helpers.default.getSubmissionStatus(type, pages, pageId, action, submissionData, currentTask, true);
278
281
  setData(submissionData); // Now submit the data to the backend...
279
282
 
280
283
  hooks.onSubmit(action.type, submissionData, function () {
@@ -285,14 +288,14 @@ var FormRenderer = function FormRenderer(_ref) {
285
288
  }
286
289
  }
287
290
 
288
- if (action.type === _models.PageAction.TYPES.SAVE_AND_RETURN) {
291
+ if (action.type === _models.PageAction.TYPES.SAVE_AND_CONTINUE && hub === _models.HubFormats.TASK) {
289
292
  if (_helpers.default.canCYASubmit(currentTask.fullPages, onError)) {
290
293
  var _submissionData = _utils.default.Format.form({
291
294
  pages: pages,
292
295
  components: components
293
296
  }, _objectSpread({}, data), _models.EventTypes.SUBMIT);
294
297
 
295
- _submissionData.formStatus = _helpers.default.getSubmissionStatus(type, pages, pageId, action, _submissionData, currentTask);
298
+ _submissionData.formStatus = _helpers.default.getSubmissionStatus(type, pages, pageId, action, _submissionData, currentTask, true);
296
299
  setData(_submissionData);
297
300
  hooks.onSubmit(action.type, _submissionData, function () {
298
301
  return onPageChange(_models.FormPages.HUB);
@@ -301,16 +304,33 @@ var FormRenderer = function FormRenderer(_ref) {
301
304
  });
302
305
  }
303
306
  }
307
+
308
+ if (action.type === _models.PageAction.TYPES.SAVE_AND_RETURN) {
309
+ if (_helpers.default.canCYASubmit(currentTask.fullPages, onError)) {
310
+ var _submissionData2 = _utils.default.Format.form({
311
+ pages: pages,
312
+ components: components
313
+ }, _objectSpread({}, data), _models.EventTypes.SUBMIT);
314
+
315
+ _submissionData2.formStatus = _helpers.default.getSubmissionStatus(type, pages, pageId, action, _submissionData2, currentTask);
316
+ setData(_submissionData2);
317
+ hooks.onSubmit(action.type, _submissionData2, function () {
318
+ if (type === _models.FormTypes.TASK) {
319
+ onPageChange(undefined);
320
+ } else {
321
+ onPageChange(_models.FormPages.HUB);
322
+ }
323
+ }, function (errors) {
324
+ return _handlers.default.submissionError(errors, onError);
325
+ });
326
+ }
327
+ }
304
328
  };
305
329
 
306
330
  var classes = _utils.default.classBuilder(classBlock, classModifiers, className);
307
331
 
308
332
  if (hub === _models.HubFormats.TASK) {
309
- cya.actions = [{
310
- type: _models.PageAction.TYPES.SAVE_AND_RETURN,
311
- label: 'Submit',
312
- validate: true
313
- }];
333
+ cya.actions = [_models.PageAction.TYPES.SAVE_AND_CONTINUE, _models.PageAction.TYPES.SAVE_AND_RETURN];
314
334
  }
315
335
 
316
336
  return /*#__PURE__*/_react.default.createElement("div", {
@@ -633,7 +633,8 @@ describe('components', function () {
633
633
 
634
634
  cyaPage = container.childNodes[0].childNodes[0];
635
635
  expect(cyaPage.childNodes[0].textContent).toEqual('Check your answers');
636
- expect(cyaPage.childNodes[5].textContent).toEqual('Submit');
636
+ expect(cyaPage.childNodes[5].childNodes[0].textContent).toEqual('Save and continue');
637
+ expect(cyaPage.childNodes[5].childNodes[1].textContent).toEqual('Save and return later');
637
638
 
638
639
  _react.fireEvent.click(cyaPage.childNodes[5].childNodes[0], {}); //Should be back at task list
639
640
 
@@ -650,7 +651,7 @@ describe('components', function () {
650
651
  expect(finalSubmit.mode).toEqual('sea');
651
652
  expect(finalSubmit.formStatus.tasks['Date, location and mode details'].complete).toEqual(true);
652
653
 
653
- case 38:
654
+ case 39:
654
655
  case "end":
655
656
  return _context18.stop();
656
657
  }
@@ -11,18 +11,18 @@ var _getNextPageId = _interopRequireDefault(require("./getNextPageId"));
11
11
 
12
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
13
 
14
- var getSubmissionStatus = function getSubmissionStatus(formType, pages, currentPageId, action, formData, currentTask) {
14
+ var getSubmissionStatus = function getSubmissionStatus(formType, pages, currentPageId, action, formData, currentTask, isCompleted) {
15
15
  if (formType === _models.FormTypes.TASK) {
16
16
  var formStatus = formData.formStatus ? formData.formStatus : {};
17
17
  formStatus.tasks = formStatus.tasks ? formStatus.tasks : {};
18
18
  formStatus.tasks[currentTask.name] = formStatus.tasks[currentTask.name] ? formStatus.tasks[currentTask.name] : {};
19
19
 
20
- if (currentPageId === _models.FormPages.CYA) {
20
+ if (currentPageId === (_models.FormPages.CYA || 'submitForm') && isCompleted) {
21
21
  formStatus.tasks[currentTask.name].complete = true;
22
22
  } else {
23
23
  formStatus.tasks[currentTask.name] = {
24
24
  complete: false,
25
- currentPage: action.page
25
+ currentPage: currentPageId
26
26
  };
27
27
  }
28
28
 
@@ -210,19 +210,19 @@ describe('components', function () {
210
210
  });
211
211
  describe("when the form type is '".concat(_models.FormTypes.TASK, "'"), function () {
212
212
  var FORM_TYPE = _models.FormTypes.TASK;
213
- it("should mark the current task as complete if the current page is '".concat(_models.FormPages.CYA, "'"), function () {
213
+ it("should mark the current task as complete if the current page is '".concat(_models.FormPages.CYA, "' and it is marked as complete"), function () {
214
214
  var CURRENT_PAGE_ID = _models.FormPages.CYA;
215
215
  var TASK_NAME = 'taskName';
216
216
  var CURRENT_TASK = {
217
217
  name: TASK_NAME
218
218
  };
219
- expect((0, _getSubmissionStatus.default)(FORM_TYPE, PAGES, CURRENT_PAGE_ID, undefined, {}, CURRENT_TASK)).toMatchObject({
219
+ expect((0, _getSubmissionStatus.default)(FORM_TYPE, PAGES, CURRENT_PAGE_ID, undefined, {}, CURRENT_TASK, true)).toMatchObject({
220
220
  tasks: _defineProperty({}, TASK_NAME, {
221
221
  complete: true
222
222
  })
223
223
  });
224
224
  });
225
- it("should update the current task with the next page and a false complete flag if the current page is not '".concat(_models.FormPages.CYA, "'"), function () {
225
+ it("should update the current task with the current page and a false complete flag if the current page is not '".concat(_models.FormPages.CYA, "'"), function () {
226
226
  var CURRENT_PAGE_ID = 'eventDate';
227
227
  var TASK_NAME = 'taskName';
228
228
  var CURRENT_TASK = {
@@ -236,7 +236,7 @@ describe('components', function () {
236
236
  expect((0, _getSubmissionStatus.default)(FORM_TYPE, PAGES, CURRENT_PAGE_ID, ACTION, {}, CURRENT_TASK)).toMatchObject({
237
237
  tasks: _defineProperty({}, TASK_NAME, {
238
238
  complete: false,
239
- currentPage: NEXT_PAGE_ID
239
+ currentPage: CURRENT_PAGE_ID
240
240
  })
241
241
  });
242
242
  });
@@ -65,7 +65,13 @@ var Task = function Task(_ref) {
65
65
  }, linkActive ? /*#__PURE__*/_react.default.createElement(_copReactComponents.Link, {
66
66
  onClick: function onClick() {
67
67
  return _onClick(task);
68
- }
68
+ },
69
+ onKeyPress: function onKeyPress(event) {
70
+ if (event.key === 'Enter') {
71
+ _onClick(task);
72
+ }
73
+ },
74
+ tabIndex: "0"
69
75
  }, task.name) : task.name), /*#__PURE__*/_react.default.createElement(_TaskState.default, {
70
76
  state: currentState
71
77
  }));
@@ -11,7 +11,7 @@
11
11
  min-width: 550px;
12
12
  }
13
13
  .hods-task-list__items {
14
- @include govuk-font($size: 19);
14
+ font-size: 19px;
15
15
  @include govuk-responsive-margin(9, 'bottom');
16
16
  list-style: none;
17
17
  padding-left: 0;
@@ -21,7 +21,8 @@
21
21
 
22
22
  .hods-task-list__section {
23
23
  display: table;
24
- @include govuk-font($size: 24, $weight: bold);
24
+ font-size: 24px;
25
+ font-weight: bold;
25
26
  }
26
27
 
27
28
  .hods-task-list__section-number {
@@ -46,10 +47,11 @@
46
47
 
47
48
  .hods-task-list__task-name {
48
49
  display: block;
49
- cursor: pointer;
50
+ cursor: auto;
50
51
  @include govuk-media-query($from: 450px) {
51
52
  float: left;
52
53
  }
54
+ font-weight: normal;
53
55
  }
54
56
 
55
57
  .hods-task-reference-description{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "2.8.1",
3
+ "version": "2.8.3",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",