Skip to content

Commit

Permalink
Add/Remove UBOs (#2904)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Omri-Levy authored Dec 26, 2024
1 parent 3294577 commit 01c1a6c
Show file tree
Hide file tree
Showing 58 changed files with 1,495 additions and 337 deletions.
8 changes: 8 additions & 0 deletions apps/backoffice-v2/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,13 @@ const config: StorybookConfig = {
docs: {
autodocs: true,
},
viteFinal: config => {
config.optimizeDeps = {
...config.optimizeDeps,
include: ['@ballerine/ui'],
};

return config;
},
};
export default config;
11 changes: 11 additions & 0 deletions apps/backoffice-v2/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# @ballerine/backoffice-v2

## 0.7.84

### Patch Changes

- Updated dependencies
- @ballerine/common@0.9.60
- @ballerine/ui@0.5.54
- @ballerine/workflow-browser-sdk@0.6.79
- @ballerine/react-pdf-toolkit@1.2.54
- @ballerine/workflow-node-sdk@0.6.79

## 0.7.83

### Patch Changes
Expand Down
12 changes: 6 additions & 6 deletions apps/backoffice-v2/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ballerine/backoffice-v2",
"version": "0.7.83",
"version": "0.7.84",
"description": "Ballerine - Backoffice",
"homepage": "https://github.com/ballerine-io/ballerine",
"type": "module",
Expand Down Expand Up @@ -52,11 +52,11 @@
},
"dependencies": {
"@ballerine/blocks": "0.2.30",
"@ballerine/common": "0.9.59",
"@ballerine/react-pdf-toolkit": "^1.2.53",
"@ballerine/ui": "^0.5.53",
"@ballerine/workflow-browser-sdk": "0.6.78",
"@ballerine/workflow-node-sdk": "0.6.78",
"@ballerine/common": "0.9.60",
"@ballerine/react-pdf-toolkit": "^1.2.54",
"@ballerine/ui": "^0.5.54",
"@ballerine/workflow-browser-sdk": "0.6.79",
"@ballerine/workflow-node-sdk": "0.6.79",
"@botpress/webchat": "^2.1.10",
"@botpress/webchat-generator": "^0.2.9",
"@fontsource/inter": "^4.5.15",
Expand Down
8 changes: 8 additions & 0 deletions apps/backoffice-v2/public/locales/en/toast.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,13 @@
"update_details": {
"success": "Details updated successfully.",
"error": "Error occurred while updating details."
},
"ubo_created": {
"success": "UBO successfully added",
"error": "Error adding UBO"
},
"ubo_deleted": {
"success": "UBO successfully removed",
"error": "Error removing UBO"
}
}
8 changes: 4 additions & 4 deletions apps/backoffice-v2/src/common/api-client/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { z, ZodSchema } from 'zod';
export interface IApiClient {
<TBody extends AnyRecord, TZodSchema extends ZodSchema>(params: {
endpoint: string;
method: typeof Method.POST | typeof Method.PUT | typeof Method.PATCH;
method: typeof Method.POST | typeof Method.PUT | typeof Method.PATCH | typeof Method.DELETE;
body?: TBody;
options?: Omit<RequestInit, 'body'>;
timeout?: number;
Expand All @@ -19,7 +19,7 @@ export interface IApiClient {

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

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

<TZodSchema extends ZodSchema>(params: {
url: string;
method: typeof Method.GET | typeof Method.DELETE;
method: typeof Method.GET;
options?: Omit<RequestInit, 'body'>;
timeout?: number;
schema: TZodSchema;
Expand Down
25 changes: 25 additions & 0 deletions apps/backoffice-v2/src/domains/ui-definition/fetchers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { apiClient } from '@/common/api-client/api-client';

import { Method } from '@/common/enums';

import { handleZodError } from '@/common/utils/handle-zod-error/handle-zod-error';
import { z } from 'zod';

export const translateUiDefinition = async ({
id,
partialUiDefinition,
}: {
id: string;
partialUiDefinition: Record<string, unknown>;
}) => {
const [data, error] = await apiClient({
endpoint: `../case-management/ui-definition/${id}/translate/en`,
method: Method.POST,
body: {
partialUiDefinition,
},
schema: z.record(z.string(), z.unknown()),
});

return handleZodError(error, data);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { useQuery } from '@tanstack/react-query';

import { uiDefinitionQueryKeys } from '@/domains/ui-definition/query-keys';

export const useTranslateUiDefinitionQuery = ({
id,
partialUiDefinition,
}: {
id: string;
partialUiDefinition: Record<string, unknown>;
}) => {
return useQuery({
...uiDefinitionQueryKeys.translate({ id, partialUiDefinition }),
enabled: !!partialUiDefinition && !!id,
});
};
22 changes: 22 additions & 0 deletions apps/backoffice-v2/src/domains/ui-definition/query-keys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { createQueryKeys } from '@lukemorales/query-key-factory';
import { translateUiDefinition } from './fetchers';

export const uiDefinitionQueryKeys = createQueryKeys('ui-definition', {
translate: ({
id,
partialUiDefinition,
}: {
id: string;
partialUiDefinition: Record<string, unknown>;
}) => {
return {
queryKey: [
{
id,
partialUiDefinition,
},
],
queryFn: () => translateUiDefinition({ id, partialUiDefinition }),
};
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ export const WorkflowDefinitionByIdSchema = ObjectWithIdSchema.extend({
})
.optional()
.nullable(),
uiDefinitions: z
.array(z.object({ id: z.string(), uiContext: z.string() }))
.optional()
.nullable(),
});

export type TWorkflowDefinitionById = z.infer<typeof WorkflowDefinitionByIdSchema>;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { apiClient } from '@/common/api-client/api-client';

import { Method } from '@/common/enums';

import { z } from 'zod';

import { handleZodError } from '@/common/utils/handle-zod-error/handle-zod-error';

import { toast } from 'sonner';
import { useMutation } from '@tanstack/react-query';
import { useQueryClient } from '@tanstack/react-query';
import { t } from 'i18next';

export const useCreateUboMutation = ({
workflowId,
onSuccess,
}: {
workflowId: string;
onSuccess: () => void;
}) => {
const queryClient = useQueryClient();

return useMutation({
mutationFn: async (ubo: Record<string, unknown>) => {
const [data, error] = await apiClient({
endpoint: `../case-management/workflows/${workflowId}/ubos`,
method: Method.POST,
body: ubo,
schema: z.undefined(),
});

return handleZodError(error, data);
},
onSuccess: () => {
void queryClient.invalidateQueries();
toast.success(t('toast:ubo_created.success'));
onSuccess();
},
onError: () => {
toast.error(t('toast:ubo_created.error'));
},
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { apiClient } from '@/common/api-client/api-client';

import { z } from 'zod';

import { handleZodError } from '@/common/utils/handle-zod-error/handle-zod-error';

import { toast } from 'sonner';
import { Method } from '@/common/enums';
import { useQueryClient } from '@tanstack/react-query';
import { useMutation } from '@tanstack/react-query';
import { t } from 'i18next';

export const useDeleteUbosByIdsMutation = ({ workflowId }: { workflowId: string }) => {
const queryClient = useQueryClient();

return useMutation({
mutationFn: async (ids: string[]) => {
const [data, error] = await apiClient({
endpoint: `../case-management/workflows/${workflowId}/ubos`,
method: Method.DELETE,
body: { ids },
schema: z.undefined(),
});

return handleZodError(error, data);
},
onSuccess: () => {
void queryClient.invalidateQueries();

toast.success(t('toast:ubo_deleted.success'));
},
onError: () => {
toast.error(t('toast:ubo_deleted.error'));
},
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const BlockCell: FunctionComponent<IBlockCellProps> = ({ value, props })
}

return (
<Card className={ctw('me-4 shadow-[0_4px_4px_0_rgba(174,174,174,0.0625)]', props?.className)}>
<Card className={ctw('shadow-[0_4px_4px_0_rgba(174,174,174,0.0625)]', props?.className)}>
<CardContent
className={ctw(
'grid gap-2',
Expand Down
Loading

0 comments on commit 01c1a6c

Please sign in to comment.