@tsed/react-formio 1.14.1 → 2.0.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 (174) hide show
  1. package/coverage.json +4 -4
  2. package/dist/index.d.ts +3 -2
  3. package/dist/index.js +1277 -3684
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.modern.js +956 -2767
  6. package/dist/index.modern.js.map +1 -1
  7. package/package.json +4 -5
  8. package/readme.md +9 -57
  9. package/src/components/input-tags/inputTags.component.tsx +1 -1
  10. package/src/components/select/select.component.tsx +1 -1
  11. package/src/components/table/filters/sliderColumnFilter.component.tsx +2 -2
  12. package/src/index.ts +3 -2
  13. package/dist/stores/action/action.actions.d.ts +0 -9
  14. package/dist/stores/action/action.actions.spec.d.ts +0 -1
  15. package/dist/stores/action/action.constant.d.ts +0 -1
  16. package/dist/stores/action/action.reducers.d.ts +0 -7
  17. package/dist/stores/action/action.reducers.spec.d.ts +0 -1
  18. package/dist/stores/action/action.selectors.d.ts +0 -2
  19. package/dist/stores/action/action.selectors.spec.d.ts +0 -1
  20. package/dist/stores/action/index.d.ts +0 -4
  21. package/dist/stores/action-info/action-info.actions.d.ts +0 -5
  22. package/dist/stores/action-info/action-info.actions.spec.d.ts +0 -1
  23. package/dist/stores/action-info/action-info.constant.d.ts +0 -1
  24. package/dist/stores/action-info/action-info.reducers.d.ts +0 -7
  25. package/dist/stores/action-info/action-info.reducers.spec.d.ts +0 -1
  26. package/dist/stores/action-info/action-info.selectors.d.ts +0 -2
  27. package/dist/stores/action-info/action-info.selectors.spec.d.ts +0 -1
  28. package/dist/stores/action-info/index.d.ts +0 -4
  29. package/dist/stores/actions/actions.actions.d.ts +0 -5
  30. package/dist/stores/actions/actions.actions.spec.d.ts +0 -1
  31. package/dist/stores/actions/actions.constant.d.ts +0 -1
  32. package/dist/stores/actions/actions.reducers.d.ts +0 -8
  33. package/dist/stores/actions/actions.reducers.spec.d.ts +0 -1
  34. package/dist/stores/actions/actions.selectors.d.ts +0 -2
  35. package/dist/stores/actions/actions.selectors.spec.d.ts +0 -1
  36. package/dist/stores/actions/index.d.ts +0 -4
  37. package/dist/stores/auth/auth.actions.d.ts +0 -9
  38. package/dist/stores/auth/auth.constant.d.ts +0 -1
  39. package/dist/stores/auth/auth.reducers.d.ts +0 -16
  40. package/dist/stores/auth/auth.reducers.spec.d.ts +0 -1
  41. package/dist/stores/auth/auth.selectors.d.ts +0 -6
  42. package/dist/stores/auth/auth.selectors.spec.d.ts +0 -1
  43. package/dist/stores/auth/auth.utils.d.ts +0 -6
  44. package/dist/stores/auth/auth.utils.spec.d.ts +0 -1
  45. package/dist/stores/auth/getAccess.action.d.ts +0 -1
  46. package/dist/stores/auth/getAccess.action.spec.d.ts +0 -1
  47. package/dist/stores/auth/getProjectAccess.action.d.ts +0 -1
  48. package/dist/stores/auth/index.d.ts +0 -10
  49. package/dist/stores/auth/initAuth.action.d.ts +0 -1
  50. package/dist/stores/auth/initAuth.action.spec.d.ts +0 -1
  51. package/dist/stores/auth/logout.action.d.ts +0 -1
  52. package/dist/stores/auth/logout.action.spec.d.ts +0 -1
  53. package/dist/stores/auth/setUser.action.d.ts +0 -1
  54. package/dist/stores/auth/setUser.action.spec.d.ts +0 -1
  55. package/dist/stores/form/form.actions.d.ts +0 -10
  56. package/dist/stores/form/form.actions.spec.d.ts +0 -1
  57. package/dist/stores/form/form.reducers.d.ts +0 -9
  58. package/dist/stores/form/form.reducers.spec.d.ts +0 -1
  59. package/dist/stores/form/form.selectors.d.ts +0 -2
  60. package/dist/stores/form/form.selectors.spec.d.ts +0 -1
  61. package/dist/stores/form/index.d.ts +0 -3
  62. package/dist/stores/forms/forms.actions.d.ts +0 -9
  63. package/dist/stores/forms/forms.actions.spec.d.ts +0 -1
  64. package/dist/stores/forms/forms.reducers.d.ts +0 -16
  65. package/dist/stores/forms/forms.reducers.spec.d.ts +0 -1
  66. package/dist/stores/forms/forms.selectors.d.ts +0 -10
  67. package/dist/stores/forms/forms.selectors.spec.d.ts +0 -1
  68. package/dist/stores/forms/index.d.ts +0 -3
  69. package/dist/stores/index.d.ts +0 -10
  70. package/dist/stores/index.spec.d.ts +0 -1
  71. package/dist/stores/root/index.d.ts +0 -1
  72. package/dist/stores/root/root.selectors.d.ts +0 -5
  73. package/dist/stores/root/root.selectors.spec.d.ts +0 -1
  74. package/dist/stores/submission/index.d.ts +0 -3
  75. package/dist/stores/submission/submission.actions.d.ts +0 -10
  76. package/dist/stores/submission/submission.actions.spec.d.ts +0 -1
  77. package/dist/stores/submission/submission.reducers.d.ts +0 -11
  78. package/dist/stores/submission/submission.reducers.spec.d.ts +0 -1
  79. package/dist/stores/submission/submission.selectors.d.ts +0 -2
  80. package/dist/stores/submission/submission.selectors.spec.d.ts +0 -1
  81. package/dist/stores/submissions/index.d.ts +0 -3
  82. package/dist/stores/submissions/submissions.actions.d.ts +0 -6
  83. package/dist/stores/submissions/submissions.actions.spec.d.ts +0 -1
  84. package/dist/stores/submissions/submissions.reducers.d.ts +0 -17
  85. package/dist/stores/submissions/submissions.reducers.spec.d.ts +0 -1
  86. package/dist/stores/submissions/submissions.selectors.d.ts +0 -9
  87. package/dist/stores/submissions/submissions.selectors.spec.d.ts +0 -1
  88. package/dist/utils/clean.d.ts +0 -1
  89. package/dist/utils/clean.test.d.ts +0 -1
  90. package/dist/utils/mapRequestParams.d.ts +0 -9
  91. package/dist/utils/mapRequestParams.test.d.ts +0 -1
  92. package/dist/utils/url.d.ts +0 -3
  93. package/dist/utils/url.test.d.ts +0 -1
  94. package/src/stores/action/action.actions.spec.ts +0 -114
  95. package/src/stores/action/action.actions.ts +0 -82
  96. package/src/stores/action/action.constant.ts +0 -1
  97. package/src/stores/action/action.reducers.spec.ts +0 -91
  98. package/src/stores/action/action.reducers.ts +0 -54
  99. package/src/stores/action/action.selectors.spec.ts +0 -19
  100. package/src/stores/action/action.selectors.ts +0 -6
  101. package/src/stores/action/index.ts +0 -4
  102. package/src/stores/action-info/action-info.actions.spec.ts +0 -46
  103. package/src/stores/action-info/action-info.actions.ts +0 -32
  104. package/src/stores/action-info/action-info.constant.ts +0 -1
  105. package/src/stores/action-info/action-info.reducers.spec.ts +0 -60
  106. package/src/stores/action-info/action-info.reducers.ts +0 -44
  107. package/src/stores/action-info/action-info.selectors.spec.ts +0 -19
  108. package/src/stores/action-info/action-info.selectors.ts +0 -7
  109. package/src/stores/action-info/index.ts +0 -4
  110. package/src/stores/actions/actions.actions.spec.ts +0 -62
  111. package/src/stores/actions/actions.actions.ts +0 -34
  112. package/src/stores/actions/actions.constant.ts +0 -1
  113. package/src/stores/actions/actions.reducers.spec.ts +0 -62
  114. package/src/stores/actions/actions.reducers.ts +0 -48
  115. package/src/stores/actions/actions.selectors.spec.ts +0 -34
  116. package/src/stores/actions/actions.selectors.ts +0 -7
  117. package/src/stores/actions/index.ts +0 -4
  118. package/src/stores/auth/auth.actions.ts +0 -13
  119. package/src/stores/auth/auth.constant.ts +0 -1
  120. package/src/stores/auth/auth.reducers.spec.ts +0 -376
  121. package/src/stores/auth/auth.reducers.ts +0 -151
  122. package/src/stores/auth/auth.selectors.spec.ts +0 -47
  123. package/src/stores/auth/auth.selectors.ts +0 -14
  124. package/src/stores/auth/auth.utils.spec.ts +0 -29
  125. package/src/stores/auth/auth.utils.tsx +0 -37
  126. package/src/stores/auth/getAccess.action.spec.ts +0 -257
  127. package/src/stores/auth/getAccess.action.ts +0 -57
  128. package/src/stores/auth/getProjectAccess.action.ts +0 -25
  129. package/src/stores/auth/index.ts +0 -10
  130. package/src/stores/auth/initAuth.action.spec.ts +0 -56
  131. package/src/stores/auth/initAuth.action.ts +0 -29
  132. package/src/stores/auth/logout.action.spec.ts +0 -25
  133. package/src/stores/auth/logout.action.ts +0 -9
  134. package/src/stores/auth/setUser.action.spec.ts +0 -25
  135. package/src/stores/auth/setUser.action.ts +0 -9
  136. package/src/stores/form/form.actions.spec.ts +0 -203
  137. package/src/stores/form/form.actions.ts +0 -84
  138. package/src/stores/form/form.reducers.spec.ts +0 -78
  139. package/src/stores/form/form.reducers.ts +0 -59
  140. package/src/stores/form/form.selectors.spec.ts +0 -19
  141. package/src/stores/form/form.selectors.ts +0 -5
  142. package/src/stores/form/index.ts +0 -3
  143. package/src/stores/forms/forms.actions.spec.ts +0 -91
  144. package/src/stores/forms/forms.actions.ts +0 -44
  145. package/src/stores/forms/forms.reducers.spec.ts +0 -97
  146. package/src/stores/forms/forms.reducers.ts +0 -77
  147. package/src/stores/forms/forms.selectors.spec.ts +0 -39
  148. package/src/stores/forms/forms.selectors.ts +0 -6
  149. package/src/stores/forms/index.ts +0 -3
  150. package/src/stores/index.spec.ts +0 -125
  151. package/src/stores/index.ts +0 -33
  152. package/src/stores/root/index.ts +0 -1
  153. package/src/stores/root/root.selectors.spec.ts +0 -94
  154. package/src/stores/root/root.selectors.ts +0 -23
  155. package/src/stores/submission/index.ts +0 -3
  156. package/src/stores/submission/submission.actions.spec.ts +0 -214
  157. package/src/stores/submission/submission.actions.ts +0 -81
  158. package/src/stores/submission/submission.reducers.spec.ts +0 -96
  159. package/src/stores/submission/submission.reducers.ts +0 -70
  160. package/src/stores/submission/submission.selectors.spec.ts +0 -19
  161. package/src/stores/submission/submission.selectors.ts +0 -5
  162. package/src/stores/submissions/index.ts +0 -3
  163. package/src/stores/submissions/submissions.actions.spec.ts +0 -99
  164. package/src/stores/submissions/submissions.actions.ts +0 -38
  165. package/src/stores/submissions/submissions.reducers.spec.ts +0 -98
  166. package/src/stores/submissions/submissions.reducers.ts +0 -78
  167. package/src/stores/submissions/submissions.selectors.spec.ts +0 -39
  168. package/src/stores/submissions/submissions.selectors.ts +0 -6
  169. package/src/utils/clean.test.ts +0 -7
  170. package/src/utils/clean.ts +0 -12
  171. package/src/utils/mapRequestParams.test.ts +0 -81
  172. package/src/utils/mapRequestParams.ts +0 -36
  173. package/src/utils/url.test.ts +0 -31
  174. package/src/utils/url.ts +0 -23
@@ -1,214 +0,0 @@
1
- import { Formio } from "formiojs";
2
-
3
- import {
4
- clearSubmissionError,
5
- deleteSubmission,
6
- failSubmission,
7
- getSubmission,
8
- receiveSubmission,
9
- requestSubmission,
10
- resetSubmission,
11
- saveSubmission,
12
- sendSubmission
13
- } from "./submission.actions";
14
-
15
- jest.mock("formiojs/Formio");
16
-
17
- describe("Submission actions", () => {
18
- describe("getSubmission", () => {
19
- beforeEach(() => {
20
- (Formio as any).mockClear();
21
- });
22
- it("should return a result", async () => {
23
- // GIVEN
24
- (Formio as any).prototype.loadSubmission.mockReturnValue(Promise.resolve({}));
25
-
26
- const dispatch = jest.fn();
27
- const name = "name";
28
- const id = "123454";
29
- const formId = "formId";
30
-
31
- const getState = () => ({
32
- [name]: {}
33
- });
34
-
35
- // WHEN
36
- await new Promise((resolve) => getSubmission(name, formId, id, resolve)(dispatch, getState));
37
-
38
- // THEN
39
- expect(Formio).toHaveBeenCalledWith("/formId/submission/123454");
40
- expect(Formio.prototype.loadSubmission).toHaveBeenCalledWith();
41
- expect(dispatch).toHaveBeenCalledWith({
42
- name: "name",
43
- type: requestSubmission.toString(),
44
- payload: {
45
- formId: "formId",
46
- id: "123454",
47
- url: "/formId/submission/123454"
48
- }
49
- });
50
- expect(dispatch).toHaveBeenCalledWith({
51
- type: receiveSubmission.toString(),
52
- name: "name",
53
- payload: {
54
- submission: {},
55
- url: "/formId/submission/123454"
56
- }
57
- });
58
- });
59
- it("should do nothing when submission is already loaded", async () => {
60
- // GIVEN
61
- (Formio.prototype.loadSubmission as any).mockReturnValue(Promise.resolve({}));
62
-
63
- const dispatch = jest.fn();
64
- const name = "name";
65
- const id = "123454";
66
- const formId = "formId";
67
-
68
- const getState = () => ({
69
- id
70
- });
71
-
72
- // WHEN
73
- await getSubmission(name, formId, id)(dispatch, getState);
74
-
75
- // THEN
76
- expect(Formio).not.toHaveBeenCalled();
77
- });
78
- it("should throw error", async () => {
79
- // GIVEN
80
- (Formio.prototype.loadSubmission as any).mockReturnValue(Promise.reject(new Error("message")));
81
-
82
- const dispatch = jest.fn();
83
- const name = "name";
84
- const id = "123454";
85
- const formId = "formId";
86
-
87
- const getState = () => ({
88
- [name]: {}
89
- });
90
-
91
- // WHEN
92
- await new Promise((resolve) => getSubmission(name, formId, id, resolve)(dispatch, getState));
93
-
94
- // THEN
95
- expect(Formio).toHaveBeenCalledWith("/formId/submission/123454");
96
- expect(Formio.prototype.loadSubmission).toHaveBeenCalledWith();
97
- expect(dispatch).toHaveBeenCalledWith({
98
- name: "name",
99
- type: failSubmission.toString(),
100
- payload: {
101
- error: new Error("message")
102
- }
103
- });
104
- });
105
- });
106
- describe("saveSubmission", () => {
107
- it("should return a result", async () => {
108
- // GIVEN
109
- const dispatch = jest.fn();
110
- const name = "name";
111
- const data = { _id: "123454" };
112
- const formId = "formId";
113
-
114
- (Formio.prototype.saveSubmission as any).mockReturnValue(Promise.resolve(data));
115
- // WHEN
116
- await new Promise((resolve) => saveSubmission(name, formId, data, resolve)(dispatch));
117
-
118
- // THEN
119
- expect(dispatch).toHaveBeenCalledWith({
120
- name: "name",
121
- type: clearSubmissionError.toString()
122
- });
123
- expect(Formio).toHaveBeenCalledWith("/formId/submission/123454");
124
- expect(Formio.prototype.saveSubmission).toHaveBeenCalledWith(data);
125
- expect(dispatch).toHaveBeenCalledWith({
126
- name: "name",
127
- type: sendSubmission.toString(),
128
- payload: {
129
- formId,
130
- submission: { _id: "123454" }
131
- }
132
- });
133
- expect(dispatch).toHaveBeenCalledWith({
134
- name: "name",
135
- payload: {
136
- url: "/formId/submission/123454",
137
- submission: data
138
- },
139
- type: receiveSubmission.toString()
140
- });
141
- });
142
- it("should throw error", async () => {
143
- // GIVEN
144
- (Formio.prototype.saveSubmission as any).mockImplementation(() => {
145
- throw new Error("message");
146
- });
147
-
148
- const dispatch = jest.fn();
149
- const name = "name";
150
- const data = { _id: "123454" };
151
- const formId = "formId";
152
-
153
- // WHEN
154
- await new Promise((resolve) => saveSubmission(name, formId, data, resolve)(dispatch));
155
-
156
- // THEN
157
- expect(Formio).toHaveBeenCalledWith("/formId/submission/123454");
158
- expect(Formio.prototype.saveSubmission).toHaveBeenCalledWith(data);
159
- expect(dispatch).toHaveBeenCalledWith({
160
- name: "name",
161
- type: failSubmission.toString(),
162
- payload: {
163
- error: new Error("message")
164
- }
165
- });
166
- });
167
- });
168
- describe("deleteSubmission", () => {
169
- it("should return a result", async () => {
170
- // GIVEN
171
- (Formio.prototype.deleteSubmission as any).mockReturnValue(Promise.resolve({}));
172
-
173
- const dispatch = jest.fn();
174
- const name = "name";
175
- const id = "123454";
176
- const formId = "formId";
177
-
178
- // WHEN
179
- await new Promise((resolve) => deleteSubmission(name, formId, id, resolve)(dispatch));
180
-
181
- // THEN
182
- expect(Formio).toHaveBeenCalledWith("/formId/submission/123454");
183
- expect(Formio.prototype.deleteSubmission).toHaveBeenCalledWith();
184
- expect(dispatch).toHaveBeenCalledWith({
185
- name: "name",
186
- type: resetSubmission.toString()
187
- });
188
- });
189
- it("should throw error", async () => {
190
- // GIVEN
191
- (Formio.prototype.deleteSubmission as any).mockImplementation(() => {
192
- throw new Error("message");
193
- });
194
- const dispatch = jest.fn();
195
- const name = "name";
196
- const id = "123454";
197
- const formId = "formId";
198
-
199
- // WHEN
200
- await new Promise((resolve) => deleteSubmission(name, formId, id, resolve)(dispatch));
201
-
202
- // THEN
203
- expect(Formio).toHaveBeenCalledWith("/formId/submission/123454");
204
- expect(Formio.prototype.deleteSubmission).toHaveBeenCalledWith();
205
- expect(dispatch).toHaveBeenCalledWith({
206
- name: "name",
207
- type: failSubmission.toString(),
208
- payload: {
209
- error: new Error("message")
210
- }
211
- });
212
- });
213
- });
214
- });
@@ -1,81 +0,0 @@
1
- import { createAction } from "@tsed/redux-utils";
2
- import { Formio } from "formiojs";
3
- import noop from "lodash/noop";
4
-
5
- import { Submission } from "../../interfaces";
6
- import { getSubmissionUrl } from "../../utils/url";
7
-
8
- export const clearSubmissionError = createAction();
9
- export const requestSubmission = createAction();
10
- export const sendSubmission = createAction();
11
- export const receiveSubmission = createAction();
12
- export const failSubmission = createAction();
13
- export const resetSubmission = createAction();
14
-
15
- export const getSubmission =
16
- (name: string, formId: string, id: string, done = noop) =>
17
- async (dispatch: any, getState: any) => {
18
- // Check to see if the submission is already loaded.
19
- if (getState().id === id) {
20
- return;
21
- }
22
-
23
- const url = getSubmissionUrl(formId, id);
24
- const formio = new Formio(url);
25
-
26
- dispatch(clearSubmissionError(name));
27
- dispatch(requestSubmission(name, { id, formId, url }));
28
-
29
- try {
30
- const result = await formio.loadSubmission();
31
-
32
- dispatch(receiveSubmission(name, { submission: result, url }));
33
- done(null, result);
34
- } catch (error) {
35
- dispatch(failSubmission(name, { error }));
36
- done(error);
37
- }
38
- };
39
-
40
- export const saveSubmission =
41
- (name: string, formId: string, data: Submission, done = noop) =>
42
- async (dispatch: any) => {
43
- dispatch(clearSubmissionError(name));
44
- dispatch(sendSubmission(name, { submission: data, formId }));
45
-
46
- const id = data._id;
47
- const url = getSubmissionUrl(formId, id);
48
- const formio = new Formio(url);
49
-
50
- try {
51
- const result = await formio.saveSubmission(data);
52
- dispatch(
53
- receiveSubmission(name, {
54
- submission: result,
55
- url: getSubmissionUrl(formId, result._id)
56
- })
57
- );
58
- done(null, result);
59
- } catch (error) {
60
- dispatch(failSubmission(name, { error }));
61
- done(error);
62
- }
63
- };
64
-
65
- export const deleteSubmission =
66
- (name: string, formId: string, id: string, done = noop) =>
67
- async (dispatch: any) => {
68
- dispatch(clearSubmissionError(name));
69
-
70
- const url = getSubmissionUrl(formId, id);
71
- const formio = new Formio(url);
72
-
73
- try {
74
- await formio.deleteSubmission();
75
- dispatch(resetSubmission(name));
76
- done(null);
77
- } catch (error) {
78
- dispatch(failSubmission(name, { error }));
79
- done(error);
80
- }
81
- };
@@ -1,96 +0,0 @@
1
- import { failSubmission, receiveSubmission, requestSubmission, resetSubmission, sendSubmission } from "./submission.actions";
2
- import { submissionReducer } from "./submission.reducers";
3
-
4
- describe("Submission reducers", () => {
5
- it("should return state (resetSubmission)", () => {
6
- const reducer = submissionReducer("name");
7
- const state: any = {};
8
- const payload = {};
9
-
10
- expect(reducer.$emit(resetSubmission.toString(), state, payload)).toEqual({
11
- name: "name",
12
- error: null,
13
- formId: "",
14
- id: "",
15
- isActive: false,
16
- lastUpdated: 0,
17
- data: {},
18
- url: ""
19
- });
20
- });
21
- it("should return state (requestSubmission)", () => {
22
- const reducer = submissionReducer("name");
23
- const state: any = {};
24
- const payload = {
25
- formId: "formId",
26
- id: "id",
27
- url: "url"
28
- };
29
-
30
- expect(reducer.$emit(requestSubmission.toString(), state, payload)).toEqual({
31
- name: "name",
32
- formId: "formId",
33
- id: "id",
34
- isActive: true,
35
- data: {},
36
- url: "url"
37
- });
38
- });
39
-
40
- it("should return state (sendSubmission)", () => {
41
- const reducer = submissionReducer("name");
42
- const state: any = {};
43
- const payload = {
44
- formId: "formId",
45
- submission: {},
46
- id: "id",
47
- url: "url"
48
- };
49
-
50
- expect(reducer.$emit(sendSubmission.toString(), state, payload)).toEqual({
51
- name: "name",
52
- formId: "formId",
53
- id: "id",
54
- isActive: true,
55
- data: {},
56
- url: "url"
57
- });
58
- });
59
-
60
- it("should return state (receiveSubmission)", () => {
61
- const reducer = submissionReducer("name");
62
- const state: any = {};
63
- const payload = {
64
- formId: "formId",
65
- id: "id",
66
- url: "url",
67
- submission: {
68
- _id: "id"
69
- }
70
- };
71
-
72
- expect(reducer.$emit(receiveSubmission.toString(), state, payload)).toEqual({
73
- name: "name",
74
- url: "url",
75
- error: null,
76
- isActive: false,
77
- data: {
78
- _id: "id"
79
- }
80
- });
81
- });
82
-
83
- it("should return state (failSubmission)", () => {
84
- const reducer = submissionReducer("name");
85
- const state: any = {};
86
- const payload = {
87
- error: new Error("message")
88
- };
89
-
90
- expect(reducer.$emit(failSubmission.toString(), state, payload)).toEqual({
91
- name: "name",
92
- error: payload.error,
93
- isActive: false
94
- });
95
- });
96
- });
@@ -1,70 +0,0 @@
1
- import { createReducer, InitialStateCreator } from "@tsed/redux-utils";
2
-
3
- import { Submission } from "../../interfaces";
4
- import {
5
- clearSubmissionError,
6
- failSubmission,
7
- receiveSubmission,
8
- requestSubmission,
9
- resetSubmission,
10
- sendSubmission
11
- } from "./submission.actions";
12
-
13
- export interface SubmissionState {
14
- formId: string;
15
- id: string;
16
- isActive: boolean;
17
- lastUpdated: number;
18
- data: Partial<Submission>;
19
- url: string;
20
- error: null | Error;
21
- }
22
-
23
- const createInitialState: InitialStateCreator = () => ({
24
- formId: "",
25
- id: "",
26
- isActive: false,
27
- lastUpdated: 0,
28
- data: {},
29
- url: "",
30
- error: null
31
- });
32
-
33
- export const submissionReducer = createReducer<SubmissionState>(
34
- {
35
- [resetSubmission.toString()]: (_: any, _2: any, reset: any) => reset(),
36
- [clearSubmissionError.toString()]: (state: any) => ({
37
- ...state,
38
- error: null
39
- }),
40
- [requestSubmission.toString()]: (state: any, { formId, id, url }: any) => ({
41
- ...state,
42
- formId,
43
- id,
44
- url,
45
- data: {},
46
- isActive: true
47
- }),
48
- [sendSubmission.toString()]: (state: any, { formId, submission, id, url }: any) => ({
49
- ...state,
50
- formId,
51
- id,
52
- url: url || state.url,
53
- data: submission,
54
- isActive: true
55
- }),
56
- [receiveSubmission.toString()]: (state: any, { submission, url }: any) => ({
57
- ...state,
58
- data: submission,
59
- url: url || state.url,
60
- isActive: false,
61
- error: null
62
- }),
63
- [failSubmission.toString()]: (state: any, { error }: any) => ({
64
- ...state,
65
- isActive: false,
66
- error
67
- })
68
- },
69
- createInitialState
70
- );
@@ -1,19 +0,0 @@
1
- import { selectSubmission } from "./submission.selectors";
2
-
3
- describe("submission Selectors", () => {
4
- describe("selectSubmission()", () => {
5
- it("should return submission", () => {
6
- expect(
7
- selectSubmission("submission", {
8
- submission: {
9
- data: {
10
- _id: "id"
11
- }
12
- }
13
- })
14
- ).toEqual({
15
- _id: "id"
16
- });
17
- });
18
- });
19
- });
@@ -1,5 +0,0 @@
1
- import { Submission } from "../../interfaces";
2
- import { selectRoot } from "../root";
3
- import { SubmissionState } from "./submission.reducers";
4
-
5
- export const selectSubmission = (name: string, state: any): Partial<Submission> => selectRoot<SubmissionState>(name, state).data;
@@ -1,3 +0,0 @@
1
- export * from "./submissions.actions";
2
- export * from "./submissions.reducers";
3
- export * from "./submissions.selectors";
@@ -1,99 +0,0 @@
1
- import { Formio } from "formiojs";
2
-
3
- import { mapRequestParams } from "../../utils/mapRequestParams";
4
- import { failSubmissions, getSubmissions, receiveSubmissions, requestSubmissions } from "./submissions.actions";
5
-
6
- jest.mock("formiojs");
7
- jest.mock("../../utils/mapRequestParams");
8
-
9
- describe("Submissions actions", () => {
10
- beforeEach(() => {
11
- (mapRequestParams as any).mockImplementation((o: any) => o);
12
- });
13
- describe("getSubmissions", () => {
14
- it("should return a result", async () => {
15
- // GIVEN
16
- (Formio.prototype.loadSubmissions as any).mockReturnValue(Promise.resolve([{}]));
17
- (Formio.getProjectUrl as any).mockReturnValue("https://formio");
18
-
19
- const dispatch = jest.fn();
20
- const name = "name";
21
- const formId = "formId";
22
- const parameters = {
23
- pageSize: 10,
24
- pageIndex: 0
25
- };
26
-
27
- const getState = () => ({
28
- [name]: {
29
- parameters
30
- }
31
- });
32
-
33
- // WHEN
34
- await new Promise((resolve) => getSubmissions(name, formId, parameters, resolve)(dispatch, getState));
35
-
36
- // THEN
37
- expect(Formio).toHaveBeenCalledWith("https://formio/formId/submission");
38
- expect(Formio.prototype.loadSubmissions).toHaveBeenCalledWith({
39
- params: parameters
40
- });
41
- expect(dispatch).toHaveBeenCalledWith({
42
- name: "name",
43
- type: requestSubmissions.toString(),
44
- payload: {
45
- formId,
46
- parameters
47
- }
48
- });
49
- expect(dispatch).toHaveBeenCalledWith({
50
- name: "name",
51
- payload: {
52
- submissions: [{}]
53
- },
54
- type: receiveSubmissions.toString()
55
- });
56
- });
57
- it("should return a error", async () => {
58
- // GIVEN
59
- (Formio.prototype.loadSubmissions as any).mockReturnValue(Promise.reject(new Error("message")));
60
- (Formio.getProjectUrl as any).mockReturnValue("https://formio");
61
-
62
- const dispatch = jest.fn();
63
- const name = "name";
64
- const formId = "formId";
65
- const parameters = {
66
- pageSize: 10,
67
- pageIndex: 0
68
- };
69
-
70
- const getState = () => ({
71
- [name]: {
72
- parameters
73
- }
74
- });
75
-
76
- // WHEN
77
- await new Promise((resolve) => getSubmissions(name, formId, parameters, resolve)(dispatch, getState));
78
-
79
- // THEN
80
- expect(Formio).toHaveBeenCalledWith("https://formio/formId/submission");
81
- expect(Formio.prototype.loadSubmissions).toHaveBeenCalledWith({
82
- params: parameters
83
- });
84
- expect(dispatch).toHaveBeenCalledWith({
85
- name: "name",
86
- type: requestSubmissions.toString(),
87
- payload: {
88
- formId,
89
- parameters
90
- }
91
- });
92
- expect(dispatch).toHaveBeenCalledWith({
93
- name: "name",
94
- payload: { error: new Error("message") },
95
- type: failSubmissions.toString()
96
- });
97
- });
98
- });
99
- });
@@ -1,38 +0,0 @@
1
- import { createAction } from "@tsed/redux-utils";
2
- import { Formio } from "formiojs";
3
- import noop from "lodash/noop";
4
-
5
- import { mapRequestParams } from "../../utils/mapRequestParams";
6
- import { getSubmissionUrl } from "../../utils/url";
7
- import { selectSubmissionsParameters } from "./submissions.selectors";
8
-
9
- export const resetSubmissions = createAction();
10
- export const requestSubmissions = createAction();
11
- export const receiveSubmissions = createAction();
12
- export const failSubmissions = createAction();
13
-
14
- export const getSubmissions =
15
- (name: string, formId: string, parameters: any = {}, done = noop) =>
16
- async (dispatch: any, getState: any) => {
17
- dispatch(requestSubmissions(name, { formId, parameters }));
18
-
19
- const url = getSubmissionUrl(formId);
20
- const formio = new Formio(url);
21
- const requestParams = mapRequestParams(selectSubmissionsParameters(name, getState()));
22
-
23
- try {
24
- const submissions = await formio.loadSubmissions({ params: requestParams });
25
- dispatch(receiveSubmissions(name, { submissions }));
26
- done(null, submissions);
27
- } catch (error) {
28
- dispatch(failSubmissions(name, { error }));
29
- done(error);
30
- }
31
- };
32
-
33
- export const refreshSubmissions = (name: string, formId: string, done = noop) => {
34
- return async (dispatch: any, getState: any) => {
35
- const parameters = selectSubmissionsParameters(name, getState());
36
- return getSubmissions(name, formId, parameters, done)(dispatch, getState);
37
- };
38
- };