24 lines
695 B
TypeScript
24 lines
695 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 = (props?: ProfileProps) => {
|
|
const telegramId = props?.telegramId;
|
|
|
|
return useQuery({
|
|
queryFn: () => getProfile({ telegramId }),
|
|
queryKey: telegramId ? ['profile', 'telegramId', telegramId, 'get'] : ['profile', 'get'],
|
|
});
|
|
};
|
|
|
|
export const useProfileMutation = () => {
|
|
const { refetch } = useProfileQuery();
|
|
|
|
return useMutation({
|
|
mutationFn: updateProfile,
|
|
mutationKey: ['profile', 'update'],
|
|
onSuccess: () => refetch(),
|
|
});
|
|
};
|