-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(backoffice-v2): moved end-user query to modules
- Loading branch information
Showing
5 changed files
with
47 additions
and
41 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
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); | ||
}; |
39 changes: 0 additions & 39 deletions
39
apps/backoffice-v2/src/domains/individuals/queries/useEndUserById/useEndUserById.tsx
This file was deleted.
Oops, something went wrong.
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