hooks/customers: use invalidateQueries
This commit is contained in:
parent
b09283c33d
commit
7d368d9ef0
@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
import { getCustomer, updateCustomer } from '@/actions/api/customers';
|
||||
import { useMutation, useQuery } from '@tanstack/react-query';
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import { useSession } from 'next-auth/react';
|
||||
|
||||
export const useCustomerQuery = (props?: Parameters<typeof getCustomer>[0]) => {
|
||||
@ -14,11 +14,20 @@ export const useCustomerQuery = (props?: Parameters<typeof getCustomer>[0]) => {
|
||||
};
|
||||
|
||||
export const useCustomerMutation = () => {
|
||||
const { refetch } = useCustomerQuery();
|
||||
const { data: session } = useSession();
|
||||
const telegramId = session?.user?.telegramId;
|
||||
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
function handleOnSuccess() {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ['customer', 'telegramId', telegramId, 'get'],
|
||||
});
|
||||
}
|
||||
|
||||
return useMutation({
|
||||
mutationFn: updateCustomer,
|
||||
mutationKey: ['customer', 'update'],
|
||||
onSuccess: () => refetch(),
|
||||
onSuccess: handleOnSuccess,
|
||||
});
|
||||
};
|
||||
|
||||
@ -28,6 +28,7 @@ export const useSlotMutation = ({
|
||||
documentId,
|
||||
}: Pick<Parameters<typeof updateSlot>[0], 'documentId'>) => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
function handleOnSuccess() {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ['slots', 'get', documentId],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user