From 0380a0682d16ba35c707cb7b0f68920fb8a4908d Mon Sep 17 00:00:00 2001 From: Romain Lenzotti Date: Sat, 4 Jan 2025 19:00:15 +0100 Subject: [PATCH] fix(react-formio): changing naming convention for Type (prefix by Type instead Schema) --- .../src/hooks/useAction.hook.tsx | 12 +++--- .../src/hooks/useActions.hook.ts | 8 ++-- .../src/hooks/useForm.hook.ts | 8 ++-- .../src/hooks/useForms.hook.ts | 6 +-- .../src/hooks/useSubmission.hook.tsx | 6 +-- .../src/hooks/useSubmissions.hook.tsx | 6 +-- .../src/interfaces/FormioContainerOptions.ts | 6 +-- .../src/utils/ExportClient.ts | 8 ++-- .../src/views/form.routes.tsx | 6 +-- .../src/views/submissions.stories.tsx | 4 +- .../action-info/action-info.reducers.ts | 4 +- .../action-info/action-info.selectors.ts | 5 +-- .../src/stores/action/action.reducers.ts | 4 +- .../src/stores/action/action.selectors.ts | 4 +- .../src/stores/actions/actions.reducers.ts | 6 +-- .../src/stores/auth/auth.actions.ts | 8 ++-- .../src/stores/auth/auth.reducers.ts | 10 ++--- .../src/stores/auth/auth.selectors.ts | 6 +-- .../src/stores/auth/auth.utils.tsx | 4 +- .../src/stores/auth/getAccess.action.ts | 10 ++--- .../src/stores/form/form.actions.ts | 6 +-- .../src/stores/form/form.reducers.ts | 4 +- .../src/stores/form/form.selectors.ts | 4 +- .../src/stores/forms/forms.actions.ts | 8 ++-- .../src/stores/forms/forms.reducers.ts | 4 +- .../stores/submission/submission.actions.ts | 4 +- .../stores/submission/submission.reducers.ts | 4 +- .../stores/submission/submission.selectors.ts | 4 +- .../submissions/submissions.reducers.ts | 4 +- .../actions-table/actionsTable.component.tsx | 4 +- .../actions-table/actionsTable.stories.tsx | 2 +- .../src/components/alert/alert.stories.tsx | 2 +- .../src/components/card/card.stories.tsx | 2 +- .../form-access/formAccess.component.tsx | 25 ++++++----- .../form-access/formAccess.schema.ts | 10 ++--- .../form-access/formAccess.stories.tsx | 2 +- .../form-access/formAccess.utils.spec.ts | 20 +++++---- .../form-access/formAccess.utils.ts | 42 ++++++++++--------- .../form-action/formAction.component.tsx | 10 ++--- .../form-action/formAction.stories.tsx | 2 +- .../form-builder/formBuilder.stories.tsx | 2 +- .../form-control/formControl.stories.tsx | 2 +- .../components/form-edit/formEdit.reducer.ts | 12 +++--- .../components/form-edit/formEdit.stories.tsx | 2 +- .../form-edit/formParameters.component.tsx | 4 +- .../components/form-edit/useFormEdit.hook.ts | 10 ++--- .../form-settings/formSettings.component.tsx | 11 +++-- .../form-settings/formSettings.schema.ts | 4 +- .../form-settings/formSettings.stories.tsx | 2 +- .../form-settings/formSettings.utils.ts | 8 ++-- .../components/form/form.component.spec.tsx | 6 +-- .../src/components/form/form.component.tsx | 11 ++--- .../src/components/form/form.stories.tsx | 2 +- .../react-formio/src/components/form/types.ts | 8 ++++ .../src/components/form/useForm.hook.ts | 41 +++++++----------- .../components/formCell.component.tsx | 4 +- .../forms-table/formsTable.component.tsx | 4 +- .../forms-table/formsTable.stories.tsx | 2 +- .../input-tags/inputTags.stories.tsx | 2 +- .../input-text/inputText.stories.tsx | 2 +- .../src/components/loader/loader.stories.tsx | 2 +- .../src/components/modal/modal.stories.tsx | 2 +- .../pagination/pagination.stories.tsx | 2 +- .../src/components/select/select.stories.tsx | 2 +- .../submissionsTable.component.tsx | 6 +-- .../submissionsTable.stories.tsx | 6 +-- .../src/components/table/table.stories.tsx | 8 ++-- .../table/utils/mapFormToColumns.tsx | 9 ++-- .../tabs/tabs.component.stories.tsx | 2 +- .../src/interfaces/ActionSchema.ts | 26 ------------ .../react-formio/src/interfaces/ActionType.ts | 26 ++++++++++++ .../src/interfaces/ComponentType.ts | 3 ++ .../src/interfaces/FormOptions.ts | 5 ++- .../interfaces/{FormSchema.ts => FormType.ts} | 6 +-- .../interfaces/{RoleSchema.ts => RoleType.ts} | 2 +- .../react-formio/src/interfaces/Submission.ts | 5 --- .../src/interfaces/SubmissionType.ts | 20 +++++++++ packages/react-formio/src/interfaces/index.ts | 9 ++-- 78 files changed, 299 insertions(+), 275 deletions(-) create mode 100644 packages/react-formio/src/components/form/types.ts delete mode 100644 packages/react-formio/src/interfaces/ActionSchema.ts create mode 100644 packages/react-formio/src/interfaces/ActionType.ts create mode 100644 packages/react-formio/src/interfaces/ComponentType.ts rename packages/react-formio/src/interfaces/{FormSchema.ts => FormType.ts} (59%) rename packages/react-formio/src/interfaces/{RoleSchema.ts => RoleType.ts} (54%) delete mode 100644 packages/react-formio/src/interfaces/Submission.ts create mode 100644 packages/react-formio/src/interfaces/SubmissionType.ts diff --git a/packages/react-formio-container/src/hooks/useAction.hook.tsx b/packages/react-formio-container/src/hooks/useAction.hook.tsx index fc5b95ad..8677717a 100644 --- a/packages/react-formio-container/src/hooks/useAction.hook.tsx +++ b/packages/react-formio-container/src/hooks/useAction.hook.tsx @@ -1,6 +1,6 @@ import { - ActionInfoSchema, - ActionSchema, + ActionInfoType, + ActionType, deleteAction, getAction, getActionInfo, @@ -11,7 +11,7 @@ import { selectAuth, selectError, selectForm, - Submission, + SubmissionType, Utils } from "@tsed/react-formio-stores"; import { push } from "connected-react-router"; @@ -35,7 +35,7 @@ export function useAction(props: UseActionProps) { const form = useSelector((state) => selectForm(type, state)); const error = useSelector((state) => selectError("action", state)); const action = useSelector(selectAction); - const actionInfo: ActionInfoSchema | undefined = useSelector(selectActionInfo) as any; + const actionInfo: ActionInfoType | undefined = useSelector(selectActionInfo) as any; const fetch = useCallback(() => { if (form?._id) { @@ -47,7 +47,7 @@ export function useAction(props: UseActionProps) { } }, [form?._id, actionId]); - const onSaveDone = (err: Error | null, actionInfo: ActionSchema) => { + const onSaveDone = (err: Error | null, actionInfo: ActionType) => { if (!err) { onSuccess({ name: `${actionAction}:action`, @@ -68,7 +68,7 @@ export function useAction(props: UseActionProps) { } }; - const saveAction = (actionInfo: Submission) => { + const saveAction = (actionInfo: SubmissionType) => { dispatch(saveAct(form?._id!, actionInfo, onSaveDone)); }; diff --git a/packages/react-formio-container/src/hooks/useActions.hook.ts b/packages/react-formio-container/src/hooks/useActions.hook.ts index ce922e4e..60b86de8 100644 --- a/packages/react-formio-container/src/hooks/useActions.hook.ts +++ b/packages/react-formio-container/src/hooks/useActions.hook.ts @@ -1,6 +1,6 @@ import { - ActionInfoSchema, - ActionSchema, + ActionInfoType, + ActionType, Operation, selectActions, selectAuth, @@ -37,13 +37,13 @@ export function useActions(props: UseActionsProps) { }); const [operation, setOperation] = useState(); - const [currentAction, setCurrentAction] = useState(availableActions[0]); + const [currentAction, setCurrentAction] = useState(availableActions[0]); const addAction = (actionName: string) => { dispatch(push([basePath, actionName, "add"].join("/"))); }; - const dispatchOperation = (actionInfo: ActionSchema, operation: Operation) => { + const dispatchOperation = (actionInfo: ActionType, operation: Operation) => { setOperation(operation); dispatch(push([basePath, (actionInfo as any)._id, operation.action].join("/"))); diff --git a/packages/react-formio-container/src/hooks/useForm.hook.ts b/packages/react-formio-container/src/hooks/useForm.hook.ts index fc7378f3..447d8fbb 100644 --- a/packages/react-formio-container/src/hooks/useForm.hook.ts +++ b/packages/react-formio-container/src/hooks/useForm.hook.ts @@ -1,7 +1,7 @@ import { AuthState, deleteForm, - FormSchema, + FormType, getForm as getFormAction, oneOfIsActive, receiveForm, @@ -99,7 +99,7 @@ export function useForm(props: UseFormProps) { form._id && dispatch(deleteForm(formType, form._id, onRemoveDone)); }; - const duplicateForm = (form: Partial) => { + const duplicateForm = (form: Partial) => { dispatch(receiveForm(formType, { ...form, _id: undefined })); dispatch(push(`${basePath}/create`)); onSuccess({ @@ -110,7 +110,7 @@ export function useForm(props: UseFormProps) { }); }; - const onSaveDone = async (err: Error | null, updatedForm: FormSchema) => { + const onSaveDone = async (err: Error | null, updatedForm: FormType) => { if (!err) { dispatch(refreshForms(formType)); @@ -133,7 +133,7 @@ export function useForm(props: UseFormProps) { } }; - const saveForm = (form: Partial) => { + const saveForm = (form: Partial) => { onSubmitForm(type, form); dispatch(saveFormAction(type, form, onSaveDone)); }; diff --git a/packages/react-formio-container/src/hooks/useForms.hook.ts b/packages/react-formio-container/src/hooks/useForms.hook.ts index 0783023b..8383a18f 100644 --- a/packages/react-formio-container/src/hooks/useForms.hook.ts +++ b/packages/react-formio-container/src/hooks/useForms.hook.ts @@ -1,4 +1,4 @@ -import { FormSchema, FormsState, getForms, Operation, selectRoot } from "@tsed/react-formio-stores"; +import { FormsState, FormType, getForms, Operation, selectRoot } from "@tsed/react-formio-stores"; import { push } from "connected-react-router"; import { useCallback, useEffect, useState } from "react"; import { useDispatch, useSelector } from "react-redux"; @@ -23,9 +23,9 @@ export function useForms(props: UseFormsProps) { const { error, data, isActive, parameters } = useSelector((state) => selectRoot(formType, state)); const setParameters = useQuery(fetch, parameters); const [operation, setOperation] = useState(); - const [currentData, setCurrentData] = useState(); + const [currentData, setCurrentData] = useState(); - const dispatchOperation = (data: FormSchema, operation: Operation) => { + const dispatchOperation = (data: FormType, operation: Operation) => { setOperation(operation); setCurrentData(currentData); dispatch(push([basePath.replace(":formType", formType), data._id, operation.action].join("/"))); diff --git a/packages/react-formio-container/src/hooks/useSubmission.hook.tsx b/packages/react-formio-container/src/hooks/useSubmission.hook.tsx index 32a23f3e..f11737dd 100644 --- a/packages/react-formio-container/src/hooks/useSubmission.hook.tsx +++ b/packages/react-formio-container/src/hooks/useSubmission.hook.tsx @@ -12,7 +12,7 @@ import { selectIsActive, selectRoot, selectSubmission, - Submission + SubmissionType } from "@tsed/react-formio-stores"; import { push } from "connected-react-router"; import noop from "lodash/noop"; @@ -82,7 +82,7 @@ export function useSubmission(props: UseSubmissionProps) { submissionId && dispatch(deleteSubmission(submissionType, formId, submissionId, onRemoveDone)); }; - const onSaveDone = async (err: Error | null, updatedSubmission: Submission) => { + const onSaveDone = async (err: Error | null, updatedSubmission: SubmissionType) => { if (!err) { onSuccess({ name: `${submissionAction}:${submissionType}`, @@ -104,7 +104,7 @@ export function useSubmission(props: UseSubmissionProps) { } }; - const saveSubmission = (submission: Submission) => { + const saveSubmission = (submission: SubmissionType) => { onSubmitSubmission(submissionType, formId, submission); dispatch(saveSubmissionAction(submissionType, formId, submission, onSaveDone)); }; diff --git a/packages/react-formio-container/src/hooks/useSubmissions.hook.tsx b/packages/react-formio-container/src/hooks/useSubmissions.hook.tsx index 4a0a6516..1a100e9e 100644 --- a/packages/react-formio-container/src/hooks/useSubmissions.hook.tsx +++ b/packages/react-formio-container/src/hooks/useSubmissions.hook.tsx @@ -1,4 +1,4 @@ -import { getSubmissions, Operation, selectAuth, selectForm, selectRoot, Submission, SubmissionsState } from "@tsed/react-formio-stores"; +import { getSubmissions, Operation, selectAuth, selectForm, selectRoot, SubmissionsState, SubmissionType } from "@tsed/react-formio-stores"; import { push } from "connected-react-router"; import { useCallback, useEffect, useState } from "react"; import { useDispatch, useSelector } from "react-redux"; @@ -28,9 +28,9 @@ export function useSubmissions(props: UseSubmissionsProps) { const setParameters = useQuery(fetch, parameters); const [operation, setOperation] = useState(); - const [currentData, setCurrentData] = useState(); + const [currentData, setCurrentData] = useState(); - const dispatchOperation = (data: Submission, operation: Operation) => { + const dispatchOperation = (data: SubmissionType, operation: Operation) => { setOperation(operation); setCurrentData(currentData); dispatch(push([basePath, data._id, operation.action].join("/"))); diff --git a/packages/react-formio-container/src/interfaces/FormioContainerOptions.ts b/packages/react-formio-container/src/interfaces/FormioContainerOptions.ts index d034e793..6b10b5c8 100644 --- a/packages/react-formio-container/src/interfaces/FormioContainerOptions.ts +++ b/packages/react-formio-container/src/interfaces/FormioContainerOptions.ts @@ -1,4 +1,4 @@ -import { FormSchema, Submission } from "@tsed/react-formio"; +import { FormType, SubmissionType } from "@tsed/react-formio"; import { FormRoute } from "../views/form.routes"; @@ -54,8 +54,8 @@ export interface FormioContainerOptions extends Record { * Handler called when an event is an error */ onError?: FormioErrorHandler; - onSubmitForm?: (type: string, form: FormSchema) => void; - onSubmitSubmission?: (submissionType: string, formId: string, submission: Submission) => void; + onSubmitForm?: (type: string, form: FormType) => void; + onSubmitSubmission?: (submissionType: string, formId: string, submission: SubmissionType) => void; /** * i18n function to translate sentences */ diff --git a/packages/react-formio-container/src/utils/ExportClient.ts b/packages/react-formio-container/src/utils/ExportClient.ts index 0ab5144d..28facca1 100644 --- a/packages/react-formio-container/src/utils/ExportClient.ts +++ b/packages/react-formio-container/src/utils/ExportClient.ts @@ -1,4 +1,4 @@ -import { FormSchema } from "@tsed/react-formio"; +import { FormType } from "@tsed/react-formio"; import FileSaver from "file-saver"; import moment from "moment"; @@ -8,12 +8,12 @@ async function getDatabase() { return httpClient.get("/export"); } -async function exportForm(form: FormSchema) { +async function exportForm(form: FormType) { const database = await getDatabase(); return database.forms[form.machineName!] || database.resources[form.machineName!]; } -async function exportActions(form: FormSchema) { +async function exportActions(form: FormType) { const database = await getDatabase(); return Object.entries(database.actions).reduce((obj, [machineName, action]) => { @@ -25,7 +25,7 @@ async function exportActions(form: FormSchema) { }, {}); } -async function getContent(form: FormSchema, type: string, format = "json") { +async function getContent(form: FormType, type: string, format = "json") { let result; console.log(form, type, format); switch (type) { diff --git a/packages/react-formio-container/src/views/form.routes.tsx b/packages/react-formio-container/src/views/form.routes.tsx index caed36cf..79fc6b01 100644 --- a/packages/react-formio-container/src/views/form.routes.tsx +++ b/packages/react-formio-container/src/views/form.routes.tsx @@ -1,5 +1,5 @@ import type { TabsItemProps } from "@tsed/react-formio"; -import { AuthState, checkRoleFormAccess, FormSchema } from "@tsed/react-formio-stores"; +import { AuthState, checkRoleFormAccess, FormType } from "@tsed/react-formio-stores"; import { ComponentType } from "react"; import { FormAccessView } from "./formAccess.view"; @@ -16,7 +16,7 @@ export interface FormRoute extends TabsItemProps, Record; roles?: string[]; - when?(ctx: { formAction: string; auth: AuthState; form: Partial; item: FormRoute }): boolean; + when?(ctx: { formAction: string; auth: AuthState; form: Partial; item: FormRoute }): boolean; } export interface FormRoutesOptions { @@ -24,7 +24,7 @@ export interface FormRoutesOptions { operationsSettings: Record; formAction: string; auth: AuthState; - form: Partial; + form: Partial; } export const defaultFormRoutes: FormRoute[] = [ diff --git a/packages/react-formio-container/src/views/submissions.stories.tsx b/packages/react-formio-container/src/views/submissions.stories.tsx index 2fd8f624..ff064dc3 100644 --- a/packages/react-formio-container/src/views/submissions.stories.tsx +++ b/packages/react-formio-container/src/views/submissions.stories.tsx @@ -1,4 +1,4 @@ -import formSchema from "../__fixtures__/form-schema.json"; +import FormType from "../__fixtures__/form-schema.json"; import formSubmissions from "../__fixtures__/form-submissions.json"; import { SubmissionsComponent } from "./submissions.view"; @@ -22,6 +22,6 @@ export const Sandbox = (args: any) => { }; Sandbox.args = { - form: formSchema, + form: FormType, data: formSubmissions }; diff --git a/packages/react-formio-stores/src/stores/action-info/action-info.reducers.ts b/packages/react-formio-stores/src/stores/action-info/action-info.reducers.ts index eda2d2ed..c6aa5f33 100644 --- a/packages/react-formio-stores/src/stores/action-info/action-info.reducers.ts +++ b/packages/react-formio-stores/src/stores/action-info/action-info.reducers.ts @@ -1,4 +1,4 @@ -import type { ActionSchema } from "@tsed/react-formio"; +import type { ActionType } from "@tsed/react-formio"; import { createReducer, InitialStateCreator } from "@tsed/redux-utils"; import { failActionInfo, receiveActionInfo, requestActionInfo, resetActionInfo } from "./action-info.actions"; @@ -6,7 +6,7 @@ import { ACTION_INFO } from "./action-info.constant"; export interface ActionInfoState { error: null | Error; - data?: Partial; + data?: Partial; isActive: boolean; } diff --git a/packages/react-formio-stores/src/stores/action-info/action-info.selectors.ts b/packages/react-formio-stores/src/stores/action-info/action-info.selectors.ts index 1da79913..11e4f28a 100644 --- a/packages/react-formio-stores/src/stores/action-info/action-info.selectors.ts +++ b/packages/react-formio-stores/src/stores/action-info/action-info.selectors.ts @@ -1,8 +1,7 @@ -import type { ActionSchema } from "@tsed/react-formio"; +import type { ActionType } from "@tsed/react-formio"; import { selectRoot } from "../root"; import { ACTION_INFO } from "./action-info.constant"; import { ActionInfoState } from "./action-info.reducers"; -export const selectActionInfo = (state: Record): Partial => - selectRoot(ACTION_INFO, state).data!; +export const selectActionInfo = (state: Record): Partial => selectRoot(ACTION_INFO, state).data!; diff --git a/packages/react-formio-stores/src/stores/action/action.reducers.ts b/packages/react-formio-stores/src/stores/action/action.reducers.ts index 38eb4ccc..6174cc7b 100644 --- a/packages/react-formio-stores/src/stores/action/action.reducers.ts +++ b/packages/react-formio-stores/src/stores/action/action.reducers.ts @@ -1,4 +1,4 @@ -import type { ActionSchema } from "@tsed/react-formio"; +import type { ActionType } from "@tsed/react-formio"; import { createReducer, InitialStateCreator } from "@tsed/redux-utils"; import { clearActionError, failAction, receiveAction, requestAction, resetAction, sendAction } from "./action.actions"; @@ -6,7 +6,7 @@ import { ACTION } from "./action.constant"; export interface ActionState { error: null | Error; - data: ActionSchema; + data: ActionType; isActive: boolean; } diff --git a/packages/react-formio-stores/src/stores/action/action.selectors.ts b/packages/react-formio-stores/src/stores/action/action.selectors.ts index 2413583c..7e346fd0 100644 --- a/packages/react-formio-stores/src/stores/action/action.selectors.ts +++ b/packages/react-formio-stores/src/stores/action/action.selectors.ts @@ -1,7 +1,7 @@ -import type { ActionSchema } from "@tsed/react-formio"; +import type { ActionType } from "@tsed/react-formio"; import { selectRoot } from "../root"; import { ACTION } from "./action.constant"; import { ActionState } from "./action.reducers"; -export const selectAction = (state: Record): ActionSchema => selectRoot(ACTION, state).data; +export const selectAction = (state: Record): ActionType => selectRoot(ACTION, state).data; diff --git a/packages/react-formio-stores/src/stores/actions/actions.reducers.ts b/packages/react-formio-stores/src/stores/actions/actions.reducers.ts index 8245af4c..bc67d50e 100644 --- a/packages/react-formio-stores/src/stores/actions/actions.reducers.ts +++ b/packages/react-formio-stores/src/stores/actions/actions.reducers.ts @@ -1,4 +1,4 @@ -import type { ActionInfoSchema, ActionSchema } from "@tsed/react-formio"; +import type { ActionInfoType, ActionType } from "@tsed/react-formio"; import { createReducer, InitialStateCreator } from "@tsed/redux-utils"; import { failActions, receiveActions, requestActions, resetActions } from "./actions.actions"; @@ -6,8 +6,8 @@ import { ACTIONS } from "./actions.constant"; export interface ActionsState { error: null | Error; - data: ActionSchema[]; - availableActions: ActionInfoSchema[]; + data: ActionType[]; + availableActions: ActionInfoType[]; isActive: boolean; } diff --git a/packages/react-formio-stores/src/stores/auth/auth.actions.ts b/packages/react-formio-stores/src/stores/auth/auth.actions.ts index 9c12930e..dfc07dea 100644 --- a/packages/react-formio-stores/src/stores/auth/auth.actions.ts +++ b/packages/react-formio-stores/src/stores/auth/auth.actions.ts @@ -1,12 +1,12 @@ -import type { FormSchema, RoleSchema, Submission } from "@tsed/react-formio"; +import type { FormType, RoleType, SubmissionType } from "@tsed/react-formio"; import { createAction } from "@tsed/redux-utils"; export const requestUser = createAction(); -export const receiveUser = createAction<{ user: Submission }>(); +export const receiveUser = createAction<{ user: SubmissionType }>(); export const failUser = createAction<{ error: Error }>(); export const logoutUser = createAction(); export const submissionAccessUser = createAction<{ submissionAccess: any }>(); export const formAccessUser = createAction<{ formAccess: any }>(); export const projectAccessUser = createAction<{ projectAccess: any }>(); -export const userRoles = createAction<{ roles: Record }>(); -export const userForms = createAction<{ forms: Record }>(); +export const userRoles = createAction<{ roles: Record }>(); +export const userForms = createAction<{ forms: Record }>(); diff --git a/packages/react-formio-stores/src/stores/auth/auth.reducers.ts b/packages/react-formio-stores/src/stores/auth/auth.reducers.ts index c2890ec9..40f33310 100644 --- a/packages/react-formio-stores/src/stores/auth/auth.reducers.ts +++ b/packages/react-formio-stores/src/stores/auth/auth.reducers.ts @@ -1,4 +1,4 @@ -import type { FormSchema, RoleSchema, Submission } from "@tsed/react-formio"; +import type { FormType, RoleType, SubmissionType } from "@tsed/react-formio"; import { createReducer } from "@tsed/redux-utils"; import { @@ -17,13 +17,13 @@ import { AUTH } from "./auth.constant"; export interface AuthState { init: boolean; isActive: boolean; - user: null | Submission; + user: null | SubmissionType; authenticated: boolean; projectAccess: Record; formAccess: Record; submissionAccess: Record; - roles: Record; - forms: Record; + roles: Record; + forms: Record; is: Record; error: null | Error; } @@ -54,7 +54,7 @@ function mapProjectRolesToUserRoles(projectRoles: Record, userRoles ); } -function getUserRoles(projectRoles: Record) { +function getUserRoles(projectRoles: Record) { return Object.keys(projectRoles).reduce( (result, name) => ({ ...result, diff --git a/packages/react-formio-stores/src/stores/auth/auth.selectors.ts b/packages/react-formio-stores/src/stores/auth/auth.selectors.ts index 03db35c5..e83af134 100644 --- a/packages/react-formio-stores/src/stores/auth/auth.selectors.ts +++ b/packages/react-formio-stores/src/stores/auth/auth.selectors.ts @@ -1,4 +1,4 @@ -import type { RoleSchema, Submission } from "@tsed/react-formio"; +import type { RoleType, SubmissionType } from "@tsed/react-formio"; import get from "lodash/get"; import { selectRoot } from "../root"; @@ -7,8 +7,8 @@ import { AuthState } from "./auth.reducers"; export const selectAuth = (state: any) => selectRoot(AUTH, state); -export const selectUser = (state: any): null | Submission => get(selectAuth(state), "user"); +export const selectUser = (state: any): null | SubmissionType => get(selectAuth(state), "user"); -export const selectRoles = (state: any): Record => get(selectAuth(state), "roles"); +export const selectRoles = (state: any): Record => get(selectAuth(state), "roles"); export const selectIsAuthenticated = (state: any): boolean => get(selectAuth(state), "authenticated"); diff --git a/packages/react-formio-stores/src/stores/auth/auth.utils.tsx b/packages/react-formio-stores/src/stores/auth/auth.utils.tsx index c7733d68..26f90812 100644 --- a/packages/react-formio-stores/src/stores/auth/auth.utils.tsx +++ b/packages/react-formio-stores/src/stores/auth/auth.utils.tsx @@ -1,4 +1,4 @@ -import type { FormSchema } from "@tsed/react-formio"; +import type { FormType } from "@tsed/react-formio"; import get from "lodash/get"; import { AuthState } from "./auth.reducers"; @@ -24,7 +24,7 @@ export function isAuthorized(auth: AuthState, roles: string[] = []): boolean { return false; } -export function checkRoleFormAccess(auth: AuthState, form?: Partial, roles?: string[]) { +export function checkRoleFormAccess(auth: AuthState, form?: Partial, roles?: string[]) { if (roles && roles.length) { if (isAuthorized(auth, roles)) { return true; diff --git a/packages/react-formio-stores/src/stores/auth/getAccess.action.ts b/packages/react-formio-stores/src/stores/auth/getAccess.action.ts index 1476d75f..42a3ff91 100644 --- a/packages/react-formio-stores/src/stores/auth/getAccess.action.ts +++ b/packages/react-formio-stores/src/stores/auth/getAccess.action.ts @@ -1,10 +1,10 @@ -import type { FormSchema, RoleSchema } from "@tsed/react-formio"; +import type { FormType, RoleType } from "@tsed/react-formio"; import { Formio } from "formiojs"; import { formAccessUser, submissionAccessUser, userForms, userRoles } from "./auth.actions"; import { AUTH } from "./auth.constant"; -function transformSubmissionAccess(forms: Record) { +function transformSubmissionAccess(forms: Record) { return Object.values(forms).reduce( (result, form) => ({ ...result, @@ -20,7 +20,7 @@ function transformSubmissionAccess(forms: Record) { ); } -function transformFormAccess(forms: Record) { +function transformFormAccess(forms: Record) { return Object.values(forms).reduce( (result, form) => ({ ...result, @@ -41,8 +41,8 @@ export async function getAccess(dispatch: any) { try { const result: { - roles: Record; - forms: Record; + roles: Record; + forms: Record; } = await Formio.makeStaticRequest(`${projectUrl}/access`); const submissionAccess = transformSubmissionAccess(result.forms); diff --git a/packages/react-formio-stores/src/stores/form/form.actions.ts b/packages/react-formio-stores/src/stores/form/form.actions.ts index 3386ec3c..e72a062d 100644 --- a/packages/react-formio-stores/src/stores/form/form.actions.ts +++ b/packages/react-formio-stores/src/stores/form/form.actions.ts @@ -1,4 +1,4 @@ -import type { FormSchema } from "@tsed/react-formio"; +import type { FormType } from "@tsed/react-formio"; import { createAction } from "@tsed/redux-utils"; import { Formio } from "formiojs"; import noop from "lodash/noop"; @@ -14,7 +14,7 @@ export const failForm = createAction(); export const resetForm = createAction(); export const sendForm = createAction(); -function shouldGet(form: Partial, id: string) { +function shouldGet(form: Partial, id: string) { return form && form.components && Array.isArray(form.components) && form.components.length && form._id === id; } @@ -47,7 +47,7 @@ export const getForm = }; export const saveForm = - (name: string, form: Partial, done = noop) => + (name: string, form: Partial, done = noop) => async (dispatch: any) => { dispatch(clearFormError(name)); dispatch(sendForm(name, { form })); diff --git a/packages/react-formio-stores/src/stores/form/form.reducers.ts b/packages/react-formio-stores/src/stores/form/form.reducers.ts index bc143e78..a86fcb1f 100644 --- a/packages/react-formio-stores/src/stores/form/form.reducers.ts +++ b/packages/react-formio-stores/src/stores/form/form.reducers.ts @@ -1,11 +1,11 @@ -import type { FormSchema } from "@tsed/react-formio"; +import type { FormType } from "@tsed/react-formio"; import { createReducer, InitialStateCreator } from "@tsed/redux-utils"; import { clearFormError, failForm, receiveForm, requestForm, resetForm, sendForm } from "./form.actions"; export interface FormState { error: null | Error; - data?: Partial; + data?: Partial; isActive: boolean; lastUpdated: number; url: string; diff --git a/packages/react-formio-stores/src/stores/form/form.selectors.ts b/packages/react-formio-stores/src/stores/form/form.selectors.ts index 6e7dd9f1..4e0d0ee9 100644 --- a/packages/react-formio-stores/src/stores/form/form.selectors.ts +++ b/packages/react-formio-stores/src/stores/form/form.selectors.ts @@ -1,6 +1,6 @@ -import type { FormSchema } from "@tsed/react-formio"; +import type { FormType } from "@tsed/react-formio"; import { selectRoot } from "../root"; import { FormState } from "./form.reducers"; -export const selectForm = (name: string, state: any): Partial => selectRoot(name, state).data!; +export const selectForm = (name: string, state: any): Partial => selectRoot(name, state).data!; diff --git a/packages/react-formio-stores/src/stores/forms/forms.actions.ts b/packages/react-formio-stores/src/stores/forms/forms.actions.ts index f10383ec..995eb0f9 100644 --- a/packages/react-formio-stores/src/stores/forms/forms.actions.ts +++ b/packages/react-formio-stores/src/stores/forms/forms.actions.ts @@ -1,4 +1,4 @@ -import type { FormSchema } from "@tsed/react-formio"; +import type { FormType } from "@tsed/react-formio"; import { createAction } from "@tsed/redux-utils"; import { Formio } from "formiojs"; import noop from "lodash/noop"; @@ -10,10 +10,10 @@ export const resetForms = createAction(); export const requestForms = createAction<{ parameters: Partial; }>(); -export const receiveForms = createAction<{ forms: FormSchema[] }>(); +export const receiveForms = createAction<{ forms: FormType[] }>(); export const failForms = createAction(); -export type GetFormsCB = (err: any, forms?: FormSchema[]) => void; +export type GetFormsCB = (err: any, forms?: FormType[]) => void; export const getForms = (name: string, parameters: Partial, done: GetFormsCB = noop) => @@ -24,7 +24,7 @@ export const getForms = const requestParams = mapRequestParams(selectFormsParameters(name, getState())); try { - const result: FormSchema[] = await formio.loadForms({ + const result: FormType[] = await formio.loadForms({ params: requestParams }); dispatch(receiveForms(name, { forms: result })); diff --git a/packages/react-formio-stores/src/stores/forms/forms.reducers.ts b/packages/react-formio-stores/src/stores/forms/forms.reducers.ts index 469632ef..59685d08 100644 --- a/packages/react-formio-stores/src/stores/forms/forms.reducers.ts +++ b/packages/react-formio-stores/src/stores/forms/forms.reducers.ts @@ -1,4 +1,4 @@ -import type { FormSchema } from "@tsed/react-formio"; +import type { FormType } from "@tsed/react-formio"; import { createReducer } from "@tsed/redux-utils"; import { failForms, receiveForms, requestForms, resetForms } from "./forms.actions"; @@ -15,7 +15,7 @@ export interface FormsState { sortBy: any[]; filters: any[]; }; - data: FormSchema[]; + data: FormType[]; } const createInitialState = ({ pageIndex = 0, pageSize = 10, query = {}, select = "", sortBy = [] }: any = {}): FormsState => { diff --git a/packages/react-formio-stores/src/stores/submission/submission.actions.ts b/packages/react-formio-stores/src/stores/submission/submission.actions.ts index 6fd90f5f..97243aa4 100644 --- a/packages/react-formio-stores/src/stores/submission/submission.actions.ts +++ b/packages/react-formio-stores/src/stores/submission/submission.actions.ts @@ -1,4 +1,4 @@ -import { Submission } from "@tsed/react-formio"; +import { SubmissionType } from "@tsed/react-formio"; import { createAction } from "@tsed/redux-utils"; import { Formio } from "formiojs"; import noop from "lodash/noop"; @@ -38,7 +38,7 @@ export const getSubmission = }; export const saveSubmission = - (name: string, formId: string, data: Submission, done = noop) => + (name: string, formId: string, data: SubmissionType, done = noop) => async (dispatch: any) => { dispatch(clearSubmissionError(name)); dispatch(sendSubmission(name, { submission: data, formId })); diff --git a/packages/react-formio-stores/src/stores/submission/submission.reducers.ts b/packages/react-formio-stores/src/stores/submission/submission.reducers.ts index 4551402e..abba6e9f 100644 --- a/packages/react-formio-stores/src/stores/submission/submission.reducers.ts +++ b/packages/react-formio-stores/src/stores/submission/submission.reducers.ts @@ -1,4 +1,4 @@ -import type { Submission } from "@tsed/react-formio"; +import type { SubmissionType } from "@tsed/react-formio"; import { createReducer, InitialStateCreator } from "@tsed/redux-utils"; import { @@ -15,7 +15,7 @@ export interface SubmissionState { id: string; isActive: boolean; lastUpdated: number; - data: Partial; + data: Partial; url: string; error: null | Error; } diff --git a/packages/react-formio-stores/src/stores/submission/submission.selectors.ts b/packages/react-formio-stores/src/stores/submission/submission.selectors.ts index 0758dba7..537c371b 100644 --- a/packages/react-formio-stores/src/stores/submission/submission.selectors.ts +++ b/packages/react-formio-stores/src/stores/submission/submission.selectors.ts @@ -1,6 +1,6 @@ -import type { Submission } from "@tsed/react-formio"; +import type { SubmissionType } from "@tsed/react-formio"; import { selectRoot } from "../root"; import { SubmissionState } from "./submission.reducers"; -export const selectSubmission = (name: string, state: any): Partial => selectRoot(name, state).data; +export const selectSubmission = (name: string, state: any): Partial => selectRoot(name, state).data; diff --git a/packages/react-formio-stores/src/stores/submissions/submissions.reducers.ts b/packages/react-formio-stores/src/stores/submissions/submissions.reducers.ts index 0d838a6a..4a08dab9 100644 --- a/packages/react-formio-stores/src/stores/submissions/submissions.reducers.ts +++ b/packages/react-formio-stores/src/stores/submissions/submissions.reducers.ts @@ -1,4 +1,4 @@ -import type { Submission } from "@tsed/react-formio"; +import type { SubmissionType } from "@tsed/react-formio"; import { createReducer } from "@tsed/redux-utils"; import { failSubmissions, receiveSubmissions, requestSubmissions, resetSubmissions } from "./submissions.actions"; @@ -15,7 +15,7 @@ export interface SubmissionsState { select: any; sortBy: any[]; }; - data: Submission[]; + data: SubmissionType[]; } export function createInitialState({ pageIndex = 0, pageSize = 10, query = {}, select = "", sortBy = [] }: any = {}): SubmissionsState { diff --git a/packages/react-formio/src/components/actions-table/actionsTable.component.tsx b/packages/react-formio/src/components/actions-table/actionsTable.component.tsx index 2193953b..6c50a0eb 100644 --- a/packages/react-formio/src/components/actions-table/actionsTable.component.tsx +++ b/packages/react-formio/src/components/actions-table/actionsTable.component.tsx @@ -2,13 +2,13 @@ import classnames from "classnames"; import noop from "lodash/noop"; import { useState } from "react"; -import { ActionSchema } from "../../interfaces"; +import { ActionType } from "../../interfaces"; import { iconClass } from "../../utils/iconClass"; import { Select } from "../select/select.component"; import { TableProps } from "../table/hooks/useCustomTable.hook"; import { Table } from "../table/table.component"; -export type ActionsTableProps = Omit, "columns"> & { +export type ActionsTableProps = Omit, "columns"> & { onAddAction?: (actionName: string) => void; availableActions?: { label: string; value: string }[]; }; diff --git a/packages/react-formio/src/components/actions-table/actionsTable.stories.tsx b/packages/react-formio/src/components/actions-table/actionsTable.stories.tsx index 7574aaf4..cc544297 100644 --- a/packages/react-formio/src/components/actions-table/actionsTable.stories.tsx +++ b/packages/react-formio/src/components/actions-table/actionsTable.stories.tsx @@ -6,7 +6,7 @@ import data from "./__fixtures__/data.json"; import { ActionsTable } from "./actionsTable.component"; export default { - title: "ReactFormio/ActionsTable", + title: "@tsed/react-formio/ActionsTable", component: ActionsTable, argTypes: { data: { diff --git a/packages/react-formio/src/components/alert/alert.stories.tsx b/packages/react-formio/src/components/alert/alert.stories.tsx index f0fe2bf4..9eaac0ad 100644 --- a/packages/react-formio/src/components/alert/alert.stories.tsx +++ b/packages/react-formio/src/components/alert/alert.stories.tsx @@ -1,7 +1,7 @@ import { Alert } from "./alert.component"; export default { - title: "ReactFormio/Alert", + title: "@tsed/react-formio/Alert", component: Alert, argTypes: {}, parameters: {} diff --git a/packages/react-formio/src/components/card/card.stories.tsx b/packages/react-formio/src/components/card/card.stories.tsx index b4dc8956..b397a43c 100644 --- a/packages/react-formio/src/components/card/card.stories.tsx +++ b/packages/react-formio/src/components/card/card.stories.tsx @@ -1,7 +1,7 @@ import { Card } from "./card.component"; export default { - title: "ReactFormio/Card", + title: "@tsed/react-formio/Card", component: Card, argTypes: {}, parameters: {} diff --git a/packages/react-formio/src/components/form-access/formAccess.component.tsx b/packages/react-formio/src/components/form-access/formAccess.component.tsx index 6f0a8243..f4baa3f4 100644 --- a/packages/react-formio/src/components/form-access/formAccess.component.tsx +++ b/packages/react-formio/src/components/form-access/formAccess.component.tsx @@ -1,22 +1,21 @@ import { PropsWithChildren, useCallback, useEffect, useMemo, useState } from "react"; -import type { FormOptions, FormSchema, Submission } from "../../interfaces"; +import type { FormOptions, FormType, SubmissionType } from "../../interfaces"; import { Card } from "../card/card.component"; import { Form } from "../form/form.component"; -import { ChangedSubmission } from "../form/useForm.hook"; import { - AccessRoles, + AccessRolesType, dataAccessToSubmissions, - FormAccessSchema, + FormAccessType, getFormAccess, shouldUpdate, - SubmissionAccess, + SubmissionAccessType, submissionsToDataAccess, updateSubmissions } from "./formAccess.utils"; export interface FormAccessProps { - form: Partial; + form: Partial; roles: any; onSubmit?: Function; options?: FormOptions; @@ -28,7 +27,7 @@ function useFormAccess({ form: formDefinition, roles, onSubmit, options }: FormA const [submissions, setSubmissions] = useState(() => dataAccessToSubmissions(formDefinition, form)); const onChange = useCallback( - (type: string, submission: Submission) => { + (type: string, submission: SubmissionType) => { updateSubmissions(type, submission, submissions, setSubmissions); }, [submissions] @@ -57,12 +56,12 @@ function useFormAccess({ form: formDefinition, roles, onSubmit, options }: FormA interface NamedFormAccessProps { name: "access" | "submissionAccess"; - form: FormAccessSchema; - submissions: SubmissionAccess; + form: FormAccessType; + submissions: SubmissionAccessType; options: any; onSubmit: any; - onChange(name: "access" | "submissionAccess", submission: Submission): void; + onChange(name: "access" | "submissionAccess", submission: SubmissionType): void; } function NamedFormAccess({ name, form, submissions, options, onChange, onSubmit, children }: PropsWithChildren) { @@ -70,12 +69,12 @@ function NamedFormAccess({ name, form, submissions, options, onChange, onSubmit, return ( <> -
name={name} form={form[name]} submission={submissions[name]} - onChange={({ data, isValid }: ChangedSubmission) => { - isValid && onChange(name, { data }); + onChange={({ data, isValid }) => { + isValid && onChange(name, { data: data as unknown as AccessRolesType }); setIsValid(isValid); }} options={options} diff --git a/packages/react-formio/src/components/form-access/formAccess.schema.ts b/packages/react-formio/src/components/form-access/formAccess.schema.ts index b04844cc..ac3e4923 100644 --- a/packages/react-formio/src/components/form-access/formAccess.schema.ts +++ b/packages/react-formio/src/components/form-access/formAccess.schema.ts @@ -1,8 +1,6 @@ -import { ExtendedComponentSchema } from "formiojs"; +import type { ComponentType, FormType } from "../../interfaces"; -import { FormSchema } from "../../interfaces/FormSchema"; - -export function getRoleComponent({ label, key, description, choices, data }: any): ExtendedComponentSchema { +export function getRoleComponent({ label, key, description, choices, data }: any): ComponentType { return { label, key, @@ -34,7 +32,7 @@ function toDescription(description: string, hr = true): string { return '' + description + " " + (hr ? '
' : ""); } -export function getSubmissionPermissionForm({ choices }: any): FormSchema { +export function getSubmissionPermissionForm({ choices }: any): FormType { return { description: "Elevated permissions allow users to access and modify other user's entities. Assign with caution.", components: [ @@ -107,7 +105,7 @@ export function getSubmissionPermissionForm({ choices }: any): FormSchema { }; } -export function getAccessPermissionForm({ choices }: any): FormSchema { +export function getAccessPermissionForm({ choices }: any): FormType { return { description: "Elevated permissions allow users to access and modify other user's entities. Assign with caution.", components: [ diff --git a/packages/react-formio/src/components/form-access/formAccess.stories.tsx b/packages/react-formio/src/components/form-access/formAccess.stories.tsx index 423fd6d4..c8403a65 100644 --- a/packages/react-formio/src/components/form-access/formAccess.stories.tsx +++ b/packages/react-formio/src/components/form-access/formAccess.stories.tsx @@ -4,7 +4,7 @@ import { expect, fn, userEvent, within } from "@storybook/test"; import { FormAccess } from "./formAccess.component"; export default { - title: "ReactFormio/FormAccess", + title: "@tsed/react-formio/FormAccess", component: FormAccess, argTypes: { onSubmit: { action: "onSubmit" } diff --git a/packages/react-formio/src/components/form-access/formAccess.utils.spec.ts b/packages/react-formio/src/components/form-access/formAccess.utils.spec.ts index 8cd95fbf..581e353c 100644 --- a/packages/react-formio/src/components/form-access/formAccess.utils.spec.ts +++ b/packages/react-formio/src/components/form-access/formAccess.utils.spec.ts @@ -1,5 +1,11 @@ -import { FormSchema } from "../../interfaces"; -import { dataAccessToSubmissions, getFormAccess, SubmissionAccess, submissionsToDataAccess, updateSubmissions } from "./formAccess.utils"; +import { FormType } from "../../interfaces"; +import { + dataAccessToSubmissions, + getFormAccess, + SubmissionAccessType, + submissionsToDataAccess, + updateSubmissions +} from "./formAccess.utils"; const roles: any[] = [ { @@ -13,7 +19,7 @@ const roles: any[] = [ describe("formAccess.utils", () => { describe("dataAccessToSubmissions()", () => { it("should map data access to form submissions", () => { - const data: FormSchema = { + const data: FormType = { _id: "id", components: [], access: [ @@ -60,7 +66,7 @@ describe("formAccess.utils", () => { }); describe("submissionsToDataAccess()", () => { it("should map form submissions to data access", () => { - const submissions: SubmissionAccess = { + const submissions: SubmissionAccessType = { access: { data: { delete_all: [], @@ -85,7 +91,7 @@ describe("formAccess.utils", () => { } }; - const originalForm: FormSchema = { + const originalForm: FormType = { _id: "id", components: [], access: [ @@ -173,7 +179,7 @@ describe("formAccess.utils", () => { describe("updateSubmissions()", () => { it("should update submissions", () => { - const submissions: SubmissionAccess = { + const submissions: SubmissionAccessType = { access: { data: { delete_all: [], @@ -239,7 +245,7 @@ describe("formAccess.utils", () => { }); }); it("should do nothing", () => { - const submissions: SubmissionAccess = { + const submissions: SubmissionAccessType = { access: { data: { delete_all: [], diff --git a/packages/react-formio/src/components/form-access/formAccess.utils.ts b/packages/react-formio/src/components/form-access/formAccess.utils.ts index a5cd696d..b57201aa 100644 --- a/packages/react-formio/src/components/form-access/formAccess.utils.ts +++ b/packages/react-formio/src/components/form-access/formAccess.utils.ts @@ -1,10 +1,9 @@ -import { ExtendedComponentSchema } from "formiojs"; import cloneDeep from "lodash/cloneDeep"; import isEqual from "lodash/isEqual"; import noop from "lodash/noop"; -import { FormSchema, Submission } from "../../interfaces"; -import { RoleSchema } from "../../interfaces/RoleSchema"; +import { ComponentType, FormType, SubmissionType } from "../../interfaces"; +import { RoleType } from "../../interfaces/RoleType"; import { getAccessPermissionForm, getSubmissionPermissionForm } from "./formAccess.schema"; export interface Choice { @@ -17,19 +16,19 @@ export interface Access { type: string; } -export type AccessRoles = Record; +export type AccessRolesType = Record; -export type FormAccessSchema = { - access: FormSchema; - submissionAccess: FormSchema; +export type FormAccessType = { + access: FormType; + submissionAccess: FormType; }; -export type SubmissionAccess = { - access: Submission; - submissionAccess: Submission; +export type SubmissionAccessType = { + access: SubmissionType; + submissionAccess: SubmissionType; }; -function rolesToChoices(roles: RoleSchema[]): Choice[] { +function rolesToChoices(roles: RoleType[]): Choice[] { return Object.values(roles).map((role) => { return { label: role.title || "", @@ -38,7 +37,7 @@ function rolesToChoices(roles: RoleSchema[]): Choice[] { }); } -function accessToHash(keys: (string | undefined)[] | undefined, access: Access[] = []): AccessRoles { +function accessToHash(keys: (string | undefined)[] | undefined, access: Access[] = []): AccessRolesType { const hash = Object.values(access).reduce((o: any, role: any) => { o[role.type] = role.roles; return o; @@ -52,7 +51,7 @@ function accessToHash(keys: (string | undefined)[] | undefined, access: Access[] }, {}); } -function hashToAccess(data: AccessRoles) { +function hashToAccess(data: AccessRolesType) { const accessRoles: any[] = []; Object.entries(data).forEach(([accessType, roles]) => { @@ -68,7 +67,7 @@ function hashToAccess(data: AccessRoles) { return accessRoles; } -export function getFormAccess(roles: RoleSchema[]): FormAccessSchema { +export function getFormAccess(roles: RoleType[]): FormAccessType { const choices = rolesToChoices(roles); const access = getAccessPermissionForm({ choices }); const submissionAccess = getSubmissionPermissionForm({ choices }); @@ -79,8 +78,8 @@ export function getFormAccess(roles: RoleSchema[]): FormAccessSchema { }; } -export function dataAccessToSubmissions(form: Partial, formAccess: FormAccessSchema): SubmissionAccess { - const getKeys = (components: ExtendedComponentSchema[]) => components.map(({ key }) => key); +export function dataAccessToSubmissions(form: Partial, formAccess: FormAccessType): SubmissionAccessType { + const getKeys = (components: ComponentType[]) => components.map(({ key }) => key); return { access: { @@ -92,7 +91,7 @@ export function dataAccessToSubmissions(form: Partial, formAccess: F }; } -export function submissionsToDataAccess(form: Partial, submissions: SubmissionAccess): Partial { +export function submissionsToDataAccess(form: Partial, submissions: SubmissionAccessType): Partial { return { ...cloneDeep(form), access: hashToAccess(submissions.access.data), @@ -100,11 +99,16 @@ export function submissionsToDataAccess(form: Partial, submissions: }; } -export function shouldUpdate(type: string, submission: Submission, submissions: SubmissionAccess) { +export function shouldUpdate(type: string, submission: SubmissionType, submissions: SubmissionAccessType) { return !isEqual(submission.data, (submissions as any)[type].data); } -export function updateSubmissions(type: string, submission: Submission, submissions: SubmissionAccess, cb: Function = noop) { +export function updateSubmissions( + type: string, + submission: SubmissionType, + submissions: SubmissionAccessType, + cb: Function = noop +) { if (shouldUpdate(type, submission, submissions)) { submissions = { ...submissions, diff --git a/packages/react-formio/src/components/form-action/formAction.component.tsx b/packages/react-formio/src/components/form-action/formAction.component.tsx index ad411a52..d5371606 100644 --- a/packages/react-formio/src/components/form-action/formAction.component.tsx +++ b/packages/react-formio/src/components/form-action/formAction.component.tsx @@ -1,10 +1,10 @@ import FormioUtils from "formiojs/utils"; import { PropsWithChildren, ReactElement } from "react"; -import { ActionDefaultsSchema, ActionSchema, FormOptions, Submission } from "../../interfaces"; +import { ActionDefaultsType, ActionType, FormOptions, SubmissionType } from "../../interfaces"; import { Form } from "../form/form.component"; -function mapData(options: any, defaults: ActionDefaultsSchema): any { +function mapData(options: any, defaults: ActionDefaultsType): any { return { ...defaults, ...options @@ -33,9 +33,9 @@ function mapSettingsForm({ action, ...settingsForm }: any): any { } export interface FormActionProps { - actionInfo: Partial; - submission?: Partial; - onSubmit?: (submission: Submission) => void; + actionInfo: Partial; + submission?: Partial; + onSubmit?: (submission: SubmissionType) => void; options: FormOptions; } diff --git a/packages/react-formio/src/components/form-action/formAction.stories.tsx b/packages/react-formio/src/components/form-action/formAction.stories.tsx index f71523eb..65fe1199 100644 --- a/packages/react-formio/src/components/form-action/formAction.stories.tsx +++ b/packages/react-formio/src/components/form-action/formAction.stories.tsx @@ -1,7 +1,7 @@ import { FormAction } from "./formAction.component"; export default { - title: "ReactFormio/FormAction", + title: "@tsed/react-formio/FormAction", component: FormAction, argTypes: { onSubmit: { action: "onSubmit" }, diff --git a/packages/react-formio/src/components/form-builder/formBuilder.stories.tsx b/packages/react-formio/src/components/form-builder/formBuilder.stories.tsx index d6e03727..58caf72e 100644 --- a/packages/react-formio/src/components/form-builder/formBuilder.stories.tsx +++ b/packages/react-formio/src/components/form-builder/formBuilder.stories.tsx @@ -1,7 +1,7 @@ import { FormBuilder } from "../../index"; export default { - title: "ReactFormio/FormBuilder", + title: "@tsed/react-formio/FormBuilder", component: FormBuilder, argTypes: { display: { diff --git a/packages/react-formio/src/components/form-control/formControl.stories.tsx b/packages/react-formio/src/components/form-control/formControl.stories.tsx index 94d45662..31dda9a0 100644 --- a/packages/react-formio/src/components/form-control/formControl.stories.tsx +++ b/packages/react-formio/src/components/form-control/formControl.stories.tsx @@ -2,7 +2,7 @@ import { iconClass } from "../../utils/iconClass"; import { FormControl } from "./formControl.component"; export default { - title: "ReactFormio/FormControl", + title: "@tsed/react-formio/FormControl", component: FormControl, argTypes: { label: { diff --git a/packages/react-formio/src/components/form-edit/formEdit.reducer.ts b/packages/react-formio/src/components/form-edit/formEdit.reducer.ts index 1675daf0..a04a93f3 100644 --- a/packages/react-formio/src/components/form-edit/formEdit.reducer.ts +++ b/packages/react-formio/src/components/form-edit/formEdit.reducer.ts @@ -2,15 +2,15 @@ import camelCase from "lodash/camelCase"; import cloneDeep from "lodash/cloneDeep"; import isEqual from "lodash/isEqual"; -import { FormSchema } from "../../interfaces"; +import { FormType } from "../../interfaces"; -export const hasChanged = (form: Partial, value: Partial): boolean => !isEqual(form, value); +export const hasChanged = (form: Partial, value: Partial): boolean => !isEqual(form, value); export interface FormEditState { - past: Partial[]; - future: Partial[]; - current: Partial; - original: Partial; + past: Partial[]; + future: Partial[]; + current: Partial; + original: Partial; } export function createInitialState(props: any): FormEditState { diff --git a/packages/react-formio/src/components/form-edit/formEdit.stories.tsx b/packages/react-formio/src/components/form-edit/formEdit.stories.tsx index 9911f020..76299300 100644 --- a/packages/react-formio/src/components/form-edit/formEdit.stories.tsx +++ b/packages/react-formio/src/components/form-edit/formEdit.stories.tsx @@ -2,7 +2,7 @@ import { FormEdit } from "./formEdit.component"; import { defaultDisplayChoices } from "./formParameters.component"; export default { - title: "ReactFormio/FormEdit", + title: "@tsed/react-formio/FormEdit", component: FormEdit, argTypes: { form: { diff --git a/packages/react-formio/src/components/form-edit/formParameters.component.tsx b/packages/react-formio/src/components/form-edit/formParameters.component.tsx index 9c340f72..dc07c4e6 100644 --- a/packages/react-formio/src/components/form-edit/formParameters.component.tsx +++ b/packages/react-formio/src/components/form-edit/formParameters.component.tsx @@ -1,6 +1,6 @@ import { ReactElement } from "react"; -import { FormSchema } from "../../interfaces/FormSchema"; +import { FormType } from "../../interfaces/FormType"; import { InputTags } from "../input-tags/inputTags.component"; import { InputText } from "../input-text/inputText.component"; import { Select } from "../select/select.component"; @@ -13,7 +13,7 @@ export const defaultDisplayChoices = [ export interface FormParametersProps { onChange?: (name: string, value: any) => void; - form: Partial; + form: Partial; typeChoices?: { label: string; value: any }[]; displayChoices?: { label: string; value: any }[]; enableTags?: boolean; diff --git a/packages/react-formio/src/components/form-edit/useFormEdit.hook.ts b/packages/react-formio/src/components/form-edit/useFormEdit.hook.ts index fcc774fe..2638fe38 100644 --- a/packages/react-formio/src/components/form-edit/useFormEdit.hook.ts +++ b/packages/react-formio/src/components/form-edit/useFormEdit.hook.ts @@ -1,16 +1,16 @@ import cloneDeep from "lodash/cloneDeep"; import { useEffect, useReducer } from "react"; -import { FormSchema } from "../../interfaces/FormSchema"; +import { FormType } from "../../interfaces/FormType"; import { createInitialState, hasChanged, reducer } from "./formEdit.reducer"; export interface UseFormEditHookProps extends Record { - form?: Partial; + form?: Partial; typeChoices?: { label: string; value: any }[]; displayChoices?: { label: string; value: any }[]; enableTags?: boolean; - onSubmit?: (form: Partial) => void; - onCopy?: (form: Partial) => void; + onSubmit?: (form: Partial) => void; + onCopy?: (form: Partial) => void; } export function useFormEdit(props: UseFormEditHookProps) { @@ -33,7 +33,7 @@ export function useFormEdit(props: UseFormEditHookProps) { } }, [props.form]); - const formChange = (newForm: Partial) => { + const formChange = (newForm: Partial) => { if (hasChanged(current, { ...current, ...newForm })) { dispatchFormAction({ type: "formChange", value: newForm }); } diff --git a/packages/react-formio/src/components/form-settings/formSettings.component.tsx b/packages/react-formio/src/components/form-settings/formSettings.component.tsx index 23fb06ae..487ab416 100644 --- a/packages/react-formio/src/components/form-settings/formSettings.component.tsx +++ b/packages/react-formio/src/components/form-settings/formSettings.component.tsx @@ -2,14 +2,13 @@ import isEqual from "lodash/isEqual"; import noop from "lodash/noop"; import { useEffect, useState } from "react"; -import { FormOptions, FormSchema } from "../../interfaces"; +import type { ChangedSubmission, FormOptions, FormType } from "../../interfaces"; import { Form } from "../form/form.component"; -import { ChangedSubmission } from "../form/useForm.hook"; import { getFormSettingsSchema } from "./formSettings.schema"; -import { FormSettingsSchema, formSettingsToSubmission, submissionToFormSettings } from "./formSettings.utils"; +import { formSettingsToSubmission, FormSettingsType, submissionToFormSettings } from "./formSettings.utils"; export interface FormSettingsProps { - form: Partial; + form: Partial; onSubmit?: Function; options?: FormOptions; } @@ -19,7 +18,7 @@ function useFormSettings({ form: formDefinition, onSubmit = noop, options }: For const [isValid, setIsValid] = useState(true); const [submission, setSubmission] = useState(() => formSettingsToSubmission(formDefinition)); - const onChange = ({ data, isValid }: ChangedSubmission) => { + const onChange = ({ data, isValid }: ChangedSubmission) => { if (isValid) { setSubmission({ data }); } @@ -54,7 +53,7 @@ export function FormSettings(props: FormSettingsProps) { return (
- + form={form} submission={submission} onChange={onChange} options={options} />