Skip to content

Commit adaed46

Browse files
authored
feat: refactored app state (#2808)
1 parent bcdc8a4 commit adaed46

File tree

34 files changed

+193
-131
lines changed

34 files changed

+193
-131
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.61
4+
5+
### Patch Changes
6+
7+
- Updated dependencies
8+
- @ballerine/common@0.9.46
9+
- @ballerine/workflow-browser-sdk@0.6.58
10+
- @ballerine/workflow-node-sdk@0.6.58
11+
312
## 0.7.60
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.60",
3+
"version": "0.7.61",
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.45",
54+
"@ballerine/common": "0.9.46",
5555
"@ballerine/react-pdf-toolkit": "^1.2.40",
5656
"@ballerine/ui": "^0.5.40",
57-
"@ballerine/workflow-browser-sdk": "0.6.57",
58-
"@ballerine/workflow-node-sdk": "0.6.57",
57+
"@ballerine/workflow-browser-sdk": "0.6.58",
58+
"@ballerine/workflow-node-sdk": "0.6.58",
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class CollectionFlowProcessTracker implements IProcessTracker {
3636
const stateOrderMap = new Map(steps.map(step => [step.stateName, step.orderNumber]));
3737

3838
// Get progress states and sort them by their corresponding orderNumber
39-
return Object.keys(this.workflow?.context?.collectionFlow?.state?.progress ?? {}).sort(
39+
return Object.keys(this.workflow?.context?.collectionFlow?.state?.progressBreakdown ?? {}).sort(
4040
(a, b) => {
4141
const orderA = stateOrderMap.get(a) ?? 0;
4242
const orderB = stateOrderMap.get(b) ?? 0;
@@ -47,7 +47,7 @@ export class CollectionFlowProcessTracker implements IProcessTracker {
4747
}
4848

4949
private getCollectionFlowStatus(step: string) {
50-
if (this.workflow?.context?.collectionFlow?.state?.progress?.[step]?.isCompleted) {
50+
if (this.workflow?.context?.collectionFlow?.state?.progressBreakdown?.[step]?.isCompleted) {
5151
return processStatusToIcon[ProcessStatus.SUCCESS];
5252
}
5353

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

Lines changed: 4 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 { CollectionFlowStates } from '@ballerine/common';
9+
import { CollectionFlowStatuses } from '@ballerine/common';
1010
import qs from 'qs';
1111
import { deepCamelKeys } from 'string-ts';
1212
import { z } from 'zod';
@@ -123,9 +123,9 @@ export const BaseWorkflowByIdSchema = z.object({
123123
steps: z.array(z.object({ stateName: z.string(), orderNumber: z.number() })),
124124
}),
125125
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() })),
126+
currentStep: z.string(),
127+
status: z.enum(Object.values(CollectionFlowStatuses) as [string, ...string[]]),
128+
progressBreakdown: z.record(z.string(), z.object({ isCompleted: z.boolean() })),
129129
}),
130130
additionalInformation: z.record(z.string(), z.unknown()).optional(),
131131
})

apps/kyb-app/CHANGELOG.md

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

3+
## 0.3.72
4+
5+
### Patch Changes
6+
7+
- Updated dependencies
8+
- @ballerine/common@0.9.46
9+
- @ballerine/workflow-browser-sdk@0.6.58
10+
311
## 0.3.71
412

513
### Patch Changes

apps/kyb-app/package.json

Lines changed: 3 additions & 3 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.71",
4+
"version": "0.3.72",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",
@@ -17,8 +17,8 @@
1717
"dependencies": {
1818
"@ballerine/blocks": "0.2.24",
1919
"@ballerine/ui": "0.5.40",
20-
"@ballerine/common": "^0.9.45",
21-
"@ballerine/workflow-browser-sdk": "0.6.57",
20+
"@ballerine/common": "^0.9.46",
21+
"@ballerine/workflow-browser-sdk": "0.6.58",
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/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?.collectionFlow?.state?.uiState,
23+
state: initialContext?.collectionFlow?.state?.currentStep,
2424
};
2525

2626
const machine = createStateMachine(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ 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, CollectionFlowStates } from '@ballerine/common';
15+
import { CollectionFlowManager, CollectionFlowStatuses } from '@ballerine/common';
1616
import { Button } from '@ballerine/ui';
1717
import { useCallback, useMemo } from 'react';
1818

@@ -72,7 +72,7 @@ export const SubmitButton: UIElementComponent<{ text: string }> = ({ definition
7272
if (isFinishPage && isValid) {
7373
const collectionFlowManager = new CollectionFlowManager(stateApi.getContext());
7474

75-
collectionFlowManager.state().collectionFlowState = CollectionFlowStates.completed;
75+
collectionFlowManager.state().status = CollectionFlowStatuses.completed;
7676
collectionFlowManager.state().setStepCompletionState(currentPage?.stateName as string, true);
7777

7878
stateApi.setContext(collectionFlowManager.context);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const prepareInitialUIState = (
2424
elements: {},
2525
};
2626

27-
if (pages[0]?.stateName === context.collectionFlow?.state?.uiState) return initialUIState;
27+
if (pages[0]?.stateName === context.collectionFlow?.state?.currentStep) return initialUIState;
2828

2929
pages.forEach(page => {
3030
initialUIState.elements[page.stateName] = {

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { Approved } from '@/pages/CollectionFlow/components/pages/Approved';
3131
import { Failed } from '@/pages/CollectionFlow/components/pages/Failed';
3232
import { Rejected } from '@/pages/CollectionFlow/components/pages/Rejected';
3333
import { Success } from '@/pages/CollectionFlow/components/pages/Success';
34-
import { CollectionFlowManager, CollectionFlowStates } from '@ballerine/common';
34+
import { CollectionFlowManager, CollectionFlowStatuses } from '@ballerine/common';
3535
import { AnyObject } from '@ballerine/ui';
3636

3737
const elems = {
@@ -74,7 +74,7 @@ export const CollectionFlow = withSessionProtected(() => {
7474

7575
const pageErrors = usePageErrors(context ?? ({} as CollectionFlowContext), elements || []);
7676
const isRevision = useMemo(
77-
() => context?.collectionFlow?.state?.collectionFlowState === CollectionFlowStates.revision,
77+
() => context?.collectionFlow?.state?.status === CollectionFlowStatuses.revision,
7878
[context],
7979
);
8080

@@ -83,8 +83,8 @@ export const CollectionFlow = withSessionProtected(() => {
8383

8484
if (isRevision) {
8585
const revisionStateName = getRevisionStateName(pageErrors);
86-
collectionFlowManager.state().uiState =
87-
revisionStateName || collectionFlowManager.state().uiState;
86+
collectionFlowManager.state().currentStep =
87+
revisionStateName || collectionFlowManager.state().currentStep;
8888
}
8989

9090
return collectionFlowManager.context as CollectionFlowContext;
@@ -106,10 +106,10 @@ export const CollectionFlow = withSessionProtected(() => {
106106
setLogoLoaded(false);
107107
}, [customer?.logoImageUri]);
108108

109-
if (initialContext?.collectionFlow?.state?.collectionFlowState === CollectionFlowStates.approved)
109+
if (initialContext?.collectionFlow?.state?.status === CollectionFlowStatuses.approved)
110110
return <Approved />;
111111

112-
if (initialContext?.collectionFlow?.state?.collectionFlowState === CollectionFlowStates.rejected)
112+
if (initialContext?.collectionFlow?.state?.status === CollectionFlowStatuses.rejected)
113113
return <Rejected />;
114114

115115
return definition && context ? (
@@ -132,16 +132,15 @@ export const CollectionFlow = withSessionProtected(() => {
132132
const collectionFlowManager = new CollectionFlowManager(stateApi.getContext());
133133

134134
const isAnyStepCompleted = Object.values(
135-
collectionFlowManager.state().progress || {},
135+
collectionFlowManager.state().progressBreakdown || {},
136136
).some(step => step.isCompleted);
137137

138138
collectionFlowManager.state().setStepCompletionState(prevState, true);
139-
collectionFlowManager.state().uiState = currentState;
139+
collectionFlowManager.state().currentStep = currentState;
140140

141141
if (!isAnyStepCompleted) {
142142
console.log('Collection flow touched, changing state to inprogress');
143-
collectionFlowManager.state().collectionFlowState =
144-
CollectionFlowStates.inprogress;
143+
collectionFlowManager.state().status = CollectionFlowStatuses.inprogress;
145144

146145
console.log('Updating context to', collectionFlowManager.context);
147146
}

0 commit comments

Comments
 (0)