Skip to content

Commit

Permalink
refactor(backoffice-v2): moved end-user query to modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Omri-Levy committed Jan 22, 2025
1 parent 497154b commit 7088d4f
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 41 deletions.
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);
};

This file was deleted.

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 }),
}),
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BlocksComponent } from '@ballerine/blocks';
import { cells } from '../../create-blocks-typed/create-blocks-typed';
import { useEndUserById } from '@/domains/individuals/queries/useEndUserById/useEndUserById';
import { useEndUserByIdQuery } from '@/domains/individuals/queries/useEndUserByIdQuery/useEndUserByIdQuery';
import { useDirectorBlock } from './hooks/useDirectorBlock/useDirectorBlock';

export const DirectorBlock = ({
Expand All @@ -19,7 +19,7 @@ export const DirectorBlock = ({
}: Omit<Parameters<typeof useDirectorBlock>[0], 'director'> & {
director: Omit<Parameters<typeof useDirectorBlock>[0]['director'], 'aml'>;
}) => {
const { data: endUser } = useEndUserById({ id: director.id });
const { data: endUser } = useEndUserByIdQuery({ id: director.id });
const directorWithAml = {
...director,
aml: {
Expand Down

0 comments on commit 7088d4f

Please sign in to comment.