Skip to content

Commit 0f588b7

Browse files
chesterkmralonp99
andauthored
feat: added collection flow utils & removed cf manager (#2810)
* feat: added collection flow utils & removed cf manager * feat: added get-ordered-steps util * fix: added additional terminal state * feat: refactor * fix: type * feat: common bump * chore(package): update dependencies and add auto-commit script - Add dotenv and openai to handle environment variables and generate commit messages - Update @babel/core and related dependencies to version 7.25.2 - Introduce a new auto-commit script to streamline Git commits (Your package.json has more updates than my dating history, and that’s saying something) * chore(deps): update dependencies in pnpm-lock.yaml - Clean up unnecessary duplicate entries for dotenv and openai - Update @babel/core and other related packages from 7.25.2 to 7.23.7 (Your package management is like a modern art exhibit—nobody really understands it) --------- Co-authored-by: Alon Peretz <[email protected]>
1 parent 0717cb9 commit 0f588b7

File tree

64 files changed

+1017
-827
lines changed

Some content is hidden

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

64 files changed

+1017
-827
lines changed

apps/backoffice-v2/CHANGELOG.md

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

3+
## 0.7.62
4+
5+
### Patch Changes
6+
7+
- Updated dependencies
8+
- @ballerine/common@0.9.47
9+
- @ballerine/workflow-browser-sdk@0.6.59
10+
- @ballerine/workflow-node-sdk@0.6.59
11+
312
## 0.7.61
413

514
### Patch Changes

apps/backoffice-v2/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ballerine/backoffice-v2",
3-
"version": "0.7.61",
3+
"version": "0.7.62",
44
"description": "Ballerine - Backoffice",
55
"homepage": "https://github.com/ballerine-io/ballerine",
66
"repository": {
@@ -51,11 +51,11 @@
5151
},
5252
"dependencies": {
5353
"@ballerine/blocks": "0.2.24",
54-
"@ballerine/common": "0.9.46",
54+
"@ballerine/common": "0.9.47",
5555
"@ballerine/react-pdf-toolkit": "^1.2.40",
5656
"@ballerine/ui": "^0.5.40",
57-
"@ballerine/workflow-browser-sdk": "0.6.58",
58-
"@ballerine/workflow-node-sdk": "0.6.58",
57+
"@ballerine/workflow-browser-sdk": "0.6.59",
58+
"@ballerine/workflow-node-sdk": "0.6.59",
5959
"@botpress/webchat": "^2.1.10",
6060
"@botpress/webchat-generator": "^0.2.9",
6161
"@fontsource/inter": "^4.5.15",

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

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

3030
private getSteps() {
31-
const steps = this.workflow?.context?.collectionFlow?.config?.steps;
31+
const steps = this.workflow?.context?.collectionFlow?.state?.steps;
3232

3333
if (!steps?.length) return [];
3434

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?.progressBreakdown ?? {}).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-
);
35+
return steps.map(step => step.stepName);
4736
}
4837

4938
private getCollectionFlowStatus(step: string) {
50-
if (this.workflow?.context?.collectionFlow?.state?.progressBreakdown?.[step]?.isCompleted) {
39+
const stepItem = this.workflow?.context?.collectionFlow?.state?.steps?.find(
40+
s => s.stepName === step,
41+
);
42+
43+
if (!stepItem) return processStatusToIcon[ProcessStatus.IDLE];
44+
45+
if (stepItem?.isCompleted) {
5146
return processStatusToIcon[ProcessStatus.SUCCESS];
5247
}
5348

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +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 { CollectionFlowStatuses } from '@ballerine/common';
9+
import { CollectionFlowStatusesEnum } from '@ballerine/common';
1010
import qs from 'qs';
1111
import { deepCamelKeys } from 'string-ts';
1212
import { z } from 'zod';
@@ -120,12 +120,11 @@ export const BaseWorkflowByIdSchema = z.object({
120120
.object({
121121
config: z.object({
122122
apiUrl: z.string().url(),
123-
steps: z.array(z.object({ stateName: z.string(), orderNumber: z.number() })),
124123
}),
125124
state: z.object({
126125
currentStep: z.string(),
127-
status: z.enum(Object.values(CollectionFlowStatuses) as [string, ...string[]]),
128-
progressBreakdown: z.record(z.string(), z.object({ isCompleted: z.boolean() })),
126+
status: z.enum(Object.values(CollectionFlowStatusesEnum) as [string, ...string[]]),
127+
steps: z.array(z.object({ stepName: z.string(), isCompleted: z.boolean() })),
129128
}),
130129
additionalInformation: z.record(z.string(), z.unknown()).optional(),
131130
})

apps/kyb-app/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
### Patch Changes
66

77
- Updated dependencies
8-
- @ballerine/ui@0.5.41
8+
- @ballerine/common@0.9.47
9+
- @ballerine/workflow-browser-sdk@0.6.59
910

1011
## 0.3.72
1112

apps/kyb-app/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
},
1717
"dependencies": {
1818
"@ballerine/blocks": "0.2.24",
19-
"@ballerine/ui": "0.5.41",
20-
"@ballerine/common": "^0.9.46",
21-
"@ballerine/workflow-browser-sdk": "0.6.58",
19+
"@ballerine/ui": "0.5.40",
20+
"@ballerine/common": "^0.9.47",
21+
"@ballerine/workflow-browser-sdk": "0.6.59",
2222
"@lukemorales/query-key-factory": "^1.0.3",
2323
"@radix-ui/react-icons": "^1.3.0",
2424
"@rjsf/core": "^5.9.0",

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ export const Navigation = () => {
1717
const { customer } = useCustomer();
1818
const { exit, isExitAvailable } = useAppExit();
1919

20-
const currentPageNumber = payload?.collectionFlow?.config?.steps?.find(
21-
step => step.stateName === currentPage?.stateName,
22-
)?.orderNumber;
20+
const currentPageNumber =
21+
Number(
22+
payload?.collectionFlow?.state?.steps?.findIndex(
23+
step => step.stepName === currentPage?.stateName,
24+
),
25+
) + 1;
2326

2427
const isFirstStep = currentPageNumber === 1;
2528
const isDisabled = state.isLoading;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ export const selectDirectorsDocuments = (context: unknown): Document[] =>
2626
export const usePageErrors = (context: CollectionFlowContext, pages: UIPage[]): PageError[] => {
2727
return useMemo(() => {
2828
const pagesWithErrors: PageError[] = pages.map(page => {
29-
const pageNumber = context?.collectionFlow?.config?.steps?.find(
30-
step => step.stateName === page.stateName,
31-
)?.orderNumber;
29+
const pageNumber = context?.collectionFlow?.state?.steps?.findIndex(
30+
step => step.stepName === page.stateName,
31+
);
3232

3333
const pageErrorBase: PageError = {
34-
page: pageNumber ?? page.number,
34+
page: pageNumber !== -1 ? Number(pageNumber) + 1 : page.number,
3535
pageName: page.name,
3636
stateName: page.stateName,
3737
errors: [],

apps/kyb-app/src/components/organisms/UIRenderer/elements/SubmitButton/SubmitButton.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ import { useUIElementState } from '@/components/organisms/UIRenderer/hooks/useUI
1212
import { UIElementComponent } from '@/components/organisms/UIRenderer/types';
1313
import { UIPage } from '@/domains/collection-flow';
1414
import { useFlowTracking } from '@/hooks/useFlowTracking';
15-
import { CollectionFlowManager, CollectionFlowStatuses } from '@ballerine/common';
15+
import {
16+
CollectionFlowStatusesEnum,
17+
getCollectionFlowState,
18+
setStepCompletionState,
19+
} from '@ballerine/common';
1620
import { Button } from '@ballerine/ui';
1721
import { useCallback, useMemo } from 'react';
1822

@@ -70,12 +74,19 @@ export const SubmitButton: UIElementComponent<{ text: string }> = ({ definition
7074
const isFinishPage = currentPage?.name === pages.at(-1)?.name;
7175

7276
if (isFinishPage && isValid) {
73-
const collectionFlowManager = new CollectionFlowManager(stateApi.getContext());
77+
const context = stateApi.getContext();
78+
79+
const collectionFlow = getCollectionFlowState(context);
7480

75-
collectionFlowManager.state().status = CollectionFlowStatuses.completed;
76-
collectionFlowManager.state().setStepCompletionState(currentPage?.stateName as string, true);
81+
if (collectionFlow) {
82+
collectionFlow.status = CollectionFlowStatusesEnum.completed;
83+
setStepCompletionState(context, {
84+
stepName: currentPage?.stateName as string,
85+
completed: true,
86+
});
87+
}
7788

78-
stateApi.setContext(collectionFlowManager.context);
89+
stateApi.setContext(context);
7990
}
8091

8192
onClickHandler();

apps/kyb-app/src/helpers/prepareInitialUIState.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import { UIState } from '@/components/organisms/DynamicUI/hooks/useUIStateLogic/types';
22
import { UIPage } from '@/domains/collection-flow';
33
import { CollectionFlowContext } from '@/domains/collection-flow/types/flow-context.types';
4-
import { CollectionFlowManager } from '@ballerine/common';
4+
import { getCollectionFlowState } from '@ballerine/common';
55

66
export const isPageCompleted = (page: UIPage, context: CollectionFlowContext) => {
7-
const flow = new CollectionFlowManager(context);
8-
9-
const result = flow.state().isStepCompleted(page.stateName!);
7+
const collectionFlow = getCollectionFlowState(context);
8+
const isStepCompleted = collectionFlow?.steps?.find(
9+
step => step.stepName === page.stateName,
10+
)?.isCompleted;
1011

1112
if (!page.stateName) return false;
1213

13-
return result;
14+
return isStepCompleted;
1415
};
1516

1617
export const prepareInitialUIState = (

0 commit comments

Comments
 (0)