diff --git a/apps/web/components/auth/update-profile.tsx b/apps/web/components/auth/update-profile.tsx index 480c66c..fae567e 100644 --- a/apps/web/components/auth/update-profile.tsx +++ b/apps/web/components/auth/update-profile.tsx @@ -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(() => { diff --git a/apps/web/components/profile/data-card.tsx b/apps/web/components/profile/data-card.tsx index fff5bac..739f36d 100644 --- a/apps/web/components/profile/data-card.tsx +++ b/apps/web/components/profile/data-card.tsx @@ -30,8 +30,8 @@ export function ContactDataCard({ telegramId }: Readonly) { } export function ProfileDataCard() { - const { data: customer } = useProfileQuery({}); - const { mutate: updateProfile } = useProfileMutation({}); + const { data: customer } = useProfileQuery(); + const { mutate: updateProfile } = useProfileMutation(); if (!customer) return null; diff --git a/apps/web/hooks/contacts/use-customer-contacts.ts b/apps/web/hooks/contacts/use-customer-contacts.ts index ada7839..92b300d 100644 --- a/apps/web/hooks/contacts/use-customer-contacts.ts +++ b/apps/web/hooks/contacts/use-customer-contacts.ts @@ -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, diff --git a/apps/web/hooks/profile/index.ts b/apps/web/hooks/profile/index.ts index 5192f9f..45bc79b 100644 --- a/apps/web/hooks/profile/index.ts +++ b/apps/web/hooks/profile/index.ts @@ -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(), }); };