-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
53 changed files
with
1,071 additions
and
637 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |
12 changes: 12 additions & 0 deletions
12
...backoffice-v2/src/domains/individuals/queries/useEndUserByIdQuery/useEndUserByIdQuery.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }), | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
apps/backoffice-v2/src/lib/blocks/components/DirectorBlock/DirectorBlock.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
58 changes: 58 additions & 0 deletions
58
...rc/lib/blocks/components/DirectorBlock/hooks/useDirectorBlock/create-directors-blocks.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}; |
51 changes: 51 additions & 0 deletions
51
apps/backoffice-v2/src/lib/blocks/components/DirectorBlock/hooks/useDirectorBlock/helpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
}; |
1 change: 1 addition & 0 deletions
1
apps/backoffice-v2/src/lib/blocks/components/DirectorBlock/hooks/useDirectorBlock/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './useDirectorBlock'; |
File renamed without changes.
Oops, something went wrong.