hooks/customers: use invalidateQueries

This commit is contained in:
vchikalkin 2025-05-16 16:05:09 +03:00
parent b09283c33d
commit 7d368d9ef0
2 changed files with 13 additions and 3 deletions

View File

@ -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,
});
};

View File

@ -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],