2025-02-08 21:52:48 +03:00

22 lines
730 B
TypeScript

'use client';
import { getProfile, updateProfile } from '@/actions/profile';
import { type ProfileProps } from '@/components/profile/types';
import { useMutation, useQuery } from '@tanstack/react-query';
export const useProfileQuery = ({ telegramId }: ProfileProps) => {
return useQuery({
queryFn: () => getProfile({ telegramId }),
queryKey: telegramId ? ['profile', 'telegramId', telegramId, 'get'] : ['profile', 'get'],
});
};
export const useProfileMutation = ({ telegramId }: ProfileProps) => {
const { refetch } = useProfileQuery({ telegramId });
return useMutation({
mutationFn: updateProfile,
mutationKey: ['profile', 'telegramId', telegramId, 'update'],
onSuccess: () => refetch(),
});
};