Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add/Remove UBOs #2904

Merged
merged 9 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
},
Omri-Levy marked this conversation as resolved.
Show resolved Hide resolved
};
export default config;
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`,
Omri-Levy marked this conversation as resolved.
Show resolved Hide resolved
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,
});
};
Omri-Levy marked this conversation as resolved.
Show resolved Hide resolved
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(),
Omri-Levy marked this conversation as resolved.
Show resolved Hide resolved
});

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
Loading