Skip to content

Commit 7ee7582

Browse files
chesterkmralonp99
andauthored
feat: implemented redirects using context.config (#2755)
* feat: implemented redirects using context.config * fix(vscode): submodule search issue * chore(docs): webhooks schema --------- Co-authored-by: Alon Peretz <[email protected]>
1 parent c7f9527 commit 7ee7582

File tree

50 files changed

+508
-151
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+508
-151
lines changed

apps/backoffice-v2/CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
# @ballerine/backoffice-v2
22

3+
## 0.7.54
4+
5+
### Patch Changes
6+
7+
- bump
8+
- Updated dependencies
9+
- @ballerine/react-pdf-toolkit@1.2.37
10+
- @ballerine/workflow-browser-sdk@0.6.51
11+
- @ballerine/workflow-node-sdk@0.6.51
12+
- @ballerine/blocks@0.2.23
13+
- @ballerine/common@0.9.39
14+
- @ballerine/ui@0.5.37
15+
16+
## 0.7.53
17+
18+
### Patch Changes
19+
20+
- bump
21+
- Updated dependencies
22+
- @ballerine/common@0.9.38
23+
- @ballerine/blocks@0.2.22
24+
- @ballerine/react-pdf-toolkit@1.2.36
25+
- @ballerine/ui@0.5.36
26+
- @ballerine/workflow-browser-sdk@0.6.50
27+
- @ballerine/workflow-node-sdk@0.6.50
28+
329
## 0.7.52
430

531
### Patch Changes

apps/backoffice-v2/package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ballerine/backoffice-v2",
3-
"version": "0.7.52",
3+
"version": "0.7.54",
44
"description": "Ballerine - Backoffice",
55
"homepage": "https://github.com/ballerine-io/ballerine",
66
"repository": {
@@ -50,12 +50,12 @@
5050
"preview": "vite preview"
5151
},
5252
"dependencies": {
53-
"@ballerine/blocks": "0.2.21",
54-
"@ballerine/common": "0.9.37",
55-
"@ballerine/react-pdf-toolkit": "^1.2.35",
56-
"@ballerine/ui": "^0.5.35",
57-
"@ballerine/workflow-browser-sdk": "0.6.49",
58-
"@ballerine/workflow-node-sdk": "0.6.49",
53+
"@ballerine/blocks": "0.2.23",
54+
"@ballerine/common": "0.9.39",
55+
"@ballerine/react-pdf-toolkit": "^1.2.37",
56+
"@ballerine/ui": "^0.5.37",
57+
"@ballerine/workflow-browser-sdk": "0.6.51",
58+
"@ballerine/workflow-node-sdk": "0.6.51",
5959
"@botpress/webchat": "^2.1.10",
6060
"@botpress/webchat-generator": "^0.2.9",
6161
"@fontsource/inter": "^4.5.15",
@@ -126,8 +126,8 @@
126126
"zod": "^3.22.3"
127127
},
128128
"devDependencies": {
129-
"@ballerine/config": "^1.1.19",
130-
"@ballerine/eslint-config-react": "^2.0.19",
129+
"@ballerine/config": "^1.1.21",
130+
"@ballerine/eslint-config-react": "^2.0.21",
131131
"@cspell/cspell-types": "^6.31.1",
132132
"@faker-js/faker": "^7.6.0",
133133
"@playwright/test": "^1.32.1",

apps/kyb-app/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# kyb-app
22

3+
## 0.3.64
4+
5+
### Patch Changes
6+
7+
- bump
8+
- Updated dependencies
9+
- @ballerine/workflow-browser-sdk@0.6.51
10+
- @ballerine/blocks@0.2.23
11+
- @ballerine/common@0.9.39
12+
- @ballerine/ui@0.5.37
13+
314
## 0.3.63
415

516
### Patch Changes

apps/kyb-app/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@ballerine/kyb-app",
33
"private": true,
4-
"version": "0.3.63",
4+
"version": "0.3.64",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",
@@ -14,10 +14,10 @@
1414
"test:dev": "vitest"
1515
},
1616
"dependencies": {
17-
"@ballerine/blocks": "0.2.21",
18-
"@ballerine/common": "^0.9.37",
19-
"@ballerine/ui": "0.5.36",
20-
"@ballerine/workflow-browser-sdk": "0.6.49",
17+
"@ballerine/blocks": "0.2.23",
18+
"@ballerine/common": "^0.9.39",
19+
"@ballerine/ui": "0.5.37",
20+
"@ballerine/workflow-browser-sdk": "0.6.51",
2121
"@lukemorales/query-key-factory": "^1.0.3",
2222
"@radix-ui/react-icons": "^1.3.0",
2323
"@rjsf/core": "^5.9.0",
@@ -62,8 +62,8 @@
6262
"zod": "^3.21.4"
6363
},
6464
"devDependencies": {
65-
"@ballerine/config": "^1.1.19",
66-
"@ballerine/eslint-config-react": "^2.0.19",
65+
"@ballerine/config": "^1.1.21",
66+
"@ballerine/eslint-config-react": "^2.0.21",
6767
"@jest/globals": "^29.7.0",
6868
"@sentry/vite-plugin": "^2.9.0",
6969
"@testing-library/jest-dom": "^6.1.4",

apps/kyb-app/src/components/organisms/DynamicUI/StateManager/StateManager.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const StateManager = ({
1515
children,
1616
workflowId,
1717
initialContext,
18+
config,
1819
}: StateManagerProps) => {
1920
const machine = useMemo(() => {
2021
const initialMachineState = {
@@ -31,6 +32,7 @@ export const StateManager = ({
3132
);
3233

3334
machine.overrideContext(initialMachineState);
35+
3436
return machine;
3537
}, []);
3638

@@ -60,13 +62,16 @@ export const StateManager = ({
6062
},
6163
state,
6264
payload: contextPayload,
65+
config,
6366
isPluginLoading: isPluginLoading,
6467
};
68+
6569
return ctx;
6670
}, [
6771
state,
6872
contextPayload,
6973
isPluginLoading,
74+
config,
7075
getState,
7176
sendEvent,
7277
invokePlugin,

apps/kyb-app/src/components/organisms/DynamicUI/StateManager/types.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { StateMachineAPI } from '@/components/organisms/DynamicUI/StateManager/hooks/useMachineLogic';
2-
import { CollectionFlowContext } from '@/domains/collection-flow/types/flow-context.types';
2+
import {
3+
CollectionFlowConfig,
4+
CollectionFlowContext,
5+
} from '@/domains/collection-flow/types/flow-context.types';
36
import { AnyChildren, AnyObject } from '@ballerine/ui';
47
import { MachineConfig } from 'xstate';
58

@@ -9,6 +12,7 @@ export interface StateManagerContext {
912
stateApi: StateMachineAPI;
1013
state: string;
1114
payload: AnyObject;
15+
config?: CollectionFlowConfig;
1216
isPluginLoading: boolean;
1317
}
1418

@@ -21,4 +25,5 @@ export interface StateManagerProps {
2125
extensions: AnyObject;
2226
children: AnyChildren | StateManagerChildCallback;
2327
initialContext: CollectionFlowContext | null;
28+
config?: CollectionFlowConfig;
2429
}

apps/kyb-app/src/domains/collection-flow/collection-flow.api.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ import {
77
TUser,
88
UISchema,
99
} from '@/domains/collection-flow/types';
10-
import { CollectionFlowContext } from '@/domains/collection-flow/types/flow-context.types';
10+
import {
11+
CollectionFlowConfig,
12+
CollectionFlowContext,
13+
CollectionFlowContextData,
14+
} from '@/domains/collection-flow/types/flow-context.types';
1115
import posthog from 'posthog-js';
1216

1317
export const fetchUser = async (): Promise<TUser> => {
@@ -64,8 +68,12 @@ export const fetchCustomer = async (): Promise<TCustomer> => {
6468
return await request.get('collection-flow/customer').json<TCustomer>();
6569
};
6670

67-
export const fetchFlowContext = async (): Promise<CollectionFlowContext> => {
71+
export const fetchFlowContext = async (): Promise<CollectionFlowContextData> => {
6872
const result = await request.get('collection-flow/context');
73+
const resultJson = await result.json<{
74+
context: CollectionFlowContext;
75+
config: CollectionFlowConfig;
76+
}>();
6977

70-
return (await result.json<{ context: CollectionFlowContext }>()).context || {};
78+
return resultJson;
7179
};

apps/kyb-app/src/domains/collection-flow/types/flow-context.types.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { UIOptions } from '@/domains/collection-flow/types';
2+
13
export interface FlowConfig {
24
apiUrl: string;
35
tokenId: string;
@@ -9,3 +11,11 @@ export interface FlowConfig {
911
export type CollectionFlowContext = Record<string, unknown> & {
1012
flowConfig?: FlowConfig;
1113
};
14+
15+
export interface CollectionFlowConfig {
16+
uiOptions?: UIOptions;
17+
}
18+
export interface CollectionFlowContextData {
19+
context: CollectionFlowContext;
20+
config: CollectionFlowConfig;
21+
}
Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
1+
import { useStateManagerContext } from '@/components/organisms/DynamicUI/StateManager/components/StateProvider';
2+
import { UIOptions } from '@/domains/collection-flow';
13
import { useLanguage } from '@/hooks/useLanguage';
24
import { useUISchemasQuery } from '@/hooks/useUISchemasQuery';
3-
import { useEffect } from 'react';
5+
import { useEffect, useMemo } from 'react';
46

57
export const useUIOptionsRedirect = (state: 'success' | 'failure') => {
68
const { data } = useUISchemasQuery(useLanguage());
9+
const { config } = useStateManagerContext();
10+
11+
const uiOptions: UIOptions | null = useMemo(() => {
12+
// Config has priority over uiOptions in data
13+
if (config?.uiOptions?.redirectUrls) return config.uiOptions;
14+
15+
if (data?.uiOptions?.redirectUrls) return data.uiOptions;
16+
17+
return null;
18+
}, [data, config]);
19+
20+
const redirectUrls: UIOptions['redirectUrls'] | null = useMemo(() => {
21+
if (!uiOptions) return null;
22+
23+
return uiOptions.redirectUrls;
24+
}, [uiOptions]);
725

826
useEffect(() => {
9-
if (data?.uiOptions?.redirectUrls?.[state]) {
10-
location.href = data.uiOptions.redirectUrls?.[state] as string;
27+
if (redirectUrls?.[state]) {
28+
const redirectUrl = redirectUrls[state] as string;
29+
console.info(`Collection Flow resolved to ${state}. Redirecting to ${redirectUrl}`);
30+
location.href = redirectUrls[state] as string;
1131
}
12-
}, [data, state]);
32+
}, [redirectUrls, state]);
1333
};

apps/kyb-app/src/pages/CollectionFlow/CollectionFlow.tsx

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,25 @@ export const useCompleteLastStep = () => {
6262
const isPendingSync = useRef(false);
6363

6464
useEffect(() => {
65-
(async () => {
65+
void (async () => {
6666
if (state !== 'finish') return;
6767

68-
const { data: context } = await refetch();
68+
const { data: contextData } = await refetch();
6969

7070
if (
71-
!context ||
72-
context?.flowConfig?.stepsProgress?.[elements?.at(-1)?.stateName ?? '']?.isCompleted ||
71+
!contextData ||
72+
contextData?.context?.flowConfig?.stepsProgress?.[elements?.at(-1)?.stateName ?? '']
73+
?.isCompleted ||
7374
isPendingSync.current
7475
) {
7576
return;
7677
}
7778

78-
set(context, `flowConfig.stepsProgress.${elements?.at(-1)?.stateName}.isCompleted`, true);
79+
set(
80+
contextData.context,
81+
`flowConfig.stepsProgress.${elements?.at(-1)?.stateName}.isCompleted`,
82+
true,
83+
);
7984
await stateApi.invokePlugin('sync_workflow_runtime');
8085
isPendingSync.current = true;
8186
})();
@@ -88,15 +93,15 @@ const isFailed = (state: string) => state === 'failed';
8893
export const CollectionFlow = withSessionProtected(() => {
8994
const { language } = useLanguageParam();
9095
const { data: schema } = useUISchemasQuery(language);
91-
const { data: context } = useFlowContextQuery();
96+
const { data: contextData } = useFlowContextQuery();
9297
const { customer } = useCustomer();
9398
const { t } = useTranslation();
9499
const { themeDefinition } = useTheme();
95100

96101
const elements = schema?.uiSchema?.elements;
97102
const definition = schema?.definition.definition;
98103

99-
const pageErrors = usePageErrors(context ?? {}, elements || []);
104+
const pageErrors = usePageErrors(contextData ?? {}, elements || []);
100105
const isRevision = useMemo(
101106
() => pageErrors.some(error => error.errors?.some(error => error.type === 'warning')),
102107
[pageErrors],
@@ -108,24 +113,24 @@ export const CollectionFlow = withSessionProtected(() => {
108113
const initialContext: CollectionFlowContext | null = useMemo(() => {
109114
const appState =
110115
filteredNonEmptyErrors?.[0]?.stateName ||
111-
context?.flowConfig?.appState ||
116+
contextData?.context?.flowConfig?.appState ||
112117
elements?.at(0)?.stateName;
113118

114119
if (!appState) return null;
115120

116121
return {
117-
...context,
122+
...contextData?.context,
118123
flowConfig: {
119-
...context?.flowConfig,
124+
...contextData?.context?.flowConfig,
120125
appState,
121126
},
122127
state: appState,
123128
};
124-
}, [context, elements, filteredNonEmptyErrors]);
129+
}, [contextData, elements, filteredNonEmptyErrors]);
125130

126131
const initialUIState = useMemo(() => {
127-
return prepareInitialUIState(elements || [], context || {}, isRevision);
128-
}, [elements, context, isRevision]);
132+
return prepareInitialUIState(elements || [], contextData?.context || {}, isRevision);
133+
}, [elements, contextData, isRevision]);
129134

130135
// Breadcrumbs now using scrollIntoView method to make sure that breadcrumb is always in viewport.
131136
// Due to dynamic dimensions of logo it doesnt work well if scroll happens before logo is loaded.
@@ -143,14 +148,15 @@ export const CollectionFlow = withSessionProtected(() => {
143148

144149
if (initialContext?.flowConfig?.appState == 'rejected') return <Rejected />;
145150

146-
return definition && context ? (
151+
return definition && contextData ? (
147152
<DynamicUI initialState={initialUIState}>
148153
<DynamicUI.StateManager
149154
initialContext={initialContext}
150155
workflowId="1"
151156
definitionType={schema?.definition.definitionType}
152157
extensions={schema?.definition.extensions}
153158
definition={definition as State}
159+
config={contextData?.config}
154160
>
155161
{({ state, stateApi }) => {
156162
// Temp state, has to be resolved to success or failure by plugins

0 commit comments

Comments
 (0)