-
Notifications
You must be signed in to change notification settings - Fork 8
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
7 changed files
with
190 additions
and
0 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,42 @@ | ||
import { QueryKey, useQuery } from '@tanstack/react-query'; | ||
|
||
import getFullClient, { Params } from '@/services/api/client/getFullClient'; | ||
import getQueryClient from '@/utils/get-query-client'; | ||
|
||
export const paramsBuilder = (props: Params): Params => ({ | ||
client_reference: props.client_reference, | ||
}); | ||
|
||
export const key = (params: Params): QueryKey => [ | ||
'full-client', | ||
params.client_reference, | ||
]; | ||
|
||
const useClientInfo = (props: Params, options?: Hikka.QueryOptions) => { | ||
const params = paramsBuilder(props); | ||
|
||
return useQuery({ | ||
queryKey: key(params), | ||
queryFn: () => | ||
getFullClient({ | ||
params, | ||
}), | ||
...options, | ||
refetchOnWindowFocus: false, | ||
}); | ||
}; | ||
|
||
export const prefetchClientInfo = (props: Params) => { | ||
const queryClient = getQueryClient(); | ||
const params = paramsBuilder(props); | ||
|
||
return queryClient.prefetchQuery({ | ||
queryKey: key(params), | ||
queryFn: () => | ||
getFullClient({ | ||
params, | ||
}), | ||
}); | ||
}; | ||
|
||
export default useClientInfo; |
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,42 @@ | ||
import { QueryKey, useQuery } from '@tanstack/react-query'; | ||
|
||
import getClient, { Params } from '@/services/api/client/getClient'; | ||
import getQueryClient from '@/utils/get-query-client'; | ||
|
||
export const paramsBuilder = (props: Params): Params => ({ | ||
client_reference: props.client_reference, | ||
}); | ||
|
||
export const key = (params: Params): QueryKey => [ | ||
'client', | ||
params.client_reference, | ||
]; | ||
|
||
const useClient = (props: Params, options?: Hikka.QueryOptions) => { | ||
const params = paramsBuilder(props); | ||
|
||
return useQuery({ | ||
queryKey: key(params), | ||
queryFn: () => | ||
getClient({ | ||
params, | ||
}), | ||
...options, | ||
refetchOnWindowFocus: false, | ||
}); | ||
}; | ||
|
||
export const prefetchClient = (props: Params) => { | ||
const queryClient = getQueryClient(); | ||
const params = paramsBuilder(props); | ||
|
||
return queryClient.prefetchQuery({ | ||
queryKey: key(params), | ||
queryFn: () => | ||
getClient({ | ||
params, | ||
}), | ||
}); | ||
}; | ||
|
||
export default useClient; |
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,26 @@ | ||
import { QueryKey, useQuery } from '@tanstack/react-query'; | ||
|
||
import getClients from '@/services/api/client/getClients'; | ||
import getQueryClient from '@/utils/get-query-client'; | ||
|
||
export const key = (): QueryKey => ['clients']; | ||
|
||
const useClients = (options?: Hikka.QueryOptions) => { | ||
return useQuery({ | ||
queryKey: key(), | ||
queryFn: () => getClients(), | ||
...options, | ||
refetchOnWindowFocus: false, | ||
}); | ||
}; | ||
|
||
export const prefetchClientInfo = () => { | ||
const queryClient = getQueryClient(); | ||
|
||
return queryClient.prefetchQuery({ | ||
queryKey: key(), | ||
queryFn: () => getClients(), | ||
}); | ||
}; | ||
|
||
export default useClients; |
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,20 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
|
||
import createClient from '@/services/api/client/createClient'; | ||
import { useModalContext } from '@/services/providers/modal-provider'; | ||
|
||
const useCreateClient = () => { | ||
const { closeModal } = useModalContext(); | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationKey: ['create-client'], | ||
mutationFn: createClient, | ||
onSettled: async () => { | ||
await queryClient.invalidateQueries({ queryKey: ['clients'] }); | ||
closeModal(); | ||
}, | ||
}); | ||
}; | ||
|
||
export default useCreateClient; |
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,20 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
|
||
import deleteClient from '@/services/api/client/deleteClient'; | ||
import { useModalContext } from '@/services/providers/modal-provider'; | ||
|
||
const useDeleteClient = () => { | ||
const { closeModal } = useModalContext(); | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationKey: ['delete-client'], | ||
mutationFn: deleteClient, | ||
onSettled: async () => { | ||
await queryClient.invalidateQueries({ queryKey: ['clients'] }); | ||
closeModal(); | ||
}, | ||
}); | ||
}; | ||
|
||
export default useDeleteClient; |
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,20 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
|
||
import updateClient from '@/services/api/client/updateClient'; | ||
import { useModalContext } from '@/services/providers/modal-provider'; | ||
|
||
const useUpdateClient = () => { | ||
const { closeModal } = useModalContext(); | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationKey: ['update-client'], | ||
mutationFn: updateClient, | ||
onSettled: async () => { | ||
await queryClient.invalidateQueries({ queryKey: ['clients'] }); | ||
closeModal(); | ||
}, | ||
}); | ||
}; | ||
|
||
export default useUpdateClient; |
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,20 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
|
||
import verifyClient from '@/services/api/client/verifyClient'; | ||
import { useModalContext } from '@/services/providers/modal-provider'; | ||
|
||
const useVerifyClient = () => { | ||
const { closeModal } = useModalContext(); | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationKey: ['verify-client'], | ||
mutationFn: verifyClient, | ||
onSettled: async () => { | ||
await queryClient.invalidateQueries({ queryKey: ['clients'] }); | ||
closeModal(); | ||
}, | ||
}); | ||
}; | ||
|
||
export default useVerifyClient; |