Skip to content

Commit bcdc8a4

Browse files
chesterkmralonp99
andauthored
Illiar/feat/app state (#2796)
* feat: updated types & updated common * feat: implemented collection flow manager & partially integrated in kyb and wf service * feat: implemented kyb state handling for backoffice actions * feat: refactored schemas * feat: added completed state * feat: added completed state transition on submit * fix: fixed build * fix: updated types * feat: common bump * fix: fixed process tracker in backoffice * fix: fixed kyb seed & process tracker refactor * feat: added steps order to collection flow config & fixed process tracker in backoffice * fix: cleanup * fix: schema * fix: refactor wf service * fix: seed fix * --ammend * feat: refactor * feat: refactor * fix(swagger): default values and bearer indication --------- Co-authored-by: Alon Peretz <[email protected]>
1 parent e306b2b commit bcdc8a4

File tree

85 files changed

+1633
-865
lines changed

Some content is hidden

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

85 files changed

+1633
-865
lines changed

apps/backoffice-v2/CHANGELOG.md

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

3+
## 0.7.60
4+
5+
### Patch Changes
6+
7+
- bump
8+
- Updated dependencies
9+
- @ballerine/workflow-browser-sdk@0.6.57
10+
- @ballerine/workflow-node-sdk@0.6.57
11+
- @ballerine/blocks@0.2.24
12+
- @ballerine/common@0.9.45
13+
- @ballerine/react-pdf-toolkit@1.2.40
14+
- @ballerine/ui@0.5.40
15+
16+
## 0.7.59
17+
18+
### Patch Changes
19+
20+
- Updated dependencies
21+
- @ballerine/common@0.9.44
22+
- @ballerine/workflow-browser-sdk@0.6.56
23+
- @ballerine/workflow-node-sdk@0.6.56
24+
325
## 0.7.58
426

527
### 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.58",
3+
"version": "0.7.60",
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.23",
54-
"@ballerine/common": "0.9.43",
55-
"@ballerine/react-pdf-toolkit": "^1.2.37",
56-
"@ballerine/ui": "^0.5.37",
57-
"@ballerine/workflow-browser-sdk": "0.6.55",
58-
"@ballerine/workflow-node-sdk": "0.6.55",
53+
"@ballerine/blocks": "0.2.24",
54+
"@ballerine/common": "0.9.45",
55+
"@ballerine/react-pdf-toolkit": "^1.2.40",
56+
"@ballerine/ui": "^0.5.40",
57+
"@ballerine/workflow-browser-sdk": "0.6.57",
58+
"@ballerine/workflow-node-sdk": "0.6.57",
5959
"@botpress/webchat": "^2.1.10",
6060
"@botpress/webchat-generator": "^0.2.9",
6161
"@fontsource/inter": "^4.5.15",
@@ -128,8 +128,8 @@
128128
"zod": "^3.22.3"
129129
},
130130
"devDependencies": {
131-
"@ballerine/config": "^1.1.21",
132-
"@ballerine/eslint-config-react": "^2.0.21",
131+
"@ballerine/config": "^1.1.22",
132+
"@ballerine/eslint-config-react": "^2.0.22",
133133
"@cspell/cspell-types": "^6.31.1",
134134
"@faker-js/faker": "^7.6.0",
135135
"@playwright/test": "^1.32.1",

apps/backoffice-v2/src/common/components/molecules/ProcessTracker/hooks/useProcessTracker/process-tracker-adapters/collection-flow.process-tracker.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,26 @@ export class CollectionFlowProcessTracker implements IProcessTracker {
2828
}
2929

3030
private getSteps() {
31-
return Object.keys(this.workflow?.context?.flowConfig?.stepsProgress ?? {})?.sort((a, b) => {
32-
return (
33-
(this.workflow?.context?.flowConfig?.stepsProgress?.[a]?.number ?? 0) -
34-
(this.workflow?.context?.flowConfig?.stepsProgress?.[b]?.number ?? 0)
35-
);
36-
});
31+
const steps = this.workflow?.context?.collectionFlow?.config?.steps;
32+
33+
if (!steps?.length) return [];
34+
35+
// Create a map of stateName to orderNumber for efficient lookup
36+
const stateOrderMap = new Map(steps.map(step => [step.stateName, step.orderNumber]));
37+
38+
// Get progress states and sort them by their corresponding orderNumber
39+
return Object.keys(this.workflow?.context?.collectionFlow?.state?.progress ?? {}).sort(
40+
(a, b) => {
41+
const orderA = stateOrderMap.get(a) ?? 0;
42+
const orderB = stateOrderMap.get(b) ?? 0;
43+
44+
return orderA - orderB;
45+
},
46+
);
3747
}
3848

3949
private getCollectionFlowStatus(step: string) {
40-
if (this.workflow?.context?.flowConfig?.stepsProgress?.[step]?.isCompleted) {
50+
if (this.workflow?.context?.collectionFlow?.state?.progress?.[step]?.isCompleted) {
4151
return processStatusToIcon[ProcessStatus.SUCCESS];
4252
}
4353

apps/backoffice-v2/src/domains/workflows/fetchers.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { handleZodError } from '@/common/utils/handle-zod-error/handle-zod-error
66
import { WorkflowDefinitionByIdSchema } from '@/domains/workflow-definitions/fetchers';
77
import { AmlSchema } from '@/lib/blocks/components/AmlBlock/utils/aml-adapter';
88
import { ObjectWithIdSchema } from '@/lib/zod/utils/object-with-id/object-with-id';
9+
import { CollectionFlowStates } from '@ballerine/common';
910
import qs from 'qs';
1011
import { deepCamelKeys } from 'string-ts';
1112
import { z } from 'zod';
@@ -115,18 +116,18 @@ export const BaseWorkflowByIdSchema = z.object({
115116
})
116117
.passthrough()
117118
.optional(),
118-
flowConfig: z
119+
collectionFlow: z
119120
.object({
120-
stepsProgress: z
121-
.record(
122-
z.string(),
123-
z.object({
124-
// TODO Until backwards compatibility is handled
125-
number: z.number().default(0),
126-
isCompleted: z.boolean(),
127-
}),
128-
)
129-
.or(z.undefined()),
121+
config: z.object({
122+
apiUrl: z.string().url(),
123+
steps: z.array(z.object({ stateName: z.string(), orderNumber: z.number() })),
124+
}),
125+
state: z.object({
126+
uiState: z.string(),
127+
collectionFlowState: z.enum(Object.values(CollectionFlowStates) as [string, ...string[]]),
128+
progress: z.record(z.string(), z.object({ isCompleted: z.boolean() })),
129+
}),
130+
additionalInformation: z.record(z.string(), z.unknown()).optional(),
130131
})
131132
.optional(),
132133
customData: z.record(z.string(), z.unknown()).optional(),
@@ -150,7 +151,7 @@ export const WorkflowByIdSchema = BaseWorkflowByIdSchema.extend({
150151
context: true,
151152
}).extend({
152153
context: BaseWorkflowByIdSchema.shape.context.omit({
153-
flowConfig: true,
154+
collectionFlow: true,
154155
}),
155156
}),
156157
)

apps/kyb-app/CHANGELOG.md

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

3+
## 0.3.71
4+
5+
### Patch Changes
6+
7+
- bump
8+
- Updated dependencies
9+
- @ballerine/workflow-browser-sdk@0.6.57
10+
- @ballerine/blocks@0.2.24
11+
- @ballerine/common@0.9.45
12+
- @ballerine/ui@0.5.40
13+
14+
## 0.3.70
15+
16+
### Patch Changes
17+
18+
- Updated dependencies
19+
- @ballerine/common@0.9.44
20+
- @ballerine/workflow-browser-sdk@0.6.56
21+
322
## 0.3.69
423

524
### 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.69",
4+
"version": "0.3.71",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",
@@ -15,10 +15,10 @@
1515
"test:dev": "vitest"
1616
},
1717
"dependencies": {
18-
"@ballerine/blocks": "0.2.23",
19-
"@ballerine/ui": "0.5.39",
20-
"@ballerine/common": "^0.9.43",
21-
"@ballerine/workflow-browser-sdk": "0.6.55",
18+
"@ballerine/blocks": "0.2.24",
19+
"@ballerine/ui": "0.5.40",
20+
"@ballerine/common": "^0.9.45",
21+
"@ballerine/workflow-browser-sdk": "0.6.57",
2222
"@lukemorales/query-key-factory": "^1.0.3",
2323
"@radix-ui/react-icons": "^1.3.0",
2424
"@rjsf/core": "^5.9.0",
@@ -63,8 +63,8 @@
6363
"zod": "^3.21.4"
6464
},
6565
"devDependencies": {
66-
"@ballerine/config": "^1.1.21",
67-
"@ballerine/eslint-config-react": "^2.0.21",
66+
"@ballerine/config": "^1.1.22",
67+
"@ballerine/eslint-config-react": "^2.0.22",
6868
"@jest/globals": "^29.7.0",
6969
"@sentry/vite-plugin": "^2.9.0",
7070
"@testing-library/jest-dom": "^6.1.4",

apps/kyb-app/src/components/layouts/AppShell/Navigation.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@ import { ctw } from '@ballerine/ui';
1212
export const Navigation = () => {
1313
const { state } = useDynamicUIContext();
1414
const { t } = useTranslation();
15-
const { stateApi } = useStateManagerContext();
15+
const { stateApi, payload } = useStateManagerContext();
1616
const { currentPage } = usePageResolverContext();
1717
const { customer } = useCustomer();
1818
const { exit, isExitAvailable } = useAppExit();
1919

20-
const isFirstStep = currentPage?.number === 1;
20+
const currentPageNumber = payload?.collectionFlow?.config?.steps?.find(
21+
step => step.stateName === currentPage?.stateName,
22+
)?.orderNumber;
23+
24+
const isFirstStep = currentPageNumber === 1;
2125
const isDisabled = state.isLoading;
2226

2327
const onPrevious = useCallback(async () => {

apps/kyb-app/src/components/organisms/DynamicUI/Page/hooks/usePageErrors/usePageErrors.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ErrorField } from '@/components/organisms/DynamicUI/rule-engines';
22
import { findDocumentDefinitionById } from '@/components/organisms/UIRenderer/elements/JSONForm/helpers/findDefinitionByName';
33
import { Document, UIElement, UIPage } from '@/domains/collection-flow';
4+
import { CollectionFlowContext } from '@/domains/collection-flow/types/flow-context.types';
45
import { AnyObject } from '@ballerine/ui';
56
import { useMemo } from 'react';
67

@@ -22,11 +23,15 @@ export const selectDirectorsDocuments = (context: unknown): Document[] =>
2223
?.filter(Boolean)
2324
?.flat() || [];
2425

25-
export const usePageErrors = (context: AnyObject, pages: UIPage[]): PageError[] => {
26+
export const usePageErrors = (context: CollectionFlowContext, pages: UIPage[]): PageError[] => {
2627
return useMemo(() => {
2728
const pagesWithErrors: PageError[] = pages.map(page => {
29+
const pageNumber = context?.collectionFlow?.config?.steps?.find(
30+
step => step.stateName === page.stateName,
31+
)?.orderNumber;
32+
2833
const pageErrorBase: PageError = {
29-
page: page.number,
34+
page: pageNumber ?? page.number,
3035
pageName: page.name,
3136
stateName: page.stateName,
3237
errors: [],

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const StateManager = ({
2020
const machine = useMemo(() => {
2121
const initialMachineState = {
2222
...initialContext,
23-
state: initialContext?.flowConfig?.appState,
23+
state: initialContext?.collectionFlow?.state?.uiState,
2424
};
2525

2626
const machine = createStateMachine(
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { StateMachineAPI } from '@/components/organisms/DynamicUI/StateManager/hooks/useMachineLogic';
22
import { Action } from '@/domains/collection-flow';
3+
import { CollectionFlowContext } from '@/domains/collection-flow/types/flow-context.types';
34

45
export type ActionHandlerApi = StateMachineAPI;
56

67
export abstract class ActionHandler {
78
public abstract readonly ACTION_TYPE: string;
89

9-
abstract run<TContext>(
10-
context: TContext,
10+
abstract run(
11+
context: CollectionFlowContext,
1112
action: Action,
1213
api: ActionHandlerApi,
13-
): Promise<TContext>;
14+
): Promise<CollectionFlowContext>;
1415
}

0 commit comments

Comments
 (0)