From 82d9dcc7aa4c4975a58350ba24a76022f9f7de37 Mon Sep 17 00:00:00 2001 From: Jacques Date: Mon, 20 Sep 2021 16:29:20 +0200 Subject: [PATCH] feat: timeout events for trixta actions and reactions --- package.json | 5 +- .../TrixtaActionComponent.tsx | 5 ++ .../actions/TrixtaActionComponent/types.ts | 13 ++++ .../TrixtaActionInstanceComponent.tsx | 4 +- .../TrixtaReactionComponent.tsx | 3 +- .../TrixtaReactionComponent/types.ts | 13 ++++ .../TrixtaReactionInstanceComponent.tsx | 5 ++ .../TrixtaReactionInstanceComponent/types.ts | 13 ++++ src/React/constants/actions/index.ts | 1 + src/React/constants/reactions/index.ts | 1 + .../index.test.tsx | 1 + .../hooks/use-trixta-action/index.test.tsx | 2 + src/React/hooks/use-trixta-action/types.ts | 4 + .../use-trixta-action/use-trixta-action.ts | 23 +++++- .../hooks/use-trixta-auth/use-trixta-auth.ts | 1 + .../hooks/use-trixta-reaction/index.test.tsx | 2 + src/React/hooks/use-trixta-reaction/types.ts | 6 +- .../use-trixta-reaction.ts | 15 +++- src/React/reducers/trixtaReducer.ts | 4 + .../reduxActions/internal/actions/types.ts | 44 +++++++++++ src/React/reduxActions/internal/index.ts | 1 + .../reduxActions/internal/reactions/types.ts | 44 +++++++++++ src/React/reduxActions/internal/types.ts | 4 + src/React/reduxActions/trixtaReactions.ts | 2 + src/React/reduxActions/types/trixtaActions.ts | 38 +++------- .../reduxActions/types/trixtaReactions.ts | 34 ++------- .../respondToTrixtaReactionEffectSaga.ts | 3 +- src/React/sagas/setupTrixtaSaga.ts | 75 +++++++++++++++++-- src/React/types/actions/index.ts | 9 +++ src/React/types/common/index.ts | 9 +++ src/React/types/reactions/index.ts | 9 +++ 31 files changed, 321 insertions(+), 72 deletions(-) create mode 100644 src/React/reduxActions/internal/actions/types.ts create mode 100644 src/React/reduxActions/internal/reactions/types.ts diff --git a/package.json b/package.json index ca968852..d179a7de 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "types" ], "publishConfig": { - "registry": "https://registry.npmjs.org/" + "registry": "https://registry.npmjs.org/", + "access": "public" }, "repository": { "type": "git", @@ -42,7 +43,7 @@ "link:phoenix-to-redux": "npm link @trixta/phoenix-to-redux", "build": "kcd-scripts build --bundle 'esm,cjs' --no-clean", "prebuild": "rimraf dist types && yarn run lint:fix", - "checkTs": "tsc --noEmit", + "lint:ts": "tsc --noEmit", "lint": "yarn run eslint src", "lint:fix": "yarn run lint --fix", "prettify": "prettier --write", diff --git a/src/React/components/actions/TrixtaActionComponent/TrixtaActionComponent.tsx b/src/React/components/actions/TrixtaActionComponent/TrixtaActionComponent.tsx index 600e46ad..58765b4f 100644 --- a/src/React/components/actions/TrixtaActionComponent/TrixtaActionComponent.tsx +++ b/src/React/components/actions/TrixtaActionComponent/TrixtaActionComponent.tsx @@ -30,6 +30,7 @@ function TrixtaActionComponent({ }: TrixtaActionComponentProps & DispatchProps & ConnectProps & + // eslint-disable-next-line @typescript-eslint/no-explicit-any Record) { trixtaDebugger({ type: TrixtaDebugType.Action, @@ -103,6 +104,10 @@ function mapDispatchToProps( errorEvent: ownProps.errorEvent, responseEvent: ownProps.responseEvent, requestEvent: ownProps.requestEvent, + timeoutEvent: ownProps.setTimeoutEventAsErrorEvent + ? ownProps.errorEvent + : ownProps.timeoutEvent, + timeout: ownProps.timeout, debugMode: ownProps.debugMode, formData, actionOptions: ownProps.actionOptions, diff --git a/src/React/components/actions/TrixtaActionComponent/types.ts b/src/React/components/actions/TrixtaActionComponent/types.ts index 68230e5f..a470947c 100644 --- a/src/React/components/actions/TrixtaActionComponent/types.ts +++ b/src/React/components/actions/TrixtaActionComponent/types.ts @@ -28,6 +28,19 @@ export interface TrixtaActionComponentProps extends TrixtaActionBaseProps { * [see Redux `dispatch` documentation for complete info](https://redux.js.org/api/store#dispatchaction) */ errorEvent?: string; + /** + * Event name / dispatch action type for data to dispatch after Trixta action time out error response + * [see Redux `dispatch` documentation for complete info](https://redux.js.org/api/store#dispatchaction) + */ + timeoutEvent?: string; + /** + * timeout in milliseconds for submitting data to Trixta, default is 15000 + */ + timeout?: number; + /** + * If 'true', will set the timeoutEvent the same as the ErrorEvent + */ + setTimeoutEventAsErrorEvent?: boolean; /** * Options for action in Trixta flow */ diff --git a/src/React/components/actions/TrixtaActionInstanceComponent/TrixtaActionInstanceComponent.tsx b/src/React/components/actions/TrixtaActionInstanceComponent/TrixtaActionInstanceComponent.tsx index 7a4bd3b0..7df927e4 100644 --- a/src/React/components/actions/TrixtaActionInstanceComponent/TrixtaActionInstanceComponent.tsx +++ b/src/React/components/actions/TrixtaActionInstanceComponent/TrixtaActionInstanceComponent.tsx @@ -14,8 +14,10 @@ function TrixtaActionInstanceComponent({ roleName, instance, debugMode = false, + // eslint-disable-next-line @typescript-eslint/no-unused-vars ...props -}: TrixtaActionInstanceComponentProps & ConnectProps & Record) { +}: // eslint-disable-next-line @typescript-eslint/no-explicit-any +TrixtaActionInstanceComponentProps & ConnectProps & Record) { trixtaInstanceDebugger({ type: TrixtaDebugType.Action, debugMode, diff --git a/src/React/components/reactions/TrixtaReactionComponent/TrixtaReactionComponent.tsx b/src/React/components/reactions/TrixtaReactionComponent/TrixtaReactionComponent.tsx index b506908b..b92bbf75 100644 --- a/src/React/components/reactions/TrixtaReactionComponent/TrixtaReactionComponent.tsx +++ b/src/React/components/reactions/TrixtaReactionComponent/TrixtaReactionComponent.tsx @@ -24,7 +24,8 @@ function TrixtaReactionComponent({ debugMode = false, instances, ...rest -}: ConnectProps & TrixtaReactionComponentProps & Record) { +}: // eslint-disable-next-line @typescript-eslint/no-explicit-any +ConnectProps & TrixtaReactionComponentProps & Record) { trixtaDebugger({ type: TrixtaDebugType.Reaction, debugMode, diff --git a/src/React/components/reactions/TrixtaReactionComponent/types.ts b/src/React/components/reactions/TrixtaReactionComponent/types.ts index 5bf37650..1aa37a20 100644 --- a/src/React/components/reactions/TrixtaReactionComponent/types.ts +++ b/src/React/components/reactions/TrixtaReactionComponent/types.ts @@ -16,6 +16,19 @@ export interface TrixtaReactionComponentProps extends TrixtaReactionBaseProps { * [see Redux `dispatch` documentation for complete info](https://redux.js.org/api/store#dispatchaction) */ errorEvent?: string; + /** + * Event name / dispatch action type for data to dispatch after Trixta reaction time out error response + * [see Redux `dispatch` documentation for complete info](https://redux.js.org/api/store#dispatchaction) + */ + timeoutEvent?: string; + /** + * timeout in milliseconds for submitting data to Trixta, default is 15000 + */ + timeout?: number; + /** + * If 'true', will set the timeoutEvent the same as the ErrorEvent + */ + setTimeoutEventAsErrorEvent?: boolean; /** * Enables Trixta console debugging */ diff --git a/src/React/components/reactions/TrixtaReactionInstanceComponent/TrixtaReactionInstanceComponent.tsx b/src/React/components/reactions/TrixtaReactionInstanceComponent/TrixtaReactionInstanceComponent.tsx index ab088503..2675850a 100644 --- a/src/React/components/reactions/TrixtaReactionInstanceComponent/TrixtaReactionInstanceComponent.tsx +++ b/src/React/components/reactions/TrixtaReactionInstanceComponent/TrixtaReactionInstanceComponent.tsx @@ -32,6 +32,7 @@ const TrixtaReactionInstanceComponent = ({ }: ConnectProps & DispatchProps & TrixtaReactionInstanceComponentProps & + // eslint-disable-next-line @typescript-eslint/no-explicit-any Record) => { const response = get(instance, 'response', { success: false, @@ -102,6 +103,10 @@ function mapDispatchToProps( submitTrixtaReactionResponse({ formData, errorEvent: ownProps.errorEvent, + timeoutEvent: ownProps.setTimeoutEventAsErrorEvent + ? ownProps.errorEvent + : ownProps.timeoutEvent, + timeout: ownProps.timeout, requestEvent: ownProps.requestEvent, responseEvent: ownProps.responseEvent, ref: ownProps.instanceRef, diff --git a/src/React/components/reactions/TrixtaReactionInstanceComponent/types.ts b/src/React/components/reactions/TrixtaReactionInstanceComponent/types.ts index aa72692e..503fe040 100644 --- a/src/React/components/reactions/TrixtaReactionInstanceComponent/types.ts +++ b/src/React/components/reactions/TrixtaReactionInstanceComponent/types.ts @@ -15,6 +15,19 @@ export interface TrixtaReactionInstanceComponentProps * Event name / dispatch action type for data to dispatch after Trixta reaction error response */ errorEvent?: string; + /** + * Event name / dispatch action type for data to dispatch after Trixta reaction time out error response + * [see Redux `dispatch` documentation for complete info](https://redux.js.org/api/store#dispatchaction) + */ + timeoutEvent?: string; + /** + * timeout in milliseconds for submitting data to Trixta, default is 15000 + */ + timeout?: number; + /** + * If 'true', will set the timeoutEvent the same as the ErrorEvent + */ + setTimeoutEventAsErrorEvent?: boolean; common: TrixtaCommon; /** * Enables Trixta console debbugging diff --git a/src/React/constants/actions/index.ts b/src/React/constants/actions/index.ts index 687a756d..0be5e794 100644 --- a/src/React/constants/actions/index.ts +++ b/src/React/constants/actions/index.ts @@ -2,6 +2,7 @@ export const CLEAR_TRIXTA_ACTION_RESPONSE = `@trixtateam/trixta-js/CLEAR_TRIXTA_ export const CLEAR_TRIXTA_ACTION_REQUEST_STATUS = `@trixtateam/trixta-js/CLEAR_TRIXTA_ACTION_REQUEST_STATUS`; export const SUBMIT_TRIXTA_ACTION_RESPONSE = `@trixtateam/trixta-js/SUBMIT_TRIXTA_ACTION_RESPONSE`; export const SUBMIT_TRIXTA_ACTION_RESPONSE_FAILURE = `@trixtateam/trixta-js/SUBMIT_TRIXTA_ACTION_RESPONSE_FAILURE`; +export const SUBMIT_TRIXTA_ACTION_TIMEOUT_RESPONSE_FAILURE = `@trixtateam/trixta-js/SUBMIT_TRIXTA_ACTION_TIMEOUT_RESPONSE_FAILURE`; export const SUBMIT_TRIXTA_ACTION_RESPONSE_SUCCESS = `@trixtateam/trixta-js/SUBMIT_TRIXTA_ACTION_RESPONSE_SUCCESS`; export const UPDATE_TRIXTA_ACTION_RESPONSE = `@trixtateam/trixta-js/UPDATE_TRIXTA_ACTION_RESPONSE`; export const UPDATE_TRIXTA_ACTION = `@trixtateam/trixta-js/UPDATE_TRIXTA_ACTION`; diff --git a/src/React/constants/reactions/index.ts b/src/React/constants/reactions/index.ts index 00de527b..6eb359fa 100644 --- a/src/React/constants/reactions/index.ts +++ b/src/React/constants/reactions/index.ts @@ -5,6 +5,7 @@ export const CLEAR_TRIXTA_REACTION_RESPONSE = `@trixtateam/trixta-js/CLEAR_TRIXT export const CLEAR_TRIXTA_REACTION_REQUEST_STATUS = `@trixtateam/trixta-js/CLEAR_TRIXTA_REACTION_REQUEST_STATUS`; export const SUBMIT_TRIXTA_REACTION_RESPONSE = `@trixtateam/trixta-js/SUBMIT_TRIXTA_REACTION_RESPONSE`; export const SUBMIT_TRIXTA_REACTION_RESPONSE_FAILURE = `@trixtateam/trixta-js/SUBMIT_TRIXTA_REACTION_RESPONSE_FAILURE`; +export const SUBMIT_TRIXTA_REACTION_TIMEOUT_RESPONSE_FAILURE = `@trixtateam/trixta-js/SUBMIT_TRIXTA_REACTION_TIMEOUT_RESPONSE_FAILURE`; export const SUBMIT_TRIXTA_REACTION_RESPONSE_SUCCESS = `@trixtateam/trixta-js/SUBMIT_TRIXTA_REACTION_RESPONSE_SUCCESS`; export const TRIXTA_REACTION = '@trixtateam/trixta-js/TRIXTA_REACTION'; diff --git a/src/React/hooks/use-respond-to-reaction-effect/index.test.tsx b/src/React/hooks/use-respond-to-reaction-effect/index.test.tsx index 0b618c62..7d50bbf6 100644 --- a/src/React/hooks/use-respond-to-reaction-effect/index.test.tsx +++ b/src/React/hooks/use-respond-to-reaction-effect/index.test.tsx @@ -65,6 +65,7 @@ describe('useRespondToReactionEffect', () => { const { wrapper, store } = mockStoreProviderWrapper(trixtaState); const roleName = trixtaState.agentDetails[1]; const reactionName = 'new_waitroom_status'; + // eslint-disable-next-line @typescript-eslint/no-explicit-any const actionToDispatch = (payload: any) => ({ type: 'TEST_ACTION', payload, diff --git a/src/React/hooks/use-trixta-action/index.test.tsx b/src/React/hooks/use-trixta-action/index.test.tsx index bea0804e..c1e82fee 100644 --- a/src/React/hooks/use-trixta-action/index.test.tsx +++ b/src/React/hooks/use-trixta-action/index.test.tsx @@ -204,6 +204,7 @@ describe('useTrixtaAction', () => { }; const actionName = 'request_user_info_request'; let responseData = {}; + // eslint-disable-next-line @typescript-eslint/no-explicit-any const onSuccess = (payload: any) => (responseData = payload); const { result } = renderHook( () => @@ -248,6 +249,7 @@ describe('useTrixtaAction', () => { }; const actionName = 'request_user_info_request'; let responseData = {}; + // eslint-disable-next-line @typescript-eslint/no-explicit-any const onError = (error: any) => (responseData = error); const { result } = renderHook( () => diff --git a/src/React/hooks/use-trixta-action/types.ts b/src/React/hooks/use-trixta-action/types.ts index d9e8dac3..6058c66e 100644 --- a/src/React/hooks/use-trixta-action/types.ts +++ b/src/React/hooks/use-trixta-action/types.ts @@ -7,6 +7,10 @@ import { } from '../../types/common'; export interface UseTrixtaActionProps extends TrixtaActionBaseProps { options?: { + /** + * If 'true', will set the timeoutEvent the same as the ErrorEvent + */ + setTimeoutEventAsErrorEvent?: boolean; /** * Enables Trixta console debbugging */ diff --git a/src/React/hooks/use-trixta-action/use-trixta-action.ts b/src/React/hooks/use-trixta-action/use-trixta-action.ts index 57b38f40..1f6692fc 100644 --- a/src/React/hooks/use-trixta-action/use-trixta-action.ts +++ b/src/React/hooks/use-trixta-action/use-trixta-action.ts @@ -1,4 +1,3 @@ -// ! WORK IN PROGRESS import deequal from 'deequal'; import { useCallback, useEffect, useMemo, useRef } from 'react'; import { useDispatch, useSelector } from 'react-redux'; @@ -41,7 +40,11 @@ export const useTrixtaAction = < roleName, actionName, actionParameters, - options = { debugMode: false, autoSubmit: false }, + options = { + debugMode: false, + autoSubmit: false, + setTimeoutEventAsErrorEvent: false, + }, onSuccess, onError, }: UseTrixtaActionProps): UseTrixtaActionHookReturn< @@ -84,6 +87,7 @@ export const useTrixtaAction = < makeSelectTrixtaActionResponseInstancesForRole, [], ); + // eslint-disable-next-line @typescript-eslint/no-explicit-any const selectTrixtaActionRequestStatus: any = useMemo( makeSelectTrixtaActionRequestStatus, [], @@ -127,6 +131,8 @@ export const useTrixtaAction = < responseEvent, requestEvent, errorEvent, + timeoutEvent, + timeout, }: submitTrixtaFunctionParameters) => { if (!hasRoleAccess || !isTrixtaActionReady) return; @@ -137,11 +143,22 @@ export const useTrixtaAction = < requestEvent, responseEvent, errorEvent, + timeoutEvent: options.setTimeoutEventAsErrorEvent + ? errorEvent + : timeoutEvent, + timeout, actionName, }), ); }, - [dispatch, isTrixtaActionReady, roleName, actionName, hasRoleAccess], + [ + hasRoleAccess, + isTrixtaActionReady, + dispatch, + roleName, + options.setTimeoutEventAsErrorEvent, + actionName, + ], ); useEffect(() => { diff --git a/src/React/hooks/use-trixta-auth/use-trixta-auth.ts b/src/React/hooks/use-trixta-auth/use-trixta-auth.ts index 3bddd618..21fce78c 100644 --- a/src/React/hooks/use-trixta-auth/use-trixta-auth.ts +++ b/src/React/hooks/use-trixta-auth/use-trixta-auth.ts @@ -35,6 +35,7 @@ export const useTrixtaAuth = ({ roleAccessSelector(state, { roles: rolesArr }), ); + // eslint-disable-next-line @typescript-eslint/no-explicit-any const phoenixDetails = useSelector((state) => socketPhoenixDetailsSelector(state), ); diff --git a/src/React/hooks/use-trixta-reaction/index.test.tsx b/src/React/hooks/use-trixta-reaction/index.test.tsx index 3642bbcc..40ee3f3f 100644 --- a/src/React/hooks/use-trixta-reaction/index.test.tsx +++ b/src/React/hooks/use-trixta-reaction/index.test.tsx @@ -424,6 +424,7 @@ describe('useTrixtaReaction', () => { }; let responseData = {}; + // eslint-disable-next-line @typescript-eslint/no-explicit-any const onSuccess = (payload: any) => (responseData = payload); const { result } = renderHook( () => @@ -469,6 +470,7 @@ describe('useTrixtaReaction', () => { getReducerKeyName({ name: reactionName, role: roleName }) ].instances.requestForResponse[0].details.ref; let responseData = {}; + // eslint-disable-next-line @typescript-eslint/no-explicit-any const onError = (error: any) => (responseData = error); const { result } = renderHook( () => diff --git a/src/React/hooks/use-trixta-reaction/types.ts b/src/React/hooks/use-trixta-reaction/types.ts index 6037b6cd..fb091492 100644 --- a/src/React/hooks/use-trixta-reaction/types.ts +++ b/src/React/hooks/use-trixta-reaction/types.ts @@ -1,9 +1,9 @@ import { TrixtaReactionBaseProps } from '../../../React/types/reactions'; import { DefaultUnknownType, + submitTrixtaFunctionParameters, TrixtaInstanceResponse, TrixtaReactionInstance, - submitTrixtaFunctionParameters, } from '../../types/common'; export interface UseTrixtaReactionProps extends TrixtaReactionBaseProps { @@ -11,6 +11,10 @@ export interface UseTrixtaReactionProps extends TrixtaReactionBaseProps { * Enables Trixta console debbugging */ debugMode?: boolean; + /** + * If 'true', will set the timeoutEvent the same as the ErrorEvent + */ + setTimeoutEventAsErrorEvent?: boolean; /** * This function will fire any time the response from Trixta successfully returns data and will be passed the data. */ diff --git a/src/React/hooks/use-trixta-reaction/use-trixta-reaction.ts b/src/React/hooks/use-trixta-reaction/use-trixta-reaction.ts index 8613f951..dc6b0599 100644 --- a/src/React/hooks/use-trixta-reaction/use-trixta-reaction.ts +++ b/src/React/hooks/use-trixta-reaction/use-trixta-reaction.ts @@ -47,6 +47,7 @@ export const useTrixtaReaction = < debugMode = false, onSuccess, onError, + setTimeoutEventAsErrorEvent = false, }: UseTrixtaReactionProps): UseTrixtaReactionHookReturn< TInitialData, TResponseType, @@ -77,6 +78,7 @@ export const useTrixtaReaction = < } as TrixtaReactionBaseProps; // eslint-disable-next-line @typescript-eslint/no-explicit-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any const selectIsTrixtaReactionReadyForRole: any = useMemo( makesSelectIsTrixtaReactionReadyForRole, [], @@ -84,10 +86,12 @@ export const useTrixtaReaction = < const isTrixtaReactionReady = useSelector<{ trixta: TrixtaState }, boolean>( (state) => selectIsTrixtaReactionReadyForRole(state, reactionRoleProps), ); + // eslint-disable-next-line @typescript-eslint/no-explicit-any const selectReactionResponses: any = useMemo( makeSelectTrixtaReactionResponseInstancesForRole, [], ); + // eslint-disable-next-line @typescript-eslint/no-explicit-any const selectTrixtaReactionRequestStatus: any = useMemo( makeSelectTrixtaReactionRequestStatus, [], @@ -130,6 +134,8 @@ export const useTrixtaReaction = < data, responseEvent, errorEvent, + timeoutEvent, + timeout, ref, requestEvent, }: submitTrixtaFunctionParameters) => { @@ -140,6 +146,8 @@ export const useTrixtaReaction = < formData: data ?? {}, ref: ref ?? latestInstance?.details.ref, roleName, + timeoutEvent: setTimeoutEventAsErrorEvent ? errorEvent : timeoutEvent, + timeout, responseEvent, requestEvent, errorEvent, @@ -148,12 +156,13 @@ export const useTrixtaReaction = < ); }, [ + hasRoleAccess, + isTrixtaReactionReady, dispatch, + latestInstance?.details.ref, roleName, + setTimeoutEventAsErrorEvent, reactionName, - isTrixtaReactionReady, - hasRoleAccess, - latestInstance, ], ); diff --git a/src/React/reducers/trixtaReducer.ts b/src/React/reducers/trixtaReducer.ts index 128ab138..ad730d75 100644 --- a/src/React/reducers/trixtaReducer.ts +++ b/src/React/reducers/trixtaReducer.ts @@ -22,6 +22,7 @@ import { SUBMIT_TRIXTA_ACTION_RESPONSE, SUBMIT_TRIXTA_ACTION_RESPONSE_FAILURE, SUBMIT_TRIXTA_ACTION_RESPONSE_SUCCESS, + SUBMIT_TRIXTA_ACTION_TIMEOUT_RESPONSE_FAILURE, SUBMIT_TRIXTA_REACTION_RESPONSE, SUBMIT_TRIXTA_REACTION_RESPONSE_FAILURE, SUBMIT_TRIXTA_REACTION_RESPONSE_SUCCESS, @@ -38,6 +39,7 @@ import { TrixtaRoleParameter, } from '../types'; import { SIGN_OUT_TRIXTA } from './../constants/index'; +import { SUBMIT_TRIXTA_REACTION_TIMEOUT_RESPONSE_FAILURE } from './../constants/reactions/index'; import { TrixtaReducerActions } from './../reduxActions/types'; import { TrixtaState } from './../types'; @@ -137,6 +139,7 @@ export const trixtaReducer = ( } break; case SUBMIT_TRIXTA_REACTION_RESPONSE_FAILURE: + case SUBMIT_TRIXTA_REACTION_TIMEOUT_RESPONSE_FAILURE: { const reactionName = action.additionalData.reactionName; const roleName = action.additionalData.roleName; @@ -403,6 +406,7 @@ export const trixtaReducer = ( } break; case SUBMIT_TRIXTA_ACTION_RESPONSE_FAILURE: + case SUBMIT_TRIXTA_ACTION_TIMEOUT_RESPONSE_FAILURE: { const actionName = action.additionalData.actionName; const roleName = action.additionalData.roleName; diff --git a/src/React/reduxActions/internal/actions/types.ts b/src/React/reduxActions/internal/actions/types.ts new file mode 100644 index 00000000..a585c0be --- /dev/null +++ b/src/React/reduxActions/internal/actions/types.ts @@ -0,0 +1,44 @@ +import { + SUBMIT_TRIXTA_ACTION_RESPONSE_FAILURE, + SUBMIT_TRIXTA_ACTION_RESPONSE_SUCCESS, + SUBMIT_TRIXTA_ACTION_TIMEOUT_RESPONSE_FAILURE, +} from '../../../constants'; + +export type SubmitTrixtaActionResponseSuccessAction = { + type: typeof SUBMIT_TRIXTA_ACTION_RESPONSE_SUCCESS; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + data: any; + additionalData: { + roleName: string; + actionName: string; + clearResponse?: boolean; + responseEvent?: string; + errorEvent?: string; + }; +}; + +export type SubmitTrixtaActionResponseFailureAction = { + type: typeof SUBMIT_TRIXTA_ACTION_RESPONSE_FAILURE; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + error: any; + additionalData: { + roleName: string; + actionName: string; + clearResponse?: boolean; + responseEvent?: string; + errorEvent?: string; + }; +}; + +export type SubmitTrixtaActionResponseTimeoutFailureAction = { + type: typeof SUBMIT_TRIXTA_ACTION_TIMEOUT_RESPONSE_FAILURE; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + error: any; + additionalData: { + roleName: string; + actionName: string; + clearResponse?: boolean; + responseEvent?: string; + timeoutEvent?: string; + }; +}; diff --git a/src/React/reduxActions/internal/index.ts b/src/React/reduxActions/internal/index.ts index 0da31460..45e45d4c 100644 --- a/src/React/reduxActions/internal/index.ts +++ b/src/React/reduxActions/internal/index.ts @@ -29,6 +29,7 @@ import { JoinTrixtaRoleAction, UpdateTrixtaErrorAction } from './types'; export function updateTrixtaError({ error, }: { + // eslint-disable-next-line @typescript-eslint/no-explicit-any error: any; }): UpdateTrixtaErrorAction { return { diff --git a/src/React/reduxActions/internal/reactions/types.ts b/src/React/reduxActions/internal/reactions/types.ts new file mode 100644 index 00000000..858a373f --- /dev/null +++ b/src/React/reduxActions/internal/reactions/types.ts @@ -0,0 +1,44 @@ +import { + SUBMIT_TRIXTA_REACTION_RESPONSE_FAILURE, + SUBMIT_TRIXTA_REACTION_RESPONSE_SUCCESS, + SUBMIT_TRIXTA_REACTION_TIMEOUT_RESPONSE_FAILURE, +} from '../../../constants'; + +export type SubmitTrixtaReactionResponseFailureAction = { + type: typeof SUBMIT_TRIXTA_REACTION_RESPONSE_FAILURE; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + error: any; + additionalData: { + ref?: string; + roleName: string; + reactionName: string; + responseEvent?: string; + errorEvent?: string; + }; +}; + +export type SubmitTrixtaReactionResponseTimeoutFailureAction = { + type: typeof SUBMIT_TRIXTA_REACTION_TIMEOUT_RESPONSE_FAILURE; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + error: any; + additionalData: { + ref?: string; + roleName: string; + reactionName: string; + responseEvent?: string; + timeoutEvent?: string; + }; +}; + +export type SubmitTrixtaReactionResponseSuccessAction = { + type: typeof SUBMIT_TRIXTA_REACTION_RESPONSE_SUCCESS; + additionalData: { + ref?: string; + roleName: string; + reactionName: string; + responseEvent?: string; + errorEvent?: string; + }; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + data: any; +}; diff --git a/src/React/reduxActions/internal/types.ts b/src/React/reduxActions/internal/types.ts index 4ec203ac..a3c23ddc 100644 --- a/src/React/reduxActions/internal/types.ts +++ b/src/React/reduxActions/internal/types.ts @@ -9,5 +9,9 @@ export type JoinTrixtaRoleAction = { export type UpdateTrixtaErrorAction = { type: typeof UPDATE_TRIXTA_ERROR; + // eslint-disable-next-line @typescript-eslint/no-explicit-any error: any; }; + +export * from './actions/types'; +export * from './reactions/types'; diff --git a/src/React/reduxActions/trixtaReactions.ts b/src/React/reduxActions/trixtaReactions.ts index 461e0598..be105b32 100644 --- a/src/React/reduxActions/trixtaReactions.ts +++ b/src/React/reduxActions/trixtaReactions.ts @@ -29,6 +29,7 @@ export function submitTrixtaReactionResponse({ responseEvent = undefined, requestEvent = undefined, errorEvent = undefined, + ...rest }: SubmitTrixtaReactionResponse): SubmitTrixtaReactionResponseAction< TFormData > { @@ -42,6 +43,7 @@ export function submitTrixtaReactionResponse({ errorEvent, roleName, reactionName, + ...rest, }, }; } diff --git a/src/React/reduxActions/types/trixtaActions.ts b/src/React/reduxActions/types/trixtaActions.ts index 9b6134bc..9198cb0b 100644 --- a/src/React/reduxActions/types/trixtaActions.ts +++ b/src/React/reduxActions/types/trixtaActions.ts @@ -2,8 +2,6 @@ import { CLEAR_TRIXTA_ACTION_REQUEST_STATUS, CLEAR_TRIXTA_ACTION_RESPONSE, SUBMIT_TRIXTA_ACTION_RESPONSE, - SUBMIT_TRIXTA_ACTION_RESPONSE_FAILURE, - SUBMIT_TRIXTA_ACTION_RESPONSE_SUCCESS, UPDATE_TRIXTA_ACTION, UPDATE_TRIXTA_ACTION_RESPONSE, } from '../../constants/actions/index'; @@ -13,6 +11,11 @@ import { TrixtaActionResponseDetails, } from '../../types/actions'; import { DefaultUnknownType } from '../../types/common'; +import { + SubmitTrixtaActionResponseFailureAction, + SubmitTrixtaActionResponseSuccessAction, + SubmitTrixtaActionResponseTimeoutFailureAction, +} from '../internal/actions/types'; export type UpdateTrixtaActionDetailsAction = { type: typeof UPDATE_TRIXTA_ACTION; @@ -62,38 +65,17 @@ export type SubmitTrixtaActionResponseAction = { requestEvent?: string; responseEvent?: string; errorEvent?: string; - }; -}; - -export type SubmitTrixtaActionResponsSuccesseAction = { - type: typeof SUBMIT_TRIXTA_ACTION_RESPONSE_SUCCESS; - data: any; - additionalData: { - roleName: string; - actionName: string; - clearResponse?: boolean; - responseEvent?: string; - errorEvent?: string; - }; -}; - -export type SubmitTrixtaActionResponsFailureAction = { - type: typeof SUBMIT_TRIXTA_ACTION_RESPONSE_FAILURE; - error: any; - additionalData: { - roleName: string; - actionName: string; - clearResponse?: boolean; - responseEvent?: string; - errorEvent?: string; + timeoutEvent?: string; + timeout?: number; }; }; export type TrixtaActionReducerActions = | UpdateTrixtaActionResponseAction | ClearTrixtaActionRequestStatusAction - | SubmitTrixtaActionResponsSuccesseAction - | SubmitTrixtaActionResponsFailureAction + | SubmitTrixtaActionResponseSuccessAction + | SubmitTrixtaActionResponseTimeoutFailureAction + | SubmitTrixtaActionResponseFailureAction | UpdateTrixtaActionDetailsAction | ClearTrixtaActionResponseAction | SubmitTrixtaActionResponseAction; diff --git a/src/React/reduxActions/types/trixtaReactions.ts b/src/React/reduxActions/types/trixtaReactions.ts index 640df011..2bd03ea2 100644 --- a/src/React/reduxActions/types/trixtaReactions.ts +++ b/src/React/reduxActions/types/trixtaReactions.ts @@ -1,9 +1,12 @@ +import { + SubmitTrixtaReactionResponseFailureAction, + SubmitTrixtaReactionResponseSuccessAction, + SubmitTrixtaReactionResponseTimeoutFailureAction, +} from '../internal/reactions/types'; import { CLEAR_TRIXTA_REACTION_REQUEST_STATUS, CLEAR_TRIXTA_REACTION_RESPONSE, SUBMIT_TRIXTA_REACTION_RESPONSE, - SUBMIT_TRIXTA_REACTION_RESPONSE_FAILURE, - SUBMIT_TRIXTA_REACTION_RESPONSE_SUCCESS, TRIXTA_REACTION_RESPONSE, UPDATE_TRIXTA_REACTION, UPDATE_TRIXTA_REACTION_RESPONSE, @@ -78,37 +81,16 @@ export type SubmitTrixtaReactionResponseAction< responseEvent?: string; requestEvent?: string; errorEvent?: string; + timeoutEvent?: string; + timeout?: number; roleName: string; reactionName: string; }; }; -export type SubmitTrixtaReactionResponseFailureAction = { - type: typeof SUBMIT_TRIXTA_REACTION_RESPONSE_FAILURE; - error: any; - additionalData: { - ref?: string; - roleName: string; - reactionName: string; - responseEvent?: string; - errorEvent?: string; - }; -}; - -export type SubmitTrixtaReactionResponseSuccessAction = { - type: typeof SUBMIT_TRIXTA_REACTION_RESPONSE_SUCCESS; - additionalData: { - ref?: string; - roleName: string; - reactionName: string; - responseEvent?: string; - errorEvent?: string; - }; - data: any; -}; - export type TrixtaReactionReducerActions = | SubmitTrixtaReactionResponseFailureAction + | SubmitTrixtaReactionResponseTimeoutFailureAction | ClearTrixtaReactionRequestStatusAction | SubmitTrixtaReactionResponseSuccessAction | UpdateTrixtaReactionResponseAction diff --git a/src/React/sagas/respondToTrixtaReactionEffectSaga.ts b/src/React/sagas/respondToTrixtaReactionEffectSaga.ts index ab08a157..8c89ea12 100644 --- a/src/React/sagas/respondToTrixtaReactionEffectSaga.ts +++ b/src/React/sagas/respondToTrixtaReactionEffectSaga.ts @@ -27,6 +27,7 @@ export function* respondToTrixtaReactionEffectSaga({ }): Generator< TakeEffect | PutEffect, void, + // eslint-disable-next-line @typescript-eslint/no-explicit-any EmitTrixtaReactionResponseListenerEventAction > { while (true) { @@ -34,7 +35,7 @@ export function* respondToTrixtaReactionEffectSaga({ roleName, reactionName, }); - + // eslint-disable-next-line @typescript-eslint/no-explicit-any const response: EmitTrixtaReactionResponseListenerEventAction = yield take( actionType, ); diff --git a/src/React/sagas/setupTrixtaSaga.ts b/src/React/sagas/setupTrixtaSaga.ts index f8353fdb..5190f7fb 100644 --- a/src/React/sagas/setupTrixtaSaga.ts +++ b/src/React/sagas/setupTrixtaSaga.ts @@ -27,6 +27,7 @@ import { SUBMIT_TRIXTA_REACTION_RESPONSE, SUBMIT_TRIXTA_REACTION_RESPONSE_FAILURE, SUBMIT_TRIXTA_REACTION_RESPONSE_SUCCESS, + SUBMIT_TRIXTA_REACTION_TIMEOUT_RESPONSE_FAILURE, trixtaActionLoadingStatus, trixtaReactionLoadingStatus, TRIXTA_REACTION_RESPONSE, @@ -39,11 +40,7 @@ import { removeTrixtaRole, RemoveTrixtaRoleAction, SubmitTrixtaActionResponseAction, - SubmitTrixtaActionResponsFailureAction, - SubmitTrixtaActionResponsSuccesseAction, SubmitTrixtaReactionResponseAction, - SubmitTrixtaReactionResponseFailureAction, - SubmitTrixtaReactionResponseSuccessAction, UpdateTrixtaActionDetailsAction, updateTrixtaError, UpdateTrixtaReactionDetailsAction, @@ -56,6 +53,14 @@ import { updateTrixtaReaction, updateTrixtaReactionResponse, } from '../reduxActions/internal'; +import { + SubmitTrixtaActionResponseFailureAction, + SubmitTrixtaActionResponseSuccessAction, + SubmitTrixtaActionResponseTimeoutFailureAction, + SubmitTrixtaReactionResponseFailureAction, + SubmitTrixtaReactionResponseSuccessAction, + SubmitTrixtaReactionResponseTimeoutFailureAction, +} from '../reduxActions/internal/types'; import { makeSelectTrixtaAgentDetails } from '../selectors/common'; import { TrixtaActionDetails, @@ -65,6 +70,7 @@ import { TrixtaRoleParameter, TrixtaState, } from '../types'; +import { SUBMIT_TRIXTA_ACTION_TIMEOUT_RESPONSE_FAILURE } from './../constants/actions/index'; /** * Removes the trixta role and related actions and reactions from the trixta reducer @@ -241,6 +247,8 @@ function* submitActionResponseSaga({ const roleName = payload.roleName; const responseEvent = payload.responseEvent; const errorEvent = payload.errorEvent; + const timeoutEvent = payload.timeoutEvent; + const timeout = payload.timeout; const requestEvent = payload.requestEvent; const clearResponse = payload.clearResponse; const actionName = payload.actionName; @@ -268,10 +276,14 @@ function* submitActionResponseSaga({ roleName, actionName, clearResponse, + timeout, + timeoutEvent, responseEvent, errorEvent, }, dispatchChannelError: true, + channelTimeOutEvent: SUBMIT_TRIXTA_ACTION_TIMEOUT_RESPONSE_FAILURE, + channelPushTimeOut: timeout, channelErrorResponseEvent: SUBMIT_TRIXTA_ACTION_RESPONSE_FAILURE, channelResponseEvent: SUBMIT_TRIXTA_ACTION_RESPONSE_SUCCESS, loadingStatusKey: trixtaActionLoadingStatus({ roleName, actionName }), @@ -293,7 +305,7 @@ function* submitActionResponseSaga({ function* submitActionResponseSuccess({ additionalData, data, -}: SubmitTrixtaActionResponsSuccesseAction) { +}: SubmitTrixtaActionResponseSuccessAction) { const responseEvent = additionalData.responseEvent; if (responseEvent) { yield put({ type: responseEvent, payload: data }); @@ -309,7 +321,7 @@ function* submitActionResponseSuccess({ function* submitActionResponseFailure({ error, additionalData, -}: SubmitTrixtaActionResponsFailureAction) { +}: SubmitTrixtaActionResponseFailureAction) { const errorEvent = additionalData && additionalData.errorEvent ? additionalData.errorEvent @@ -319,6 +331,25 @@ function* submitActionResponseFailure({ } } +/** + * Failure response due to timeout after submitting the action for the roleName + * @param {Object} params + * @param {Object} params.error + * @param {Object} params.additionalData - additionalData + */ +function* submitActionResponseTimoutFailure({ + error, + additionalData, +}: SubmitTrixtaActionResponseTimeoutFailureAction) { + const timeoutEvent = + additionalData && additionalData.timeoutEvent + ? additionalData.timeoutEvent + : undefined; + if (timeoutEvent) { + yield put({ type: timeoutEvent, error }); + } +} + /** * Checks the reaction response from phoenix-to-redux and updates the reactions[roleName][reactionName] reducer * accordingly. If you need to update data somewhere in the reducer based on a reaction, should @@ -434,6 +465,8 @@ function* submitResponseForReactionSaga({ const roleName = payload.roleName; const responseEvent = payload.responseEvent; const errorEvent = payload.errorEvent; + const timeoutEvent = payload.timeoutEvent; + const timeout = payload.timeout; const requestEvent = payload.requestEvent; const reactionName = payload.reactionName; const formData = payload.formData; @@ -456,9 +489,12 @@ function* submitResponseForReactionSaga({ reactionName, responseEvent, errorEvent, + timeoutEvent, ref, }, dispatchChannelError: true, + channelPushTimeOut: timeout, + channelTimeOutEvent: SUBMIT_TRIXTA_REACTION_TIMEOUT_RESPONSE_FAILURE, channelErrorResponseEvent: SUBMIT_TRIXTA_REACTION_RESPONSE_FAILURE, channelResponseEvent: SUBMIT_TRIXTA_REACTION_RESPONSE_SUCCESS, loadingStatusKey: trixtaReactionLoadingStatus({ @@ -492,6 +528,25 @@ function* submitReactionResponseFailure({ } } +/** + * Failure response due to timeout after responding to reaction for the roleName + * @param {Object} params + * @param {Object} params.error + * @param {Object} params.additionalData - additionalData + */ +function* submitReactionResponseTimeoutFailure({ + error, + additionalData, +}: SubmitTrixtaReactionResponseTimeoutFailureAction) { + const timeoutEvent = + additionalData && additionalData.timeoutEvent + ? additionalData.timeoutEvent + : undefined; + if (timeoutEvent) { + yield put({ type: timeoutEvent, error }); + } +} + /** * Success response after responding to reaction for the roleName * @param {Object} params @@ -653,6 +708,10 @@ export function* setupTrixtaSaga(): Generator { SUBMIT_TRIXTA_REACTION_RESPONSE_FAILURE, submitReactionResponseFailure, ), + takeEvery( + SUBMIT_TRIXTA_REACTION_TIMEOUT_RESPONSE_FAILURE, + submitReactionResponseTimeoutFailure, + ), takeEvery( SUBMIT_TRIXTA_REACTION_RESPONSE_SUCCESS, submitReactionResponseSuccess, @@ -661,5 +720,9 @@ export function* setupTrixtaSaga(): Generator { SUBMIT_TRIXTA_ACTION_RESPONSE_FAILURE, submitActionResponseFailure, ), + takeEvery( + SUBMIT_TRIXTA_ACTION_TIMEOUT_RESPONSE_FAILURE, + submitActionResponseTimoutFailure, + ), ]); } diff --git a/src/React/types/actions/index.ts b/src/React/types/actions/index.ts index a03de496..b652ec7c 100644 --- a/src/React/types/actions/index.ts +++ b/src/React/types/actions/index.ts @@ -95,6 +95,15 @@ export interface SubmitTrixtaActionResponse { * [see Redux `dispatch` documentation for complete info](https://redux.js.org/api/store#dispatchaction) */ errorEvent?: string; + /** + * Event name / dispatch action type for data to dispatch after Trixta action time out error response + * [see Redux `dispatch` documentation for complete info](https://redux.js.org/api/store#dispatchaction) + */ + timeoutEvent?: string; + /** + * timeout in milliseconds for submitting data to Trixta, default is 15000 + */ + timeout?: number; } export interface TrixtaActionBaseProps extends TrixtaBaseRoleProps { diff --git a/src/React/types/common/index.ts b/src/React/types/common/index.ts index 2e33a023..03b58fd0 100644 --- a/src/React/types/common/index.ts +++ b/src/React/types/common/index.ts @@ -52,6 +52,15 @@ export interface submitTrixtaFunctionParameters { * Event name / dispatch action type for data to dispatch after Trixta Reaction / Action error response */ errorEvent?: string; + /** + * Event name / dispatch action type for data to dispatch after Trixta action time out error response + * [see Redux `dispatch` documentation for complete info](https://redux.js.org/api/store#dispatchaction) + */ + timeoutEvent?: string; + /** + * timeout in milliseconds for submitting data to Trixta, default is 15000 + */ + timeout?: number; } export interface LastActionSubmit { diff --git a/src/React/types/reactions/index.ts b/src/React/types/reactions/index.ts index c965a9bb..3a84e534 100644 --- a/src/React/types/reactions/index.ts +++ b/src/React/types/reactions/index.ts @@ -85,6 +85,15 @@ export interface SubmitTrixtaReactionResponse { * [see Redux `dispatch` documentation for complete info](https://redux.js.org/api/store#dispatchaction) */ errorEvent?: string; + /** + * Event name / dispatch action type for data to dispatch after Trixta reaction time out error response + * [see Redux `dispatch` documentation for complete info](https://redux.js.org/api/store#dispatchaction) + */ + timeoutEvent?: string; + /** + * timeout in milliseconds for submitting data to Trixta, default is 15000 + */ + timeout?: number; } export interface TrixtaReaction {