From 7d368d9ef053d517caf32284fb9914c028590062 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Fri, 16 May 2025 16:05:09 +0300 Subject: [PATCH] hooks/customers: use invalidateQueries --- apps/web/hooks/api/customers.ts | 15 ++++++++++++--- apps/web/hooks/api/slots.ts | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/apps/web/hooks/api/customers.ts b/apps/web/hooks/api/customers.ts index eac4886..527d598 100644 --- a/apps/web/hooks/api/customers.ts +++ b/apps/web/hooks/api/customers.ts @@ -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[0]) => { @@ -14,11 +14,20 @@ export const useCustomerQuery = (props?: Parameters[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, }); }; diff --git a/apps/web/hooks/api/slots.ts b/apps/web/hooks/api/slots.ts index 78db87f..67066a3 100644 --- a/apps/web/hooks/api/slots.ts +++ b/apps/web/hooks/api/slots.ts @@ -28,6 +28,7 @@ export const useSlotMutation = ({ documentId, }: Pick[0], 'documentId'>) => { const queryClient = useQueryClient(); + function handleOnSuccess() { queryClient.invalidateQueries({ queryKey: ['slots', 'get', documentId],