Skip to content

Commit 01c1a6c

Browse files
authored
Add/Remove UBOs (#2904)
* feat(*): added the ability to add and remove ubos * refactor(*): pr review changes * chore(*): updated packages * fix(workflow-service): fixed path to definition * chore(workflows-service): no longer importing from data-migrations * removed unused import * fixed failing test
1 parent 3294577 commit 01c1a6c

File tree

58 files changed

+1495
-337
lines changed

Some content is hidden

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

58 files changed

+1495
-337
lines changed

apps/backoffice-v2/.storybook/main.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,13 @@ const config: StorybookConfig = {
1818
docs: {
1919
autodocs: true,
2020
},
21+
viteFinal: config => {
22+
config.optimizeDeps = {
23+
...config.optimizeDeps,
24+
include: ['@ballerine/ui'],
25+
};
26+
27+
return config;
28+
},
2129
};
2230
export default config;

apps/backoffice-v2/CHANGELOG.md

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

3+
## 0.7.84
4+
5+
### Patch Changes
6+
7+
- Updated dependencies
8+
- @ballerine/common@0.9.60
9+
- @ballerine/ui@0.5.54
10+
- @ballerine/workflow-browser-sdk@0.6.79
11+
- @ballerine/react-pdf-toolkit@1.2.54
12+
- @ballerine/workflow-node-sdk@0.6.79
13+
314
## 0.7.83
415

516
### Patch Changes

apps/backoffice-v2/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ballerine/backoffice-v2",
3-
"version": "0.7.83",
3+
"version": "0.7.84",
44
"description": "Ballerine - Backoffice",
55
"homepage": "https://github.com/ballerine-io/ballerine",
66
"type": "module",
@@ -52,11 +52,11 @@
5252
},
5353
"dependencies": {
5454
"@ballerine/blocks": "0.2.30",
55-
"@ballerine/common": "0.9.59",
56-
"@ballerine/react-pdf-toolkit": "^1.2.53",
57-
"@ballerine/ui": "^0.5.53",
58-
"@ballerine/workflow-browser-sdk": "0.6.78",
59-
"@ballerine/workflow-node-sdk": "0.6.78",
55+
"@ballerine/common": "0.9.60",
56+
"@ballerine/react-pdf-toolkit": "^1.2.54",
57+
"@ballerine/ui": "^0.5.54",
58+
"@ballerine/workflow-browser-sdk": "0.6.79",
59+
"@ballerine/workflow-node-sdk": "0.6.79",
6060
"@botpress/webchat": "^2.1.10",
6161
"@botpress/webchat-generator": "^0.2.9",
6262
"@fontsource/inter": "^4.5.15",

apps/backoffice-v2/public/locales/en/toast.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,13 @@
104104
"update_details": {
105105
"success": "Details updated successfully.",
106106
"error": "Error occurred while updating details."
107+
},
108+
"ubo_created": {
109+
"success": "UBO successfully added",
110+
"error": "Error adding UBO"
111+
},
112+
"ubo_deleted": {
113+
"success": "UBO successfully removed",
114+
"error": "Error removing UBO"
107115
}
108116
}

apps/backoffice-v2/src/common/api-client/interfaces.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { z, ZodSchema } from 'zod';
88
export interface IApiClient {
99
<TBody extends AnyRecord, TZodSchema extends ZodSchema>(params: {
1010
endpoint: string;
11-
method: typeof Method.POST | typeof Method.PUT | typeof Method.PATCH;
11+
method: typeof Method.POST | typeof Method.PUT | typeof Method.PATCH | typeof Method.DELETE;
1212
body?: TBody;
1313
options?: Omit<RequestInit, 'body'>;
1414
timeout?: number;
@@ -19,7 +19,7 @@ export interface IApiClient {
1919

2020
<TBody extends AnyRecord, TZodSchema extends ZodSchema>(params: {
2121
url: string;
22-
method: typeof Method.POST | typeof Method.PUT | typeof Method.PATCH;
22+
method: typeof Method.POST | typeof Method.PUT | typeof Method.PATCH | typeof Method.DELETE;
2323
body?: TBody;
2424
options?: Omit<RequestInit, 'body'>;
2525
timeout?: number;
@@ -30,7 +30,7 @@ export interface IApiClient {
3030

3131
<TZodSchema extends ZodSchema>(params: {
3232
endpoint: string;
33-
method: typeof Method.GET | typeof Method.DELETE;
33+
method: typeof Method.GET;
3434
options?: Omit<RequestInit, 'body'>;
3535
timeout?: number;
3636
schema: TZodSchema;
@@ -39,7 +39,7 @@ export interface IApiClient {
3939

4040
<TZodSchema extends ZodSchema>(params: {
4141
url: string;
42-
method: typeof Method.GET | typeof Method.DELETE;
42+
method: typeof Method.GET;
4343
options?: Omit<RequestInit, 'body'>;
4444
timeout?: number;
4545
schema: TZodSchema;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { apiClient } from '@/common/api-client/api-client';
2+
3+
import { Method } from '@/common/enums';
4+
5+
import { handleZodError } from '@/common/utils/handle-zod-error/handle-zod-error';
6+
import { z } from 'zod';
7+
8+
export const translateUiDefinition = async ({
9+
id,
10+
partialUiDefinition,
11+
}: {
12+
id: string;
13+
partialUiDefinition: Record<string, unknown>;
14+
}) => {
15+
const [data, error] = await apiClient({
16+
endpoint: `../case-management/ui-definition/${id}/translate/en`,
17+
method: Method.POST,
18+
body: {
19+
partialUiDefinition,
20+
},
21+
schema: z.record(z.string(), z.unknown()),
22+
});
23+
24+
return handleZodError(error, data);
25+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { useQuery } from '@tanstack/react-query';
2+
3+
import { uiDefinitionQueryKeys } from '@/domains/ui-definition/query-keys';
4+
5+
export const useTranslateUiDefinitionQuery = ({
6+
id,
7+
partialUiDefinition,
8+
}: {
9+
id: string;
10+
partialUiDefinition: Record<string, unknown>;
11+
}) => {
12+
return useQuery({
13+
...uiDefinitionQueryKeys.translate({ id, partialUiDefinition }),
14+
enabled: !!partialUiDefinition && !!id,
15+
});
16+
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { createQueryKeys } from '@lukemorales/query-key-factory';
2+
import { translateUiDefinition } from './fetchers';
3+
4+
export const uiDefinitionQueryKeys = createQueryKeys('ui-definition', {
5+
translate: ({
6+
id,
7+
partialUiDefinition,
8+
}: {
9+
id: string;
10+
partialUiDefinition: Record<string, unknown>;
11+
}) => {
12+
return {
13+
queryKey: [
14+
{
15+
id,
16+
partialUiDefinition,
17+
},
18+
],
19+
queryFn: () => translateUiDefinition({ id, partialUiDefinition }),
20+
};
21+
},
22+
});

apps/backoffice-v2/src/domains/workflow-definitions/fetchers.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ export const WorkflowDefinitionByIdSchema = ObjectWithIdSchema.extend({
7777
})
7878
.optional()
7979
.nullable(),
80+
uiDefinitions: z
81+
.array(z.object({ id: z.string(), uiContext: z.string() }))
82+
.optional()
83+
.nullable(),
8084
});
8185

8286
export type TWorkflowDefinitionById = z.infer<typeof WorkflowDefinitionByIdSchema>;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { apiClient } from '@/common/api-client/api-client';
2+
3+
import { Method } from '@/common/enums';
4+
5+
import { z } from 'zod';
6+
7+
import { handleZodError } from '@/common/utils/handle-zod-error/handle-zod-error';
8+
9+
import { toast } from 'sonner';
10+
import { useMutation } from '@tanstack/react-query';
11+
import { useQueryClient } from '@tanstack/react-query';
12+
import { t } from 'i18next';
13+
14+
export const useCreateUboMutation = ({
15+
workflowId,
16+
onSuccess,
17+
}: {
18+
workflowId: string;
19+
onSuccess: () => void;
20+
}) => {
21+
const queryClient = useQueryClient();
22+
23+
return useMutation({
24+
mutationFn: async (ubo: Record<string, unknown>) => {
25+
const [data, error] = await apiClient({
26+
endpoint: `../case-management/workflows/${workflowId}/ubos`,
27+
method: Method.POST,
28+
body: ubo,
29+
schema: z.undefined(),
30+
});
31+
32+
return handleZodError(error, data);
33+
},
34+
onSuccess: () => {
35+
void queryClient.invalidateQueries();
36+
toast.success(t('toast:ubo_created.success'));
37+
onSuccess();
38+
},
39+
onError: () => {
40+
toast.error(t('toast:ubo_created.error'));
41+
},
42+
});
43+
};

0 commit comments

Comments
 (0)