2025-05-16 12:55:50 +03:00

25 lines
750 B
TypeScript

'use client';
import { getCustomer, updateCustomer } from '@/actions/api/customers';
import { useMutation, useQuery } from '@tanstack/react-query';
import { useSession } from 'next-auth/react';
export const useCustomerQuery = (props?: Parameters<typeof getCustomer>[0]) => {
const { data: session } = useSession();
const telegramId = props?.telegramId || session?.user?.telegramId;
return useQuery({
queryFn: () => getCustomer({ telegramId }),
queryKey: ['customer', 'telegramId', telegramId, 'get'],
});
};
export const useCustomerMutation = () => {
const { refetch } = useCustomerQuery();
return useMutation({
mutationFn: updateCustomer,
mutationKey: ['customer', 'update'],
onSuccess: () => refetch(),
});
};