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

WIP - Directors individual sanctions #2980

Merged
merged 10 commits into from
Jan 23, 2025
Merged
9 changes: 9 additions & 0 deletions apps/backoffice-v2/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# @ballerine/backoffice-v2

## 0.7.96

### Patch Changes

- Updated dependencies
- @ballerine/[email protected]
- @ballerine/[email protected]
- @ballerine/[email protected]

## 0.7.95

### Patch Changes
Expand Down
8 changes: 4 additions & 4 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.95",
"version": "0.7.96",
"description": "Ballerine - Backoffice",
"homepage": "https://github.com/ballerine-io/ballerine",
"type": "module",
Expand Down Expand Up @@ -53,9 +53,9 @@
},
"dependencies": {
"@ballerine/blocks": "0.2.34",
"@ballerine/common": "0.9.68",
"@ballerine/workflow-browser-sdk": "0.6.87",
"@ballerine/workflow-node-sdk": "0.6.87",
"@ballerine/common": "0.9.69",
"@ballerine/workflow-browser-sdk": "0.6.88",
"@ballerine/workflow-node-sdk": "0.6.88",
"@ballerine/react-pdf-toolkit": "^1.2.67",
"@ballerine/ui": "^0.5.67",
"@botpress/webchat": "^2.1.10",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ export const useApproveTaskByIdMutation = (workflowId: string) => {

return useMutation({
mutationFn: ({
directorId,
documentId,
contextUpdateMethod = 'base',
comment,
}: {
directorId?: string;
documentId: string;
contextUpdateMethod?: 'base' | 'director';
comment?: string;
Expand All @@ -25,6 +27,7 @@ export const useApproveTaskByIdMutation = (workflowId: string) => {
workflowId,
documentId,
body: {
directorId,
decision: Action.APPROVE,
comment,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ export const useRemoveDecisionTaskByIdMutation = (workflowId: string) => {
return useMutation({
mutationFn: ({
documentId,
directorId,
contextUpdateMethod,
}: {
documentId: string;
directorId?: string;
contextUpdateMethod: 'base' | 'director';
}) =>
updateWorkflowDecision({
workflowId,
documentId,
body: {
directorId,
decision: null,
reason: null,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@ export const useRevisionTaskByIdMutation = () => {
workflowId,
documentId,
reason,
directorId,
contextUpdateMethod,
}: {
workflowId: string;
documentId: string;
reason?: string;
directorId?: string;
contextUpdateMethod?: 'base' | 'director';
}) =>
updateWorkflowDecision({
workflowId,
documentId,
contextUpdateMethod,
body: {
directorId,
decision: Action.REVISION,
reason,
},
Expand Down
24 changes: 24 additions & 0 deletions apps/backoffice-v2/src/domains/individuals/fetchers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { handleZodError } from '@/common/utils/handle-zod-error/handle-zod-error';

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

import { z } from 'zod';

import { HitSchema } from '@/lib/blocks/components/AmlBlock/utils/aml-adapter';

import { apiClient } from '@/common/api-client/api-client';

export const EndUserSchema = z.object({
amlHits: z.array(HitSchema.extend({ vendor: z.string().optional() })).optional(),
});

export const getEndUserById = async ({ id }: { id: string }) => {
const [endUser, error] = await apiClient({
endpoint: `end-users/${id}`,
method: Method.GET,
schema: EndUserSchema,
timeout: 30_000,
});

return handleZodError(error, endUser);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { useIsAuthenticated } from '@/domains/auth/context/AuthProvider/hooks/useIsAuthenticated/useIsAuthenticated';
import { useQuery } from '@tanstack/react-query';
import { endUsersQueryKeys } from '../../query-keys';

export const useEndUserByIdQuery = ({ id }: { id: string }) => {
const isAuthenticated = useIsAuthenticated();

return useQuery({
...endUsersQueryKeys.byId({ id }),
enabled: !!id && isAuthenticated,
});
};
9 changes: 9 additions & 0 deletions apps/backoffice-v2/src/domains/individuals/query-keys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { createQueryKeys } from '@lukemorales/query-key-factory';
import { getEndUserById } from './fetchers';

export const endUsersQueryKeys = createQueryKeys('end-users', {
byId: ({ id }: { id: string }) => ({
queryKey: ['end-users', id],
queryFn: () => getEndUserById({ id }),
}),
});
1 change: 1 addition & 0 deletions apps/backoffice-v2/src/domains/workflows/fetchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ export const updateWorkflowDecision = async ({
documentId: string;
body: {
decision: string | null;
directorId?: string;
reason?: string;
comment?: string;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { BlocksComponent } from '@ballerine/blocks';
import { cells } from '../../create-blocks-typed/create-blocks-typed';
import { useEndUserByIdQuery } from '@/domains/individuals/queries/useEndUserByIdQuery/useEndUserByIdQuery';
import { useDirectorBlock } from './hooks/useDirectorBlock/useDirectorBlock';

export const DirectorBlock = ({
workflowId,
onReuploadNeeded,
onRemoveDecision,
onApprove,
director,
tags,
revisionReasons,
isEditable,
isApproveDisabled,
documentSchemas,
isLoadingDocuments,
workflow,
}: Omit<Parameters<typeof useDirectorBlock>[0], 'director'> & {
director: Omit<Parameters<typeof useDirectorBlock>[0]['director'], 'aml'>;
}) => {
const { data: endUser } = useEndUserByIdQuery({ id: director.id });
const directorWithAml = {
...director,
aml: {
vendor: endUser?.amlHits?.find(({ vendor }) => !!vendor)?.vendor,
hits: endUser?.amlHits,
},
};
const directorBlock = useDirectorBlock({
workflowId,
onReuploadNeeded,
onRemoveDecision,
onApprove,
director: directorWithAml,
tags,
revisionReasons,
isEditable,
isApproveDisabled,
documentSchemas,
isLoadingDocuments,
workflow,
});

return (
<BlocksComponent blocks={directorBlock} cells={cells}>
{(Cell, cell) => <Cell {...cell} />}
</BlocksComponent>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { createBlocksTyped } from '@/lib/blocks/create-blocks-typed/create-blocks-typed';
import { ComponentProps } from 'react';
import { DirectorBlock } from '../../DirectorBlock';
import { getDocumentsByCountry } from '@ballerine/common';
import { extractCountryCodeFromDocuments } from '@/pages/Entity/hooks/useEntityLogic/utils';

export const createDirectorsBlocks = ({
workflowId,
onReuploadNeeded,
onRemoveDecision,
onApprove,
directors,
tags,
revisionReasons,
isEditable,
isApproveDisabled,
isLoadingDocuments,
workflow,
}: Omit<ComponentProps<typeof DirectorBlock>, 'director' | 'documentSchemas'> & {
directors: Array<ComponentProps<typeof DirectorBlock>['director']>;
}) => {
const directorsBlocks = createBlocksTyped().addBlock();

if (!directors?.length) {
return [];
}

directors?.forEach(director => {
const issuerCountryCode = extractCountryCodeFromDocuments(director.documents);
const documentSchemas = issuerCountryCode ? getDocumentsByCountry(issuerCountryCode) : [];

if (!Array.isArray(documentSchemas) || !documentSchemas.length) {
console.warn(`No document schema found for issuer country code of "${issuerCountryCode}".`);
}

directorsBlocks.addCell({
type: 'node',
value: (
<DirectorBlock
workflowId={workflowId}
onReuploadNeeded={onReuploadNeeded}
onRemoveDecision={onRemoveDecision}
onApprove={onApprove}
director={director}
tags={tags}
revisionReasons={revisionReasons}
isEditable={isEditable}
isApproveDisabled={isApproveDisabled}
documentSchemas={documentSchemas}
isLoadingDocuments={isLoadingDocuments}
workflow={workflow}
/>
),
});
});

return directorsBlocks.build();
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { createDirectorsBlocks } from './create-directors-blocks';

export const directorDocumentsAdapter = ({ documents, storageFiles }) => {
return documents?.map(
(document, documentIndex) =>
({
id: document?.id,
category: document?.category,
type: document?.type,
issuer: {
country: document?.issuer?.country,
},
decision: {
status: document?.decision?.status,
},
version: document?.version,
properties: document?.properties,
propertiesSchema: document?.propertiesSchema,
pages: document?.pages?.map(
(page, pageIndex) =>
({
type: page?.type,
imageUrl: storageFiles?.[documentIndex]?.[pageIndex],
metadata: {
side: page?.metadata?.side,
},
} satisfies Parameters<
typeof createDirectorsBlocks
>[0]['directors'][number]['documents'][number]['pages'][number]),
),
} satisfies Parameters<
typeof createDirectorsBlocks
>[0]['directors'][number]['documents'][number]),
);
};

export const directorAdapter =
storageFiles =>
({ ballerineEntityId, firstName, lastName, additionalInfo }) => {
const documents = directorDocumentsAdapter({
documents: additionalInfo?.documents,
storageFiles,
});

return {
id: ballerineEntityId,
firstName,
lastName,
documents,
} satisfies Parameters<typeof createDirectorsBlocks>[0]['directors'][number];
};
Omri-Levy marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './useDirectorBlock';
Loading
Loading