hooks/profile: allow pass empty args to useProfileQuery/useProfileMutation

This commit is contained in:
vchikalkin 2025-04-10 11:52:34 +03:00
parent 8c8a588dfc
commit ec32f56f8b
4 changed files with 10 additions and 8 deletions

View File

@ -5,7 +5,7 @@ import { useEffect, useState } from 'react';
export function UpdateProfile() {
const initDataUser = useSignal(initData.user);
const { mutate: updateProfile } = useProfileMutation({});
const { mutate: updateProfile } = useProfileMutation();
const [hasUpdated, setHasUpdated] = useState(false);
useEffect(() => {

View File

@ -30,8 +30,8 @@ export function ContactDataCard({ telegramId }: Readonly<ProfileProps>) {
}
export function ProfileDataCard() {
const { data: customer } = useProfileQuery({});
const { mutate: updateProfile } = useProfileMutation({});
const { data: customer } = useProfileQuery();
const { mutate: updateProfile } = useProfileMutation();
if (!customer) return null;

View File

@ -13,7 +13,7 @@ type Parameters_ = {
export function useCustomerContacts(parameters?: Parameters_) {
const { filter, setFilter } = use(ContactsFilterContext);
const { data: customer, isLoading: isLoadingProfile } = useProfileQuery({});
const { data: customer, isLoading: isLoadingProfile } = useProfileQuery();
const {
data: clientsData,

View File

@ -3,19 +3,21 @@ 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) => {
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 = ({ telegramId }: ProfileProps) => {
const { refetch } = useProfileQuery({ telegramId });
export const useProfileMutation = () => {
const { refetch } = useProfileQuery();
return useMutation({
mutationFn: updateProfile,
mutationKey: ['profile', 'telegramId', telegramId, 'update'],
mutationKey: ['profile', 'update'],
onSuccess: () => refetch(),
});
};