@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.
- package/.env +2 -1
- package/craco.config.js +11 -1
- package/dist/components/alert/alert.component.spec.d.ts +1 -0
- package/dist/components/alert/alert.stories.d.ts +15 -0
- package/dist/components/card/card.component.d.ts +2 -1
- package/dist/components/form/form.component.d.ts +2 -0
- package/dist/components/form/form.stories.d.ts +37 -0
- package/dist/components/form/useForm.hook.d.ts +1 -0
- package/dist/components/form-action/formAction.stories.d.ts +90 -414
- package/dist/components/input-text/inputText.component.d.ts +1 -1
- package/dist/components/input-text/inputText.component.spec.d.ts +1 -0
- package/dist/components/loader/loader.component.d.ts +2 -2
- package/dist/components/loader/loader.stories.d.ts +15 -0
- package/dist/components/pagination/pagination.component.spec.d.ts +1 -0
- package/dist/components/pagination/pagination.stories.d.ts +0 -27
- package/dist/components/select/select.component.spec.d.ts +1 -0
- package/dist/components/tabs/tabs.component.spec.d.ts +1 -0
- package/dist/index.js +114 -35
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +86 -34
- package/dist/index.modern.js.map +1 -1
- package/jest.config.js +1 -1
- package/package.json +5 -9
- package/readme.md +114 -86
- package/src/components/__fixtures__/form-schema.json +10 -42
- package/src/components/__fixtures__/form.fixture.json +1 -1
- package/src/components/actions-table/actionsTable.component.spec.tsx +4 -13
- package/src/components/actions-table/actionsTable.component.tsx +3 -11
- package/src/components/alert/alert.component.spec.tsx +97 -0
- package/src/components/alert/alert.component.tsx +2 -8
- package/src/components/alert/alert.stories.tsx +17 -0
- package/src/components/card/card.component.tsx +2 -5
- package/src/components/form/form.component.tsx +4 -8
- package/src/components/form/form.stories.tsx +66 -2
- package/src/components/form/useForm.hook.ts +29 -14
- package/src/components/form-access/formAccess.component.tsx +19 -82
- package/src/components/form-access/formAccess.schema.ts +7 -23
- package/src/components/form-access/formAccess.stories.tsx +2 -9
- package/src/components/form-access/formAccess.utils.spec.ts +4 -22
- package/src/components/form-access/formAccess.utils.ts +7 -29
- package/src/components/form-action/formAction.component.tsx +3 -19
- package/src/components/form-action/formAction.stories.tsx +251 -672
- package/src/components/form-builder/formBuilder.component.tsx +4 -13
- package/src/components/form-builder/formBuilder.stories.tsx +12 -24
- package/src/components/form-control/formControl.component.tsx +2 -8
- package/src/components/form-edit/formCtas.component.tsx +5 -23
- package/src/components/form-edit/formEdit.component.tsx +2 -20
- package/src/components/form-edit/formEdit.reducer.ts +2 -8
- package/src/components/form-edit/formEdit.stories.tsx +3 -15
- package/src/components/form-edit/formParameters.component.tsx +3 -20
- package/src/components/form-edit/useFormEdit.hook.ts +2 -9
- package/src/components/form-settings/formSettings.component.spec.tsx +2 -9
- package/src/components/form-settings/formSettings.component.tsx +6 -34
- package/src/components/form-settings/formSettings.stories.tsx +1 -6
- package/src/components/form-settings/formSettings.utils.spec.ts +1 -4
- package/src/components/form-settings/formSettings.utils.ts +2 -7
- package/src/components/forms-table/components/formCell.component.tsx +2 -6
- package/src/components/forms-table/formsTable.component.tsx +2 -7
- package/src/components/input-tags/inputTags.component.tsx +10 -34
- package/src/components/input-tags/inputTags.stories.tsx +4 -14
- package/src/components/input-text/inputText.component.spec.tsx +56 -0
- package/src/components/input-text/inputText.component.tsx +4 -5
- package/src/components/input-text/inputText.stories.tsx +6 -26
- package/src/components/loader/loader.component.spec.tsx +7 -6
- package/src/components/loader/loader.component.tsx +3 -12
- package/src/components/loader/loader.stories.tsx +17 -0
- package/src/components/modal/modal.component.spec.tsx +8 -14
- package/src/components/modal/modal.component.tsx +6 -27
- package/src/components/modal/modal.stories.tsx +1 -5
- package/src/components/modal/removeModal.component.tsx +4 -22
- package/src/components/pagination/pagination.component.spec.tsx +111 -0
- package/src/components/pagination/pagination.component.tsx +10 -42
- package/src/components/pagination/pagination.stories.tsx +9 -29
- package/src/components/react-component/reactComponent.component.tsx +3 -11
- package/src/components/select/select.component.spec.tsx +86 -0
- package/src/components/select/select.component.tsx +11 -15
- package/src/components/select/select.stories.tsx +6 -26
- package/src/components/submissions-table/submissionsTable.component.tsx +1 -3
- package/src/components/submissions-table/submissionsTable.stories.tsx +1 -1
- package/src/components/table/components/defaultArrowSort.component.tsx +1 -10
- package/src/components/table/components/defaultCell.component.tsx +1 -4
- package/src/components/table/components/defaultCellHeader.component.tsx +4 -14
- package/src/components/table/components/defaultCellOperations.component.tsx +14 -25
- package/src/components/table/components/defaultOperationButton.component.tsx +2 -10
- package/src/components/table/filters/defaultColumnFilter.component.spec.tsx +1 -1
- package/src/components/table/filters/selectColumnFilter.component.spec.tsx +2 -10
- package/src/components/table/filters/selectColumnFilter.component.tsx +2 -6
- package/src/components/table/table.component.tsx +13 -53
- package/src/components/table/table.stories.tsx +1 -1
- package/src/components/table/utils/getPageNumbers.ts +3 -11
- package/src/components/table/utils/mapFormToColumns.tsx +14 -22
- package/src/components/table/utils/useOperations.hook.tsx +2 -12
- package/src/components/tabs/tabs.component.spec.tsx +86 -0
- package/src/components/tabs/tabs.component.stories.tsx +2 -9
- package/src/components/tabs/tabs.component.tsx +9 -43
- package/src/interfaces/Operation.ts +1 -4
- package/src/react-table.d.ts +9 -28
- package/src/stores/action/action.actions.ts +31 -33
- package/src/stores/action/action.reducers.spec.ts +1 -8
- package/src/stores/action/action.reducers.ts +1 -8
- package/src/stores/action/action.selectors.ts +1 -2
- package/src/stores/action-info/action-info.actions.spec.ts +1 -5
- package/src/stores/action-info/action-info.actions.ts +16 -19
- package/src/stores/action-info/action-info.reducers.spec.ts +1 -6
- package/src/stores/action-info/action-info.reducers.ts +1 -6
- package/src/stores/action-info/action-info.selectors.ts +1 -4
- package/src/stores/actions/actions.actions.spec.ts +1 -6
- package/src/stores/actions/actions.actions.ts +16 -19
- package/src/stores/actions/actions.reducers.spec.ts +1 -6
- package/src/stores/actions/actions.reducers.ts +1 -6
- package/src/stores/actions/actions.selectors.ts +2 -4
- package/src/stores/auth/auth.reducers.ts +1 -4
- package/src/stores/auth/auth.selectors.spec.ts +1 -5
- package/src/stores/auth/auth.selectors.ts +3 -6
- package/src/stores/auth/auth.utils.tsx +2 -8
- package/src/stores/auth/getAccess.action.spec.ts +11 -54
- package/src/stores/auth/getAccess.action.ts +1 -6
- package/src/stores/auth/initAuth.action.ts +15 -17
- package/src/stores/form/form.actions.spec.ts +8 -39
- package/src/stores/form/form.actions.ts +55 -64
- package/src/stores/form/form.reducers.spec.ts +1 -7
- package/src/stores/form/form.reducers.ts +1 -8
- package/src/stores/form/form.selectors.ts +1 -2
- package/src/stores/forms/forms.actions.spec.ts +5 -18
- package/src/stores/forms/forms.actions.ts +17 -21
- package/src/stores/forms/forms.reducers.spec.ts +1 -6
- package/src/stores/forms/forms.reducers.ts +2 -13
- package/src/stores/forms/forms.selectors.ts +2 -4
- package/src/stores/index.spec.ts +6 -9
- package/src/stores/root/root.selectors.spec.ts +1 -6
- package/src/stores/root/root.selectors.ts +6 -24
- package/src/stores/submission/submission.actions.spec.ts +11 -33
- package/src/stores/submission/submission.actions.ts +57 -66
- package/src/stores/submission/submission.reducers.spec.ts +17 -27
- package/src/stores/submission/submission.reducers.ts +1 -4
- package/src/stores/submission/submission.selectors.ts +1 -4
- package/src/stores/submissions/submissions.actions.spec.ts +5 -18
- package/src/stores/submissions/submissions.actions.ts +17 -26
- package/src/stores/submissions/submissions.reducers.spec.ts +3 -12
- package/src/stores/submissions/submissions.reducers.ts +3 -17
- package/src/stores/submissions/submissions.selectors.spec.ts +1 -4
- package/src/stores/submissions/submissions.selectors.ts +2 -4
- package/src/utils/getEventValue.ts +1 -4
- package/src/utils/iconClass.ts +2 -10
- package/src/utils/mapPagination.ts +1 -6
- package/src/utils/mapRequestParams.ts +2 -12
- package/src/utils/url.test.ts +4 -12
- package/src/utils/url.ts +2 -7
- package/tsconfig.json +4 -12
- package/tsconfig.test.json +1 -1
- package/.eslintrc +0 -47
- package/.prettierrc +0 -10
|
@@ -9,26 +9,23 @@ export const requestActionInfo = createAction();
|
|
|
9
9
|
export const receiveActionInfo = createAction();
|
|
10
10
|
export const failActionInfo = createAction();
|
|
11
11
|
|
|
12
|
-
export const getActionInfo =
|
|
13
|
-
formId: string,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
) => async (dispatch: any) => {
|
|
17
|
-
dispatch(requestActionInfo(ACTION_INFO));
|
|
12
|
+
export const getActionInfo =
|
|
13
|
+
(formId: string, actionType: string, done = noop) =>
|
|
14
|
+
async (dispatch: any) => {
|
|
15
|
+
dispatch(requestActionInfo(ACTION_INFO));
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
const url = getFormUrl(formId);
|
|
18
|
+
const formio = new Formio(url);
|
|
21
19
|
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
try {
|
|
21
|
+
const actionInfo = await formio.actionInfo(actionType);
|
|
24
22
|
|
|
25
|
-
|
|
26
|
-
Formio.getProjectUrl() + actionInfo.settingsForm.action;
|
|
23
|
+
actionInfo.settingsForm.action = Formio.getProjectUrl() + actionInfo.settingsForm.action;
|
|
27
24
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
};
|
|
25
|
+
dispatch(receiveActionInfo(ACTION_INFO, { actionInfo }));
|
|
26
|
+
done(null, actionInfo);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
dispatch(failActionInfo(ACTION_INFO, { error }));
|
|
29
|
+
done(error);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
failActionInfo,
|
|
3
|
-
receiveActionInfo,
|
|
4
|
-
requestActionInfo,
|
|
5
|
-
resetActionInfo
|
|
6
|
-
} from "./action-info.actions";
|
|
1
|
+
import { failActionInfo, receiveActionInfo, requestActionInfo, resetActionInfo } from "./action-info.actions";
|
|
7
2
|
import { ACTION_INFO } from "./action-info.constant";
|
|
8
3
|
import { actionInfoReducer } from "./action-info.reducers";
|
|
9
4
|
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { InitialStateCreator, createReducer } from "@tsed/redux-utils";
|
|
2
2
|
import { ActionSchema } from "../../interfaces";
|
|
3
|
-
import {
|
|
4
|
-
failActionInfo,
|
|
5
|
-
receiveActionInfo,
|
|
6
|
-
requestActionInfo,
|
|
7
|
-
resetActionInfo
|
|
8
|
-
} from "./action-info.actions";
|
|
3
|
+
import { failActionInfo, receiveActionInfo, requestActionInfo, resetActionInfo } from "./action-info.actions";
|
|
9
4
|
import { ACTION_INFO } from "./action-info.constant";
|
|
10
5
|
|
|
11
6
|
export interface ActionInfoState {
|
|
@@ -3,7 +3,4 @@ import { selectRoot } from "../root";
|
|
|
3
3
|
import { ACTION_INFO } from "./action-info.constant";
|
|
4
4
|
import { ActionInfoState } from "./action-info.reducers";
|
|
5
5
|
|
|
6
|
-
export const selectActionInfo = (
|
|
7
|
-
state: Record<string, any>
|
|
8
|
-
): Partial<ActionSchema> =>
|
|
9
|
-
selectRoot<ActionInfoState>(ACTION_INFO, state).data;
|
|
6
|
+
export const selectActionInfo = (state: Record<string, any>): Partial<ActionSchema> => selectRoot<ActionInfoState>(ACTION_INFO, state).data;
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { Formio } from "formiojs";
|
|
2
|
-
import {
|
|
3
|
-
getActions,
|
|
4
|
-
receiveActions,
|
|
5
|
-
requestActions,
|
|
6
|
-
resetActions
|
|
7
|
-
} from "./actions.actions";
|
|
2
|
+
import { getActions, receiveActions, requestActions, resetActions } from "./actions.actions";
|
|
8
3
|
|
|
9
4
|
jest.mock("formiojs");
|
|
10
5
|
|
|
@@ -12,25 +12,22 @@ export const receiveActions = createAction<{
|
|
|
12
12
|
}>();
|
|
13
13
|
export const failActions = createAction<{ error: Error }>();
|
|
14
14
|
|
|
15
|
-
export const getActions =
|
|
16
|
-
|
|
17
|
-
) => {
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
export const getActions =
|
|
16
|
+
(id: string, done = noop) =>
|
|
17
|
+
async (dispatch: any) => {
|
|
18
|
+
dispatch(resetActions(ACTIONS));
|
|
19
|
+
dispatch(requestActions(ACTIONS));
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
const url = getFormUrl(id);
|
|
22
|
+
const formio = new Formio(url);
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
formio.loadActions({ params: {} }),
|
|
27
|
-
formio.availableActions()
|
|
28
|
-
]);
|
|
24
|
+
try {
|
|
25
|
+
const [actions, availableActions] = await Promise.all([formio.loadActions({ params: {} }), formio.availableActions()]);
|
|
29
26
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
};
|
|
27
|
+
dispatch(receiveActions(ACTIONS, { actions, availableActions }));
|
|
28
|
+
done(null, actions, availableActions);
|
|
29
|
+
} catch (error) {
|
|
30
|
+
dispatch(failActions(ACTIONS, { error }));
|
|
31
|
+
done(error);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
failActions,
|
|
3
|
-
receiveActions,
|
|
4
|
-
requestActions,
|
|
5
|
-
resetActions
|
|
6
|
-
} from "./actions.actions";
|
|
1
|
+
import { failActions, receiveActions, requestActions, resetActions } from "./actions.actions";
|
|
7
2
|
import { ACTIONS } from "./actions.constant";
|
|
8
3
|
import { actionsReducer } from "./actions.reducers";
|
|
9
4
|
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { createReducer, InitialStateCreator } from "@tsed/redux-utils";
|
|
2
2
|
import { ActionInfoSchema, ActionSchema } from "../../interfaces";
|
|
3
|
-
import {
|
|
4
|
-
failActions,
|
|
5
|
-
receiveActions,
|
|
6
|
-
requestActions,
|
|
7
|
-
resetActions
|
|
8
|
-
} from "./actions.actions";
|
|
3
|
+
import { failActions, receiveActions, requestActions, resetActions } from "./actions.actions";
|
|
9
4
|
import { ACTIONS } from "./actions.constant";
|
|
10
5
|
|
|
11
6
|
export interface ActionsState {
|
|
@@ -2,8 +2,6 @@ import { selectRoot } from "../root";
|
|
|
2
2
|
import { ACTIONS } from "./actions.constant";
|
|
3
3
|
import { ActionsState } from "./actions.reducers";
|
|
4
4
|
|
|
5
|
-
export const selectActions = (state: Record<string, any>) =>
|
|
6
|
-
selectRoot<ActionsState>(ACTIONS, state).data;
|
|
5
|
+
export const selectActions = (state: Record<string, any>) => selectRoot<ActionsState>(ACTIONS, state).data;
|
|
7
6
|
|
|
8
|
-
export const selectAvailableActions = (state: Record<string, any>) =>
|
|
9
|
-
selectRoot<ActionsState>(ACTIONS, state).availableActions;
|
|
7
|
+
export const selectAvailableActions = (state: Record<string, any>) => selectRoot<ActionsState>(ACTIONS, state).availableActions;
|
|
@@ -44,10 +44,7 @@ function createInitialState(): AuthState {
|
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
function mapProjectRolesToUserRoles(
|
|
48
|
-
projectRoles: Record<string, any>,
|
|
49
|
-
userRoles: any[]
|
|
50
|
-
) {
|
|
47
|
+
function mapProjectRolesToUserRoles(projectRoles: Record<string, any>, userRoles: any[]) {
|
|
51
48
|
return Object.entries(projectRoles).reduce(
|
|
52
49
|
(result, [name, role]) => ({
|
|
53
50
|
...result,
|
|
@@ -6,11 +6,8 @@ import { AuthState } from "./auth.reducers";
|
|
|
6
6
|
|
|
7
7
|
export const selectAuth = (state: any) => selectRoot<AuthState>(AUTH, state);
|
|
8
8
|
|
|
9
|
-
export const selectUser = <User = any>(state: any): null | Submission<User> =>
|
|
10
|
-
get(selectAuth(state), "user");
|
|
9
|
+
export const selectUser = <User = any>(state: any): null | Submission<User> => get(selectAuth(state), "user");
|
|
11
10
|
|
|
12
|
-
export const selectRoles = (state: any): Record<string, RoleSchema> =>
|
|
13
|
-
get(selectAuth(state), "roles");
|
|
11
|
+
export const selectRoles = (state: any): Record<string, RoleSchema> => get(selectAuth(state), "roles");
|
|
14
12
|
|
|
15
|
-
export const selectIsAuthenticated = (state: any): boolean =>
|
|
16
|
-
get(selectAuth(state), "authenticated");
|
|
13
|
+
export const selectIsAuthenticated = (state: any): boolean => get(selectAuth(state), "authenticated");
|
|
@@ -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 =
|
|
11
|
-
|
|
10
|
+
export const initAuth =
|
|
11
|
+
(done = noop) =>
|
|
12
|
+
async (dispatch: any) => {
|
|
13
|
+
dispatch(requestUser(AUTH));
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
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");
|