@tsed/react-formio 1.11.2 → 1.12.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 (141) 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/form-action/formAction.stories.d.ts +90 -414
  6. package/dist/components/input-text/inputText.component.d.ts +1 -1
  7. package/dist/components/input-text/inputText.component.spec.d.ts +1 -0
  8. package/dist/components/select/select.component.spec.d.ts +1 -0
  9. package/dist/components/tabs/tabs.component.spec.d.ts +1 -0
  10. package/dist/index.js +60 -30
  11. package/dist/index.js.map +1 -1
  12. package/dist/index.modern.js +59 -31
  13. package/dist/index.modern.js.map +1 -1
  14. package/jest.config.js +1 -1
  15. package/package.json +5 -9
  16. package/readme.md +74 -79
  17. package/src/components/__fixtures__/form-schema.json +10 -42
  18. package/src/components/__fixtures__/form.fixture.json +1 -1
  19. package/src/components/actions-table/actionsTable.component.spec.tsx +4 -13
  20. package/src/components/actions-table/actionsTable.component.tsx +3 -11
  21. package/src/components/alert/alert.component.spec.tsx +97 -0
  22. package/src/components/alert/alert.component.tsx +2 -8
  23. package/src/components/alert/alert.stories.tsx +17 -0
  24. package/src/components/card/card.component.tsx +1 -5
  25. package/src/components/form/form.component.tsx +1 -7
  26. package/src/components/form/useForm.hook.ts +4 -13
  27. package/src/components/form-access/formAccess.component.tsx +19 -82
  28. package/src/components/form-access/formAccess.schema.ts +7 -23
  29. package/src/components/form-access/formAccess.stories.tsx +2 -9
  30. package/src/components/form-access/formAccess.utils.spec.ts +4 -22
  31. package/src/components/form-access/formAccess.utils.ts +7 -29
  32. package/src/components/form-action/formAction.component.tsx +3 -19
  33. package/src/components/form-action/formAction.stories.tsx +251 -672
  34. package/src/components/form-builder/formBuilder.component.tsx +4 -13
  35. package/src/components/form-builder/formBuilder.stories.tsx +12 -24
  36. package/src/components/form-control/formControl.component.tsx +2 -8
  37. package/src/components/form-edit/formCtas.component.tsx +5 -23
  38. package/src/components/form-edit/formEdit.component.tsx +2 -20
  39. package/src/components/form-edit/formEdit.reducer.ts +2 -8
  40. package/src/components/form-edit/formEdit.stories.tsx +3 -15
  41. package/src/components/form-edit/formParameters.component.tsx +3 -20
  42. package/src/components/form-edit/useFormEdit.hook.ts +2 -9
  43. package/src/components/form-settings/formSettings.component.spec.tsx +2 -9
  44. package/src/components/form-settings/formSettings.component.tsx +6 -34
  45. package/src/components/form-settings/formSettings.stories.tsx +1 -6
  46. package/src/components/form-settings/formSettings.utils.spec.ts +1 -4
  47. package/src/components/form-settings/formSettings.utils.ts +2 -7
  48. package/src/components/forms-table/components/formCell.component.tsx +2 -6
  49. package/src/components/forms-table/formsTable.component.tsx +2 -7
  50. package/src/components/input-tags/inputTags.component.tsx +10 -34
  51. package/src/components/input-tags/inputTags.stories.tsx +4 -14
  52. package/src/components/input-text/inputText.component.spec.tsx +56 -0
  53. package/src/components/input-text/inputText.component.tsx +4 -5
  54. package/src/components/input-text/inputText.stories.tsx +6 -26
  55. package/src/components/loader/loader.component.tsx +2 -11
  56. package/src/components/modal/modal.component.spec.tsx +8 -14
  57. package/src/components/modal/modal.component.tsx +6 -27
  58. package/src/components/modal/modal.stories.tsx +1 -5
  59. package/src/components/modal/removeModal.component.tsx +4 -22
  60. package/src/components/pagination/pagination.component.spec.tsx +12 -38
  61. package/src/components/pagination/pagination.component.tsx +8 -41
  62. package/src/components/pagination/pagination.stories.tsx +1 -5
  63. package/src/components/react-component/reactComponent.component.tsx +3 -11
  64. package/src/components/select/select.component.spec.tsx +86 -0
  65. package/src/components/select/select.component.tsx +11 -15
  66. package/src/components/select/select.stories.tsx +6 -26
  67. package/src/components/submissions-table/submissionsTable.component.tsx +1 -3
  68. package/src/components/submissions-table/submissionsTable.stories.tsx +1 -1
  69. package/src/components/table/components/defaultArrowSort.component.tsx +1 -10
  70. package/src/components/table/components/defaultCell.component.tsx +1 -4
  71. package/src/components/table/components/defaultCellHeader.component.tsx +4 -14
  72. package/src/components/table/components/defaultCellOperations.component.tsx +14 -25
  73. package/src/components/table/components/defaultOperationButton.component.tsx +2 -10
  74. package/src/components/table/filters/defaultColumnFilter.component.spec.tsx +1 -1
  75. package/src/components/table/filters/selectColumnFilter.component.spec.tsx +2 -10
  76. package/src/components/table/filters/selectColumnFilter.component.tsx +2 -6
  77. package/src/components/table/table.component.tsx +13 -53
  78. package/src/components/table/table.stories.tsx +1 -1
  79. package/src/components/table/utils/getPageNumbers.ts +3 -11
  80. package/src/components/table/utils/mapFormToColumns.tsx +14 -22
  81. package/src/components/table/utils/useOperations.hook.tsx +2 -12
  82. package/src/components/tabs/tabs.component.spec.tsx +86 -0
  83. package/src/components/tabs/tabs.component.stories.tsx +2 -9
  84. package/src/components/tabs/tabs.component.tsx +9 -43
  85. package/src/interfaces/Operation.ts +1 -4
  86. package/src/react-table.d.ts +9 -28
  87. package/src/stores/action/action.actions.ts +31 -33
  88. package/src/stores/action/action.reducers.spec.ts +1 -8
  89. package/src/stores/action/action.reducers.ts +1 -8
  90. package/src/stores/action/action.selectors.ts +1 -2
  91. package/src/stores/action-info/action-info.actions.spec.ts +1 -5
  92. package/src/stores/action-info/action-info.actions.ts +16 -19
  93. package/src/stores/action-info/action-info.reducers.spec.ts +1 -6
  94. package/src/stores/action-info/action-info.reducers.ts +1 -6
  95. package/src/stores/action-info/action-info.selectors.ts +1 -4
  96. package/src/stores/actions/actions.actions.spec.ts +1 -6
  97. package/src/stores/actions/actions.actions.ts +16 -19
  98. package/src/stores/actions/actions.reducers.spec.ts +1 -6
  99. package/src/stores/actions/actions.reducers.ts +1 -6
  100. package/src/stores/actions/actions.selectors.ts +2 -4
  101. package/src/stores/auth/auth.reducers.ts +1 -4
  102. package/src/stores/auth/auth.selectors.spec.ts +1 -5
  103. package/src/stores/auth/auth.selectors.ts +3 -6
  104. package/src/stores/auth/auth.utils.tsx +2 -8
  105. package/src/stores/auth/getAccess.action.spec.ts +11 -54
  106. package/src/stores/auth/getAccess.action.ts +1 -6
  107. package/src/stores/auth/initAuth.action.ts +15 -17
  108. package/src/stores/form/form.actions.spec.ts +8 -39
  109. package/src/stores/form/form.actions.ts +55 -64
  110. package/src/stores/form/form.reducers.spec.ts +1 -7
  111. package/src/stores/form/form.reducers.ts +1 -8
  112. package/src/stores/form/form.selectors.ts +1 -2
  113. package/src/stores/forms/forms.actions.spec.ts +5 -18
  114. package/src/stores/forms/forms.actions.ts +17 -21
  115. package/src/stores/forms/forms.reducers.spec.ts +1 -6
  116. package/src/stores/forms/forms.reducers.ts +2 -13
  117. package/src/stores/forms/forms.selectors.ts +2 -4
  118. package/src/stores/index.spec.ts +6 -9
  119. package/src/stores/root/root.selectors.spec.ts +1 -6
  120. package/src/stores/root/root.selectors.ts +6 -24
  121. package/src/stores/submission/submission.actions.spec.ts +11 -33
  122. package/src/stores/submission/submission.actions.ts +57 -66
  123. package/src/stores/submission/submission.reducers.spec.ts +17 -27
  124. package/src/stores/submission/submission.reducers.ts +1 -4
  125. package/src/stores/submission/submission.selectors.ts +1 -4
  126. package/src/stores/submissions/submissions.actions.spec.ts +5 -18
  127. package/src/stores/submissions/submissions.actions.ts +17 -26
  128. package/src/stores/submissions/submissions.reducers.spec.ts +3 -12
  129. package/src/stores/submissions/submissions.reducers.ts +3 -17
  130. package/src/stores/submissions/submissions.selectors.spec.ts +1 -4
  131. package/src/stores/submissions/submissions.selectors.ts +2 -4
  132. package/src/utils/getEventValue.ts +1 -4
  133. package/src/utils/iconClass.ts +2 -10
  134. package/src/utils/mapPagination.ts +1 -6
  135. package/src/utils/mapRequestParams.ts +2 -12
  136. package/src/utils/url.test.ts +4 -12
  137. package/src/utils/url.ts +2 -7
  138. package/tsconfig.json +4 -12
  139. package/tsconfig.test.json +1 -1
  140. package/.eslintrc +0 -47
  141. package/.prettierrc +0 -10
@@ -23,19 +23,13 @@ export function isAuthorized(auth: AuthState, roles: string[] = []): boolean {
23
23
  return false;
24
24
  }
25
25
 
26
- export function checkRoleFormAccess(
27
- auth: AuthState,
28
- form?: Partial<FormSchema>,
29
- roles?: string[]
30
- ) {
26
+ export function checkRoleFormAccess(auth: AuthState, form?: Partial<FormSchema>, roles?: string[]) {
31
27
  if (roles && roles.length) {
32
28
  if (isAuthorized(auth, roles)) {
33
29
  return true;
34
30
  }
35
31
 
36
- return !!(
37
- roles.includes("owner") && get(form, "owner") === get(auth, "user._id")
38
- );
32
+ return !!(roles.includes("owner") && get(form, "owner") === get(auth, "user._id"));
39
33
  }
40
34
 
41
35
  return true;
@@ -1,10 +1,5 @@
1
1
  import { Formio } from "formiojs";
2
- import {
3
- formAccessUser,
4
- submissionAccessUser,
5
- userForms,
6
- userRoles
7
- } from "./auth.actions";
2
+ import { formAccessUser, submissionAccessUser, userForms, userRoles } from "./auth.actions";
8
3
  import { AUTH } from "./auth.constant";
9
4
  import { getAccess } from "./getAccess.action";
10
5
 
@@ -49,11 +44,7 @@ describe("getAccess()", () => {
49
44
  path: "user",
50
45
  access: [
51
46
  {
52
- roles: [
53
- "6016dd751c62ca370d59f0ba",
54
- "6016dd751c62ca370d59f0b9",
55
- "6016dd751c62ca370d59f0b8"
56
- ],
47
+ roles: ["6016dd751c62ca370d59f0ba", "6016dd751c62ca370d59f0b9", "6016dd751c62ca370d59f0b8"],
57
48
  type: "read_all"
58
49
  }
59
50
  ],
@@ -75,11 +66,7 @@ describe("getAccess()", () => {
75
66
  path: "admin",
76
67
  access: [
77
68
  {
78
- roles: [
79
- "6016dd751c62ca370d59f0ba",
80
- "6016dd751c62ca370d59f0b9",
81
- "6016dd751c62ca370d59f0b8"
82
- ],
69
+ roles: ["6016dd751c62ca370d59f0ba", "6016dd751c62ca370d59f0b9", "6016dd751c62ca370d59f0b8"],
83
70
  type: "read_all"
84
71
  }
85
72
  ],
@@ -101,11 +88,7 @@ describe("getAccess()", () => {
101
88
  path: "todo",
102
89
  access: [
103
90
  {
104
- roles: [
105
- "6016dd751c62ca370d59f0b8",
106
- "6016dd751c62ca370d59f0b9",
107
- "6016dd751c62ca370d59f0ba"
108
- ],
91
+ roles: ["6016dd751c62ca370d59f0b8", "6016dd751c62ca370d59f0b9", "6016dd751c62ca370d59f0ba"],
109
92
  type: "read_all"
110
93
  }
111
94
  ],
@@ -128,9 +111,7 @@ describe("getAccess()", () => {
128
111
  await getAccess(dispatch);
129
112
 
130
113
  expect(Formio.getProjectUrl).toHaveBeenCalledWith();
131
- expect(Formio.makeStaticRequest).toHaveBeenCalledWith(
132
- "https://api.form.io/access"
133
- );
114
+ expect(Formio.makeStaticRequest).toHaveBeenCalledWith("https://api.form.io/access");
134
115
 
135
116
  expect(submissionAccessUser).toHaveBeenCalledWith(AUTH, {
136
117
  submissionAccess: {
@@ -169,25 +150,13 @@ describe("getAccess()", () => {
169
150
  expect(formAccessUser).toHaveBeenCalledWith(AUTH, {
170
151
  formAccess: {
171
152
  admin: {
172
- read_all: [
173
- "6016dd751c62ca370d59f0ba",
174
- "6016dd751c62ca370d59f0b9",
175
- "6016dd751c62ca370d59f0b8"
176
- ]
153
+ read_all: ["6016dd751c62ca370d59f0ba", "6016dd751c62ca370d59f0b9", "6016dd751c62ca370d59f0b8"]
177
154
  },
178
155
  todo: {
179
- read_all: [
180
- "6016dd751c62ca370d59f0b8",
181
- "6016dd751c62ca370d59f0b9",
182
- "6016dd751c62ca370d59f0ba"
183
- ]
156
+ read_all: ["6016dd751c62ca370d59f0b8", "6016dd751c62ca370d59f0b9", "6016dd751c62ca370d59f0ba"]
184
157
  },
185
158
  user: {
186
- read_all: [
187
- "6016dd751c62ca370d59f0ba",
188
- "6016dd751c62ca370d59f0b9",
189
- "6016dd751c62ca370d59f0b8"
190
- ]
159
+ read_all: ["6016dd751c62ca370d59f0ba", "6016dd751c62ca370d59f0b9", "6016dd751c62ca370d59f0b8"]
191
160
  }
192
161
  }
193
162
  });
@@ -219,11 +188,7 @@ describe("getAccess()", () => {
219
188
  _id: "6016e1fb4ce825382505947e",
220
189
  access: [
221
190
  {
222
- roles: [
223
- "6016dd751c62ca370d59f0ba",
224
- "6016dd751c62ca370d59f0b9",
225
- "6016dd751c62ca370d59f0b8"
226
- ],
191
+ roles: ["6016dd751c62ca370d59f0ba", "6016dd751c62ca370d59f0b9", "6016dd751c62ca370d59f0b8"],
227
192
  type: "read_all"
228
193
  }
229
194
  ],
@@ -245,11 +210,7 @@ describe("getAccess()", () => {
245
210
  _id: "6016e1fb4ce825382505947f",
246
211
  access: [
247
212
  {
248
- roles: [
249
- "6016dd751c62ca370d59f0b8",
250
- "6016dd751c62ca370d59f0b9",
251
- "6016dd751c62ca370d59f0ba"
252
- ],
213
+ roles: ["6016dd751c62ca370d59f0b8", "6016dd751c62ca370d59f0b9", "6016dd751c62ca370d59f0ba"],
253
214
  type: "read_all"
254
215
  }
255
216
  ],
@@ -271,11 +232,7 @@ describe("getAccess()", () => {
271
232
  _id: "6016e1fb4ce825382505947d",
272
233
  access: [
273
234
  {
274
- roles: [
275
- "6016dd751c62ca370d59f0ba",
276
- "6016dd751c62ca370d59f0b9",
277
- "6016dd751c62ca370d59f0b8"
278
- ],
235
+ roles: ["6016dd751c62ca370d59f0ba", "6016dd751c62ca370d59f0b9", "6016dd751c62ca370d59f0b8"],
279
236
  type: "read_all"
280
237
  }
281
238
  ],
@@ -1,12 +1,7 @@
1
1
  import { Formio } from "formiojs";
2
2
  import { RoleSchema } from "../../interfaces";
3
3
  import { FormSchema } from "../../interfaces/FormSchema";
4
- import {
5
- formAccessUser,
6
- submissionAccessUser,
7
- userForms,
8
- userRoles
9
- } from "./auth.actions";
4
+ import { formAccessUser, submissionAccessUser, userForms, userRoles } from "./auth.actions";
10
5
  import { AUTH } from "./auth.constant";
11
6
 
12
7
  function transformSubmissionAccess(forms: Record<string, FormSchema>) {
@@ -7,24 +7,22 @@ import { getProjectAccess } from "./getProjectAccess.action";
7
7
  import { logout } from "./logout.action";
8
8
  import { setUser } from "./setUser.action";
9
9
 
10
- export const initAuth = (done = noop) => async (dispatch: any) => {
11
- dispatch(requestUser(AUTH));
10
+ export const initAuth =
11
+ (done = noop) =>
12
+ async (dispatch: any) => {
13
+ dispatch(requestUser(AUTH));
12
14
 
13
- try {
14
- const [user] = await Promise.all([
15
- Formio.currentUser(),
16
- getAccess(dispatch),
17
- getProjectAccess(dispatch)
18
- ]);
15
+ try {
16
+ const [user] = await Promise.all([Formio.currentUser(), getAccess(dispatch), getProjectAccess(dispatch)]);
19
17
 
20
- if (user) {
21
- dispatch(setUser(user));
22
- } else {
23
- dispatch(logout());
18
+ if (user) {
19
+ dispatch(setUser(user));
20
+ } else {
21
+ dispatch(logout());
22
+ }
23
+ } catch (error) {
24
+ dispatch(failUser(AUTH, { error }));
24
25
  }
25
- } catch (error) {
26
- dispatch(failUser(AUTH, { error }));
27
- }
28
26
 
29
- done();
30
- };
27
+ done();
28
+ };
@@ -1,27 +1,16 @@
1
1
  import { Formio } from "formiojs";
2
- import {
3
- deleteForm,
4
- failForm,
5
- getForm,
6
- receiveForm,
7
- requestForm,
8
- resetForm,
9
- saveForm,
10
- sendForm
11
- } from "./form.actions";
2
+ import { deleteForm, failForm, getForm, receiveForm, requestForm, resetForm, saveForm, sendForm } from "./form.actions";
12
3
 
13
4
  jest.mock("formiojs");
14
5
 
15
6
  describe("Form actions", () => {
16
7
  describe("getForm", () => {
17
8
  beforeEach(() => {
18
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
19
9
  // @ts-ignore
20
10
  Formio.mockClear();
21
11
  });
22
12
  it("should return a result", async () => {
23
13
  // GIVEN
24
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
25
14
  // @ts-ignore
26
15
  Formio.prototype.loadForm.mockReturnValue(Promise.resolve({}));
27
16
 
@@ -34,9 +23,7 @@ describe("Form actions", () => {
34
23
  });
35
24
 
36
25
  // WHEN
37
- await new Promise((resolve) =>
38
- getForm(name, formId, resolve)(dispatch, getState)
39
- );
26
+ await new Promise((resolve) => getForm(name, formId, resolve)(dispatch, getState));
40
27
 
41
28
  // THEN
42
29
  expect(Formio).toHaveBeenCalledWith("/formId");
@@ -60,7 +47,6 @@ describe("Form actions", () => {
60
47
  });
61
48
  it("should do nothing when submission is already loaded", async () => {
62
49
  // GIVEN
63
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
64
50
  // @ts-ignore
65
51
  Formio.prototype.loadForm.mockReturnValue(Promise.resolve({}));
66
52
 
@@ -85,11 +71,8 @@ describe("Form actions", () => {
85
71
  });
86
72
  it("should throw error", async () => {
87
73
  // GIVEN
88
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
89
74
  // @ts-ignore
90
- Formio.prototype.loadForm.mockReturnValue(
91
- Promise.reject(new Error("message"))
92
- );
75
+ Formio.prototype.loadForm.mockReturnValue(Promise.reject(new Error("message")));
93
76
 
94
77
  const dispatch = jest.fn();
95
78
  const name = "name";
@@ -100,9 +83,7 @@ describe("Form actions", () => {
100
83
  });
101
84
 
102
85
  // WHEN
103
- await new Promise((resolve) =>
104
- getForm(name, formId, resolve)(dispatch, getState)
105
- );
86
+ await new Promise((resolve) => getForm(name, formId, resolve)(dispatch, getState));
106
87
 
107
88
  // THEN
108
89
  expect(Formio).toHaveBeenCalledWith("/formId");
@@ -124,7 +105,6 @@ describe("Form actions", () => {
124
105
  const formId = "formId";
125
106
  const data = { _id: formId };
126
107
 
127
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
128
108
  // @ts-ignore
129
109
  Formio.prototype.saveForm.mockReturnValue(Promise.resolve(data));
130
110
  // WHEN
@@ -151,11 +131,8 @@ describe("Form actions", () => {
151
131
  });
152
132
  it("should throw error", async () => {
153
133
  // GIVEN
154
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
155
134
  // @ts-ignore
156
- Formio.prototype.saveForm.mockReturnValue(
157
- Promise.reject(new Error("message"))
158
- );
135
+ Formio.prototype.saveForm.mockReturnValue(Promise.reject(new Error("message")));
159
136
 
160
137
  const dispatch = jest.fn();
161
138
  const name = "name";
@@ -180,7 +157,6 @@ describe("Form actions", () => {
180
157
  describe("deleteForm", () => {
181
158
  it("should return a result", async () => {
182
159
  // GIVEN
183
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
184
160
  // @ts-ignore
185
161
  Formio.prototype.deleteForm.mockReturnValue(Promise.resolve({}));
186
162
 
@@ -189,9 +165,7 @@ describe("Form actions", () => {
189
165
  const formId = "formId";
190
166
 
191
167
  // WHEN
192
- await new Promise((resolve) =>
193
- deleteForm(name, formId, resolve)(dispatch)
194
- );
168
+ await new Promise((resolve) => deleteForm(name, formId, resolve)(dispatch));
195
169
 
196
170
  // THEN
197
171
  expect(Formio).toHaveBeenCalledWith("/formId");
@@ -203,20 +177,15 @@ describe("Form actions", () => {
203
177
  });
204
178
  it("should throw error", async () => {
205
179
  // GIVEN
206
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
207
180
  // @ts-ignore
208
- Formio.prototype.deleteForm.mockReturnValue(
209
- Promise.reject(new Error("message"))
210
- );
181
+ Formio.prototype.deleteForm.mockReturnValue(Promise.reject(new Error("message")));
211
182
 
212
183
  const dispatch = jest.fn();
213
184
  const name = "name";
214
185
  const formId = "formId";
215
186
 
216
187
  // WHEN
217
- await new Promise((resolve) =>
218
- deleteForm(name, formId, resolve)(dispatch)
219
- );
188
+ await new Promise((resolve) => deleteForm(name, formId, resolve)(dispatch));
220
189
 
221
190
  // THEN
222
191
  expect(Formio).toHaveBeenCalledWith("/formId");
@@ -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;