@tsed/react-formio 1.11.1 → 1.13.0

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 (152) hide show
  1. package/.env +2 -1
  2. package/craco.config.js +11 -1
  3. package/dist/components/alert/alert.component.spec.d.ts +1 -0
  4. package/dist/components/alert/alert.stories.d.ts +15 -0
  5. package/dist/components/card/card.component.d.ts +2 -1
  6. package/dist/components/form/form.component.d.ts +2 -0
  7. package/dist/components/form/form.stories.d.ts +37 -0
  8. package/dist/components/form/useForm.hook.d.ts +1 -0
  9. package/dist/components/form-action/formAction.stories.d.ts +90 -414
  10. package/dist/components/input-text/inputText.component.d.ts +1 -1
  11. package/dist/components/input-text/inputText.component.spec.d.ts +1 -0
  12. package/dist/components/loader/loader.component.d.ts +2 -2
  13. package/dist/components/loader/loader.stories.d.ts +15 -0
  14. package/dist/components/pagination/pagination.component.spec.d.ts +1 -0
  15. package/dist/components/pagination/pagination.stories.d.ts +0 -27
  16. package/dist/components/select/select.component.spec.d.ts +1 -0
  17. package/dist/components/tabs/tabs.component.spec.d.ts +1 -0
  18. package/dist/index.js +114 -35
  19. package/dist/index.js.map +1 -1
  20. package/dist/index.modern.js +86 -34
  21. package/dist/index.modern.js.map +1 -1
  22. package/jest.config.js +1 -1
  23. package/package.json +5 -9
  24. package/readme.md +114 -86
  25. package/src/components/__fixtures__/form-schema.json +10 -42
  26. package/src/components/__fixtures__/form.fixture.json +1 -1
  27. package/src/components/actions-table/actionsTable.component.spec.tsx +4 -13
  28. package/src/components/actions-table/actionsTable.component.tsx +3 -11
  29. package/src/components/alert/alert.component.spec.tsx +97 -0
  30. package/src/components/alert/alert.component.tsx +2 -8
  31. package/src/components/alert/alert.stories.tsx +17 -0
  32. package/src/components/card/card.component.tsx +2 -5
  33. package/src/components/form/form.component.tsx +4 -8
  34. package/src/components/form/form.stories.tsx +66 -2
  35. package/src/components/form/useForm.hook.ts +29 -14
  36. package/src/components/form-access/formAccess.component.tsx +19 -82
  37. package/src/components/form-access/formAccess.schema.ts +7 -23
  38. package/src/components/form-access/formAccess.stories.tsx +2 -9
  39. package/src/components/form-access/formAccess.utils.spec.ts +4 -22
  40. package/src/components/form-access/formAccess.utils.ts +7 -29
  41. package/src/components/form-action/formAction.component.tsx +3 -19
  42. package/src/components/form-action/formAction.stories.tsx +251 -672
  43. package/src/components/form-builder/formBuilder.component.tsx +4 -13
  44. package/src/components/form-builder/formBuilder.stories.tsx +12 -24
  45. package/src/components/form-control/formControl.component.tsx +2 -8
  46. package/src/components/form-edit/formCtas.component.tsx +5 -23
  47. package/src/components/form-edit/formEdit.component.tsx +2 -20
  48. package/src/components/form-edit/formEdit.reducer.ts +2 -8
  49. package/src/components/form-edit/formEdit.stories.tsx +3 -15
  50. package/src/components/form-edit/formParameters.component.tsx +3 -20
  51. package/src/components/form-edit/useFormEdit.hook.ts +2 -9
  52. package/src/components/form-settings/formSettings.component.spec.tsx +2 -9
  53. package/src/components/form-settings/formSettings.component.tsx +6 -34
  54. package/src/components/form-settings/formSettings.stories.tsx +1 -6
  55. package/src/components/form-settings/formSettings.utils.spec.ts +1 -4
  56. package/src/components/form-settings/formSettings.utils.ts +2 -7
  57. package/src/components/forms-table/components/formCell.component.tsx +2 -6
  58. package/src/components/forms-table/formsTable.component.tsx +2 -7
  59. package/src/components/input-tags/inputTags.component.tsx +10 -34
  60. package/src/components/input-tags/inputTags.stories.tsx +4 -14
  61. package/src/components/input-text/inputText.component.spec.tsx +56 -0
  62. package/src/components/input-text/inputText.component.tsx +4 -5
  63. package/src/components/input-text/inputText.stories.tsx +6 -26
  64. package/src/components/loader/loader.component.spec.tsx +7 -6
  65. package/src/components/loader/loader.component.tsx +3 -12
  66. package/src/components/loader/loader.stories.tsx +17 -0
  67. package/src/components/modal/modal.component.spec.tsx +8 -14
  68. package/src/components/modal/modal.component.tsx +6 -27
  69. package/src/components/modal/modal.stories.tsx +1 -5
  70. package/src/components/modal/removeModal.component.tsx +4 -22
  71. package/src/components/pagination/pagination.component.spec.tsx +111 -0
  72. package/src/components/pagination/pagination.component.tsx +10 -42
  73. package/src/components/pagination/pagination.stories.tsx +9 -29
  74. package/src/components/react-component/reactComponent.component.tsx +3 -11
  75. package/src/components/select/select.component.spec.tsx +86 -0
  76. package/src/components/select/select.component.tsx +11 -15
  77. package/src/components/select/select.stories.tsx +6 -26
  78. package/src/components/submissions-table/submissionsTable.component.tsx +1 -3
  79. package/src/components/submissions-table/submissionsTable.stories.tsx +1 -1
  80. package/src/components/table/components/defaultArrowSort.component.tsx +1 -10
  81. package/src/components/table/components/defaultCell.component.tsx +1 -4
  82. package/src/components/table/components/defaultCellHeader.component.tsx +4 -14
  83. package/src/components/table/components/defaultCellOperations.component.tsx +14 -25
  84. package/src/components/table/components/defaultOperationButton.component.tsx +2 -10
  85. package/src/components/table/filters/defaultColumnFilter.component.spec.tsx +1 -1
  86. package/src/components/table/filters/selectColumnFilter.component.spec.tsx +2 -10
  87. package/src/components/table/filters/selectColumnFilter.component.tsx +2 -6
  88. package/src/components/table/table.component.tsx +13 -53
  89. package/src/components/table/table.stories.tsx +1 -1
  90. package/src/components/table/utils/getPageNumbers.ts +3 -11
  91. package/src/components/table/utils/mapFormToColumns.tsx +14 -22
  92. package/src/components/table/utils/useOperations.hook.tsx +2 -12
  93. package/src/components/tabs/tabs.component.spec.tsx +86 -0
  94. package/src/components/tabs/tabs.component.stories.tsx +2 -9
  95. package/src/components/tabs/tabs.component.tsx +9 -43
  96. package/src/interfaces/Operation.ts +1 -4
  97. package/src/react-table.d.ts +9 -28
  98. package/src/stores/action/action.actions.ts +31 -33
  99. package/src/stores/action/action.reducers.spec.ts +1 -8
  100. package/src/stores/action/action.reducers.ts +1 -8
  101. package/src/stores/action/action.selectors.ts +1 -2
  102. package/src/stores/action-info/action-info.actions.spec.ts +1 -5
  103. package/src/stores/action-info/action-info.actions.ts +16 -19
  104. package/src/stores/action-info/action-info.reducers.spec.ts +1 -6
  105. package/src/stores/action-info/action-info.reducers.ts +1 -6
  106. package/src/stores/action-info/action-info.selectors.ts +1 -4
  107. package/src/stores/actions/actions.actions.spec.ts +1 -6
  108. package/src/stores/actions/actions.actions.ts +16 -19
  109. package/src/stores/actions/actions.reducers.spec.ts +1 -6
  110. package/src/stores/actions/actions.reducers.ts +1 -6
  111. package/src/stores/actions/actions.selectors.ts +2 -4
  112. package/src/stores/auth/auth.reducers.ts +1 -4
  113. package/src/stores/auth/auth.selectors.spec.ts +1 -5
  114. package/src/stores/auth/auth.selectors.ts +3 -6
  115. package/src/stores/auth/auth.utils.tsx +2 -8
  116. package/src/stores/auth/getAccess.action.spec.ts +11 -54
  117. package/src/stores/auth/getAccess.action.ts +1 -6
  118. package/src/stores/auth/initAuth.action.ts +15 -17
  119. package/src/stores/form/form.actions.spec.ts +8 -39
  120. package/src/stores/form/form.actions.ts +55 -64
  121. package/src/stores/form/form.reducers.spec.ts +1 -7
  122. package/src/stores/form/form.reducers.ts +1 -8
  123. package/src/stores/form/form.selectors.ts +1 -2
  124. package/src/stores/forms/forms.actions.spec.ts +5 -18
  125. package/src/stores/forms/forms.actions.ts +17 -21
  126. package/src/stores/forms/forms.reducers.spec.ts +1 -6
  127. package/src/stores/forms/forms.reducers.ts +2 -13
  128. package/src/stores/forms/forms.selectors.ts +2 -4
  129. package/src/stores/index.spec.ts +6 -9
  130. package/src/stores/root/root.selectors.spec.ts +1 -6
  131. package/src/stores/root/root.selectors.ts +6 -24
  132. package/src/stores/submission/submission.actions.spec.ts +11 -33
  133. package/src/stores/submission/submission.actions.ts +57 -66
  134. package/src/stores/submission/submission.reducers.spec.ts +17 -27
  135. package/src/stores/submission/submission.reducers.ts +1 -4
  136. package/src/stores/submission/submission.selectors.ts +1 -4
  137. package/src/stores/submissions/submissions.actions.spec.ts +5 -18
  138. package/src/stores/submissions/submissions.actions.ts +17 -26
  139. package/src/stores/submissions/submissions.reducers.spec.ts +3 -12
  140. package/src/stores/submissions/submissions.reducers.ts +3 -17
  141. package/src/stores/submissions/submissions.selectors.spec.ts +1 -4
  142. package/src/stores/submissions/submissions.selectors.ts +2 -4
  143. package/src/utils/getEventValue.ts +1 -4
  144. package/src/utils/iconClass.ts +2 -10
  145. package/src/utils/mapPagination.ts +1 -6
  146. package/src/utils/mapRequestParams.ts +2 -12
  147. package/src/utils/url.test.ts +4 -12
  148. package/src/utils/url.ts +2 -7
  149. package/tsconfig.json +4 -12
  150. package/tsconfig.test.json +1 -1
  151. package/.eslintrc +0 -47
  152. package/.prettierrc +0 -10
@@ -14,79 +14,70 @@ export const resetForm = createAction();
14
14
  export const sendForm = createAction();
15
15
 
16
16
  function shouldGet(form: Partial<FormSchema>, id: string) {
17
- return (
18
- form &&
19
- form.components &&
20
- Array.isArray(form.components) &&
21
- form.components.length &&
22
- form._id === id
23
- );
17
+ return form && form.components && Array.isArray(form.components) && form.components.length && form._id === id;
24
18
  }
25
19
 
26
- export const getForm = (name: string, id = "", done = noop) => async (
27
- dispatch: any,
28
- getState: any
29
- ) => {
30
- dispatch(clearFormError(name));
31
- // Check to see if the form is already loaded.
32
- const form = selectForm(name, getState());
20
+ export const getForm =
21
+ (name: string, id = "", done = noop) =>
22
+ async (dispatch: any, getState: any) => {
23
+ dispatch(clearFormError(name));
24
+ // Check to see if the form is already loaded.
25
+ const form = selectForm(name, getState());
33
26
 
34
- if (shouldGet(form, id)) {
35
- return;
36
- }
27
+ if (shouldGet(form, id)) {
28
+ return;
29
+ }
37
30
 
38
- const url = getFormUrl(id);
39
- const formio = new Formio(url);
31
+ const url = getFormUrl(id);
32
+ const formio = new Formio(url);
40
33
 
41
- dispatch(requestForm(name, { id, url }));
34
+ dispatch(requestForm(name, { id, url }));
42
35
 
43
- try {
44
- const form = await formio.loadForm();
36
+ try {
37
+ const form = await formio.loadForm();
45
38
 
46
- dispatch(receiveForm(name, { form, url }));
47
- dispatch(getActions(form._id));
48
- done(null, form);
49
- } catch (error) {
50
- dispatch(failForm(name, { error }));
51
- done({ error });
52
- }
53
- };
39
+ dispatch(receiveForm(name, { form, url }));
40
+ dispatch(getActions(form._id));
41
+ done(null, form);
42
+ } catch (error) {
43
+ dispatch(failForm(name, { error }));
44
+ done({ error });
45
+ }
46
+ };
54
47
 
55
- export const saveForm = (
56
- name: string,
57
- form: Partial<FormSchema>,
58
- done = noop
59
- ) => async (dispatch: any) => {
60
- dispatch(clearFormError(name));
61
- dispatch(sendForm(name, { form }));
48
+ export const saveForm =
49
+ (name: string, form: Partial<FormSchema>, done = noop) =>
50
+ async (dispatch: any) => {
51
+ dispatch(clearFormError(name));
52
+ dispatch(sendForm(name, { form }));
62
53
 
63
- const id = form._id || "";
64
- const url = getFormUrl(id);
65
- const formio = new Formio(url);
54
+ const id = form._id || "";
55
+ const url = getFormUrl(id);
56
+ const formio = new Formio(url);
66
57
 
67
- try {
68
- const result = await formio.saveForm(form);
69
- dispatch(receiveForm(name, { form: result, url: getFormUrl(result._id) }));
70
- done(null, result);
71
- } catch (error) {
72
- dispatch(failForm(name, { error }));
73
- done(error);
74
- }
75
- };
58
+ try {
59
+ const result = await formio.saveForm(form);
60
+ dispatch(receiveForm(name, { form: result, url: getFormUrl(result._id) }));
61
+ done(null, result);
62
+ } catch (error) {
63
+ dispatch(failForm(name, { error }));
64
+ done(error);
65
+ }
66
+ };
76
67
 
77
- export const deleteForm = (name: string, id: string, done = noop) => async (
78
- dispatch: any
79
- ) => {
80
- dispatch(clearFormError(name));
81
- const url = getFormUrl(id);
82
- const formio = new Formio(url);
68
+ export const deleteForm =
69
+ (name: string, id: string, done = noop) =>
70
+ async (dispatch: any) => {
71
+ dispatch(clearFormError(name));
72
+ const url = getFormUrl(id);
73
+ const formio = new Formio(url);
83
74
 
84
- try {
85
- await formio.deleteForm();
86
- dispatch(resetForm(name));
87
- done();
88
- } catch (error) {
89
- dispatch(failForm(name, { error }));
90
- done({ error });
91
- }
92
- };
75
+ try {
76
+ await formio.deleteForm();
77
+ dispatch(resetForm(name));
78
+ done();
79
+ } catch (error) {
80
+ dispatch(failForm(name, { error }));
81
+ done({ error });
82
+ }
83
+ };
@@ -1,10 +1,4 @@
1
- import {
2
- clearFormError,
3
- failForm,
4
- receiveForm,
5
- requestForm,
6
- resetForm
7
- } from "./form.actions";
1
+ import { clearFormError, failForm, receiveForm, requestForm, resetForm } from "./form.actions";
8
2
  import { formReducer } from "./form.reducers";
9
3
 
10
4
  describe("Form reducer", () => {
@@ -1,13 +1,6 @@
1
1
  import { createReducer, InitialStateCreator } from "@tsed/redux-utils";
2
2
  import { FormSchema } from "../../interfaces";
3
- import {
4
- clearFormError,
5
- failForm,
6
- receiveForm,
7
- requestForm,
8
- resetForm,
9
- sendForm
10
- } from "./form.actions";
3
+ import { clearFormError, failForm, receiveForm, requestForm, resetForm, sendForm } from "./form.actions";
11
4
 
12
5
  export interface FormState {
13
6
  error: null | Error;
@@ -2,5 +2,4 @@ import { FormSchema } from "../../interfaces";
2
2
  import { selectRoot } from "../root";
3
3
  import { FormState } from "./form.reducers";
4
4
 
5
- export const selectForm = (name: string, state: any): Partial<FormSchema> =>
6
- selectRoot<FormState>(name, state).data;
5
+ export const selectForm = (name: string, state: any): Partial<FormSchema> => selectRoot<FormState>(name, state).data;
@@ -1,11 +1,6 @@
1
1
  import { Formio } from "formiojs";
2
2
  import { mapRequestParams } from "../../utils/mapRequestParams";
3
- import {
4
- failForms,
5
- getForms,
6
- receiveForms,
7
- requestForms
8
- } from "./forms.actions";
3
+ import { failForms, getForms, receiveForms, requestForms } from "./forms.actions";
9
4
 
10
5
  jest.mock("formiojs");
11
6
  jest.mock("../../utils/mapRequestParams");
@@ -18,9 +13,7 @@ describe("Forms actions", () => {
18
13
  describe("getForms", () => {
19
14
  it("should return a result", async () => {
20
15
  // GIVEN
21
- (Formio as any).prototype.loadForms.mockReturnValue(
22
- Promise.resolve([{}])
23
- );
16
+ (Formio as any).prototype.loadForms.mockReturnValue(Promise.resolve([{}]));
24
17
  (Formio as any).getProjectUrl.mockReturnValue("https://formio");
25
18
  const dispatch = jest.fn();
26
19
  const name = "name";
@@ -36,9 +29,7 @@ describe("Forms actions", () => {
36
29
  });
37
30
 
38
31
  // WHEN
39
- await new Promise((resolve) =>
40
- getForms(name, parameters, resolve)(dispatch, getState)
41
- );
32
+ await new Promise((resolve) => getForms(name, parameters, resolve)(dispatch, getState));
42
33
 
43
34
  // THEN
44
35
  expect(Formio).toHaveBeenCalledWith("https://formio/form");
@@ -60,9 +51,7 @@ describe("Forms actions", () => {
60
51
  });
61
52
  it("should return a error", async () => {
62
53
  // GIVEN
63
- (Formio.prototype.loadForms as any).mockReturnValue(
64
- Promise.reject(new Error("message"))
65
- );
54
+ (Formio.prototype.loadForms as any).mockReturnValue(Promise.reject(new Error("message")));
66
55
  (Formio.getProjectUrl as any).mockReturnValue("https://formio");
67
56
 
68
57
  const dispatch = jest.fn();
@@ -79,9 +68,7 @@ describe("Forms actions", () => {
79
68
  });
80
69
 
81
70
  // WHEN
82
- await new Promise((resolve) =>
83
- getForms(name, parameters, resolve)(dispatch, getState)
84
- );
71
+ await new Promise((resolve) => getForms(name, parameters, resolve)(dispatch, getState));
85
72
 
86
73
  // THEN
87
74
  expect(Formio).toHaveBeenCalledWith("https://formio/form");
@@ -15,29 +15,25 @@ export const failForms = createAction();
15
15
 
16
16
  export type GetFormsCB = (err: any, forms?: FormSchema[]) => void;
17
17
 
18
- export const getForms = (
19
- name: string,
20
- parameters: Partial<RequestParamsOptions>,
21
- done: GetFormsCB = noop
22
- ) => async (dispatch: any, getState: any) => {
23
- dispatch(requestForms(name, { parameters }));
18
+ export const getForms =
19
+ (name: string, parameters: Partial<RequestParamsOptions>, done: GetFormsCB = noop) =>
20
+ async (dispatch: any, getState: any) => {
21
+ dispatch(requestForms(name, { parameters }));
24
22
 
25
- const formio = new Formio(`${Formio.getProjectUrl()}/form`);
26
- const requestParams = mapRequestParams(
27
- selectFormsParameters(name, getState())
28
- );
23
+ const formio = new Formio(`${Formio.getProjectUrl()}/form`);
24
+ const requestParams = mapRequestParams(selectFormsParameters(name, getState()));
29
25
 
30
- try {
31
- const result: FormSchema[] = await formio.loadForms({
32
- params: requestParams
33
- });
34
- dispatch(receiveForms(name, { forms: result }));
35
- done(null, result);
36
- } catch (error) {
37
- dispatch(failForms(name, { error }));
38
- done(error);
39
- }
40
- };
26
+ try {
27
+ const result: FormSchema[] = await formio.loadForms({
28
+ params: requestParams
29
+ });
30
+ dispatch(receiveForms(name, { forms: result }));
31
+ done(null, result);
32
+ } catch (error) {
33
+ dispatch(failForms(name, { error }));
34
+ done(error);
35
+ }
36
+ };
41
37
 
42
38
  export const refreshForms = (name: string, done = noop) => {
43
39
  return async (dispatch: any, getState: any) => {
@@ -1,9 +1,4 @@
1
- import {
2
- failForms,
3
- receiveForms,
4
- requestForms,
5
- resetForms
6
- } from "./forms.actions";
1
+ import { failForms, receiveForms, requestForms, resetForms } from "./forms.actions";
7
2
  import { formsReducer } from "./forms.reducers";
8
3
 
9
4
  describe("Forms reducer", () => {
@@ -1,11 +1,6 @@
1
1
  import { createReducer } from "@tsed/redux-utils";
2
2
  import { FormSchema } from "../../interfaces";
3
- import {
4
- failForms,
5
- receiveForms,
6
- requestForms,
7
- resetForms
8
- } from "./forms.actions";
3
+ import { failForms, receiveForms, requestForms, resetForms } from "./forms.actions";
9
4
 
10
5
  export interface FormsState {
11
6
  error: null | Error;
@@ -22,13 +17,7 @@ export interface FormsState {
22
17
  data: FormSchema[];
23
18
  }
24
19
 
25
- const createInitialState = ({
26
- pageIndex = 0,
27
- pageSize = 10,
28
- query = {},
29
- select = "",
30
- sortBy = []
31
- }: any = {}): FormsState => {
20
+ const createInitialState = ({ pageIndex = 0, pageSize = 10, query = {}, select = "", sortBy = [] }: any = {}): FormsState => {
32
21
  return {
33
22
  error: null,
34
23
  isActive: false,
@@ -1,8 +1,6 @@
1
1
  import { selectRoot } from "../root";
2
2
  import { FormsState } from "./forms.reducers";
3
3
 
4
- export const selectForms = (name: string, state: any) =>
5
- selectRoot<FormsState>(name, state).data;
4
+ export const selectForms = (name: string, state: any) => selectRoot<FormsState>(name, state).data;
6
5
 
7
- export const selectFormsParameters = (name: string, state: any) =>
8
- selectRoot<FormsState>(name, state).parameters;
6
+ export const selectFormsParameters = (name: string, state: any) => selectRoot<FormsState>(name, state).parameters;
@@ -2,15 +2,12 @@ import { defaultFormioReducer } from "./index";
2
2
 
3
3
  describe("defaultFormioReducer", () => {
4
4
  it("should return initial state", () => {
5
- const state = Object.entries(defaultFormioReducer).reduce(
6
- (state, [key, reduce]) => {
7
- return {
8
- ...state,
9
- [key]: reduce(undefined, {} as any)
10
- };
11
- },
12
- {}
13
- );
5
+ const state = Object.entries(defaultFormioReducer).reduce((state, [key, reduce]) => {
6
+ return {
7
+ ...state,
8
+ [key]: reduce(undefined, {} as any)
9
+ };
10
+ }, {});
14
11
 
15
12
  expect(state).toEqual({
16
13
  action: {
@@ -1,9 +1,4 @@
1
- import {
2
- oneOfIsActive,
3
- selectError,
4
- selectIsActive,
5
- selectRoot
6
- } from "./root.selectors";
1
+ import { oneOfIsActive, selectError, selectIsActive, selectRoot } from "./root.selectors";
7
2
 
8
3
  describe("root Selectors", () => {
9
4
  describe("selectRoot()", () => {
@@ -1,16 +1,8 @@
1
1
  import get from "lodash/get";
2
2
 
3
- export function selectRoot<State = Record<string, any>>(
4
- name: string
5
- ): (state: Record<string, any>) => State;
6
- export function selectRoot<State = Record<string, any>>(
7
- name: string,
8
- state: Record<string, any>
9
- ): State;
10
- export function selectRoot<State = Record<string, any>>(
11
- name: string,
12
- state?: Record<string, any>
13
- ): any {
3
+ export function selectRoot<State = Record<string, any>>(name: string): (state: Record<string, any>) => State;
4
+ export function selectRoot<State = Record<string, any>>(name: string, state: Record<string, any>): State;
5
+ export function selectRoot<State = Record<string, any>>(name: string, state?: Record<string, any>): any {
14
6
  if (state) {
15
7
  return state[name];
16
8
  }
@@ -18,24 +10,14 @@ export function selectRoot<State = Record<string, any>>(
18
10
  return (state: Record<string, any>) => selectRoot(name, state);
19
11
  }
20
12
 
21
- export const selectError = (
22
- name: string,
23
- state: Record<string, any>
24
- ): null | Error => get(selectRoot(name, state), "error");
13
+ export const selectError = (name: string, state: Record<string, any>): null | Error => get(selectRoot(name, state), "error");
25
14
 
26
- export const selectIsActive = (
27
- name: string,
28
- state: Record<string, any>
29
- ): boolean => get(selectRoot(name, state), "isActive");
15
+ export const selectIsActive = (name: string, state: Record<string, any>): boolean => get(selectRoot(name, state), "isActive");
30
16
 
31
17
  export function oneOfIsActive(...names: string[]) {
32
18
  return (state: any) => {
33
19
  return !!names.find((name) => {
34
- return get(
35
- state,
36
- `${name}.isActive`,
37
- get(state, `${name}.current.isActive`)
38
- );
20
+ return get(state, `${name}.isActive`, get(state, `${name}.current.isActive`));
39
21
  });
40
22
  };
41
23
  }
@@ -20,9 +20,7 @@ describe("Submission actions", () => {
20
20
  });
21
21
  it("should return a result", async () => {
22
22
  // GIVEN
23
- (Formio as any).prototype.loadSubmission.mockReturnValue(
24
- Promise.resolve({})
25
- );
23
+ (Formio as any).prototype.loadSubmission.mockReturnValue(Promise.resolve({}));
26
24
 
27
25
  const dispatch = jest.fn();
28
26
  const name = "name";
@@ -34,9 +32,7 @@ describe("Submission actions", () => {
34
32
  });
35
33
 
36
34
  // WHEN
37
- await new Promise((resolve) =>
38
- getSubmission(name, formId, id, resolve)(dispatch, getState)
39
- );
35
+ await new Promise((resolve) => getSubmission(name, formId, id, resolve)(dispatch, getState));
40
36
 
41
37
  // THEN
42
38
  expect(Formio).toHaveBeenCalledWith("/formId/submission/123454");
@@ -61,9 +57,7 @@ describe("Submission actions", () => {
61
57
  });
62
58
  it("should do nothing when submission is already loaded", async () => {
63
59
  // GIVEN
64
- (Formio.prototype.loadSubmission as any).mockReturnValue(
65
- Promise.resolve({})
66
- );
60
+ (Formio.prototype.loadSubmission as any).mockReturnValue(Promise.resolve({}));
67
61
 
68
62
  const dispatch = jest.fn();
69
63
  const name = "name";
@@ -82,9 +76,7 @@ describe("Submission actions", () => {
82
76
  });
83
77
  it("should throw error", async () => {
84
78
  // GIVEN
85
- (Formio.prototype.loadSubmission as any).mockReturnValue(
86
- Promise.reject(new Error("message"))
87
- );
79
+ (Formio.prototype.loadSubmission as any).mockReturnValue(Promise.reject(new Error("message")));
88
80
 
89
81
  const dispatch = jest.fn();
90
82
  const name = "name";
@@ -96,9 +88,7 @@ describe("Submission actions", () => {
96
88
  });
97
89
 
98
90
  // WHEN
99
- await new Promise((resolve) =>
100
- getSubmission(name, formId, id, resolve)(dispatch, getState)
101
- );
91
+ await new Promise((resolve) => getSubmission(name, formId, id, resolve)(dispatch, getState));
102
92
 
103
93
  // THEN
104
94
  expect(Formio).toHaveBeenCalledWith("/formId/submission/123454");
@@ -120,13 +110,9 @@ describe("Submission actions", () => {
120
110
  const data = { _id: "123454" };
121
111
  const formId = "formId";
122
112
 
123
- (Formio.prototype.saveSubmission as any).mockReturnValue(
124
- Promise.resolve(data)
125
- );
113
+ (Formio.prototype.saveSubmission as any).mockReturnValue(Promise.resolve(data));
126
114
  // WHEN
127
- await new Promise((resolve) =>
128
- saveSubmission(name, formId, data, resolve)(dispatch)
129
- );
115
+ await new Promise((resolve) => saveSubmission(name, formId, data, resolve)(dispatch));
130
116
 
131
117
  // THEN
132
118
  expect(dispatch).toHaveBeenCalledWith({
@@ -164,9 +150,7 @@ describe("Submission actions", () => {
164
150
  const formId = "formId";
165
151
 
166
152
  // WHEN
167
- await new Promise((resolve) =>
168
- saveSubmission(name, formId, data, resolve)(dispatch)
169
- );
153
+ await new Promise((resolve) => saveSubmission(name, formId, data, resolve)(dispatch));
170
154
 
171
155
  // THEN
172
156
  expect(Formio).toHaveBeenCalledWith("/formId/submission/123454");
@@ -183,9 +167,7 @@ describe("Submission actions", () => {
183
167
  describe("deleteSubmission", () => {
184
168
  it("should return a result", async () => {
185
169
  // GIVEN
186
- (Formio.prototype.deleteSubmission as any).mockReturnValue(
187
- Promise.resolve({})
188
- );
170
+ (Formio.prototype.deleteSubmission as any).mockReturnValue(Promise.resolve({}));
189
171
 
190
172
  const dispatch = jest.fn();
191
173
  const name = "name";
@@ -193,9 +175,7 @@ describe("Submission actions", () => {
193
175
  const formId = "formId";
194
176
 
195
177
  // WHEN
196
- await new Promise((resolve) =>
197
- deleteSubmission(name, formId, id, resolve)(dispatch)
198
- );
178
+ await new Promise((resolve) => deleteSubmission(name, formId, id, resolve)(dispatch));
199
179
 
200
180
  // THEN
201
181
  expect(Formio).toHaveBeenCalledWith("/formId/submission/123454");
@@ -216,9 +196,7 @@ describe("Submission actions", () => {
216
196
  const formId = "formId";
217
197
 
218
198
  // WHEN
219
- await new Promise((resolve) =>
220
- deleteSubmission(name, formId, id, resolve)(dispatch)
221
- );
199
+ await new Promise((resolve) => deleteSubmission(name, formId, id, resolve)(dispatch));
222
200
 
223
201
  // THEN
224
202
  expect(Formio).toHaveBeenCalledWith("/formId/submission/123454");
@@ -11,79 +11,70 @@ export const receiveSubmission = createAction();
11
11
  export const failSubmission = createAction();
12
12
  export const resetSubmission = createAction();
13
13
 
14
- export const getSubmission = (
15
- name: string,
16
- formId: string,
17
- id: string,
18
- done = noop
19
- ) => async (dispatch: any, getState: any) => {
20
- // Check to see if the submission is already loaded.
21
- if (getState().id === id) {
22
- return;
23
- }
14
+ export const getSubmission =
15
+ (name: string, formId: string, id: string, done = noop) =>
16
+ async (dispatch: any, getState: any) => {
17
+ // Check to see if the submission is already loaded.
18
+ if (getState().id === id) {
19
+ return;
20
+ }
24
21
 
25
- const url = getSubmissionUrl(formId, id);
26
- const formio = new Formio(url);
22
+ const url = getSubmissionUrl(formId, id);
23
+ const formio = new Formio(url);
27
24
 
28
- dispatch(clearSubmissionError(name));
29
- dispatch(requestSubmission(name, { id, formId, url }));
25
+ dispatch(clearSubmissionError(name));
26
+ dispatch(requestSubmission(name, { id, formId, url }));
30
27
 
31
- try {
32
- const result = await formio.loadSubmission();
28
+ try {
29
+ const result = await formio.loadSubmission();
33
30
 
34
- dispatch(receiveSubmission(name, { submission: result, url }));
35
- done(null, result);
36
- } catch (error) {
37
- dispatch(failSubmission(name, { error }));
38
- done(error);
39
- }
40
- };
31
+ dispatch(receiveSubmission(name, { submission: result, url }));
32
+ done(null, result);
33
+ } catch (error) {
34
+ dispatch(failSubmission(name, { error }));
35
+ done(error);
36
+ }
37
+ };
41
38
 
42
- export const saveSubmission = (
43
- name: string,
44
- formId: string,
45
- data: Submission,
46
- done = noop
47
- ) => async (dispatch: any) => {
48
- dispatch(clearSubmissionError(name));
49
- dispatch(sendSubmission(name, { submission: data, formId }));
39
+ export const saveSubmission =
40
+ (name: string, formId: string, data: Submission, done = noop) =>
41
+ async (dispatch: any) => {
42
+ dispatch(clearSubmissionError(name));
43
+ dispatch(sendSubmission(name, { submission: data, formId }));
50
44
 
51
- const id = data._id;
52
- const url = getSubmissionUrl(formId, id);
53
- const formio = new Formio(url);
45
+ const id = data._id;
46
+ const url = getSubmissionUrl(formId, id);
47
+ const formio = new Formio(url);
54
48
 
55
- try {
56
- const result = await formio.saveSubmission(data);
57
- dispatch(
58
- receiveSubmission(name, {
59
- submission: result,
60
- url: getSubmissionUrl(formId, result._id)
61
- })
62
- );
63
- done(null, result);
64
- } catch (error) {
65
- dispatch(failSubmission(name, { error }));
66
- done(error);
67
- }
68
- };
49
+ try {
50
+ const result = await formio.saveSubmission(data);
51
+ dispatch(
52
+ receiveSubmission(name, {
53
+ submission: result,
54
+ url: getSubmissionUrl(formId, result._id)
55
+ })
56
+ );
57
+ done(null, result);
58
+ } catch (error) {
59
+ dispatch(failSubmission(name, { error }));
60
+ done(error);
61
+ }
62
+ };
69
63
 
70
- export const deleteSubmission = (
71
- name: string,
72
- formId: string,
73
- id: string,
74
- done = noop
75
- ) => async (dispatch: any) => {
76
- dispatch(clearSubmissionError(name));
64
+ export const deleteSubmission =
65
+ (name: string, formId: string, id: string, done = noop) =>
66
+ async (dispatch: any) => {
67
+ dispatch(clearSubmissionError(name));
77
68
 
78
- const url = getSubmissionUrl(formId, id);
79
- const formio = new Formio(url);
69
+ const url = getSubmissionUrl(formId, id);
70
+ const formio = new Formio(url);
80
71
 
81
- try {
82
- await formio.deleteSubmission();
83
- dispatch(resetSubmission(name));
84
- done(null);
85
- } catch (error) {
86
- dispatch(failSubmission(name, { error }));
87
- done(error);
88
- }
89
- };
72
+ try {
73
+ await formio.deleteSubmission();
74
+ dispatch(resetSubmission(name));
75
+ done(null);
76
+ } catch (error) {
77
+ dispatch(failSubmission(name, { error }));
78
+ done(error);
79
+ }
80
+ };