diff --git a/apps/web/components/profile/cards/data-card.tsx b/apps/web/components/profile/cards/data-card.tsx index 2387ea2..25aef48 100644 --- a/apps/web/components/profile/cards/data-card.tsx +++ b/apps/web/components/profile/cards/data-card.tsx @@ -2,17 +2,14 @@ import { type ProfileProps } from '../types'; import { CheckboxWithText, DataField, ProfileCardHeader } from './components'; import { updateRole } from './lib/actions'; -import { getProfile, updateProfile } from '@/actions/profile'; +import { updateProfile } from '@/actions/profile'; +import { useProfile } from '@/hooks/profile'; import { Button } from '@repo/ui/components/ui/button'; import { Card } from '@repo/ui/components/ui/card'; -import { useQuery } from '@tanstack/react-query'; import Link from 'next/link'; export function ContactDataCard({ telegramId }: Readonly) { - const { data: customer } = useQuery({ - queryFn: () => getProfile({ telegramId }), - queryKey: ['profile', 'telegramId', telegramId], - }); + const { data: customer } = useProfile({ telegramId }); if (!customer) return null; @@ -33,10 +30,7 @@ export function ContactDataCard({ telegramId }: Readonly) { } export function ProfileDataCard() { - const { data: customer } = useQuery({ - queryFn: () => getProfile(), - queryKey: ['profile'], - }); + const { data: customer } = useProfile({}); if (!customer) return null; diff --git a/apps/web/components/profile/cards/links-card.tsx b/apps/web/components/profile/cards/links-card.tsx index ddb4303..9d25cb3 100644 --- a/apps/web/components/profile/cards/links-card.tsx +++ b/apps/web/components/profile/cards/links-card.tsx @@ -2,15 +2,11 @@ 'use client'; import { type ProfileProps } from '../types'; import { LinkButton } from './components'; -import { getProfile } from '@/actions/profile'; +import { useProfile } from '@/hooks/profile'; import { Enum_Customer_Role } from '@repo/graphql/types'; -import { useQuery } from '@tanstack/react-query'; export function LinksCard({ telegramId }: Readonly) { - const { data: customer } = useQuery({ - queryFn: () => getProfile({ telegramId }), - queryKey: telegramId ? ['profile', 'telegramId', telegramId] : ['profile'], - }); + const { data: customer } = useProfile({ telegramId }); const isMaster = customer?.role === Enum_Customer_Role.Master; diff --git a/apps/web/components/profile/cards/person-card.tsx b/apps/web/components/profile/cards/person-card.tsx index b1f50a9..77c9163 100644 --- a/apps/web/components/profile/cards/person-card.tsx +++ b/apps/web/components/profile/cards/person-card.tsx @@ -1,15 +1,11 @@ 'use client'; import { type ProfileProps } from '../types'; -import { getProfile } from '@/actions/profile'; +import { useProfile } from '@/hooks/profile'; import { Avatar, AvatarFallback, AvatarImage } from '@repo/ui/components/ui/avatar'; import { Card } from '@repo/ui/components/ui/card'; -import { useQuery } from '@tanstack/react-query'; export function PersonCard({ telegramId }: Readonly) { - const { data: customer } = useQuery({ - queryFn: () => getProfile({ telegramId }), - queryKey: telegramId ? ['profile', 'telegramId', telegramId] : ['profile'], - }); + const { data: customer } = useProfile({ telegramId }); if (!customer) return null; diff --git a/apps/web/hooks/profile/index.ts b/apps/web/hooks/profile/index.ts new file mode 100644 index 0000000..093632b --- /dev/null +++ b/apps/web/hooks/profile/index.ts @@ -0,0 +1,11 @@ +'use client'; +import { getProfile } from '@/actions/profile'; +import { type ProfileProps } from '@/components/profile/types'; +import { useQuery } from '@tanstack/react-query'; + +export const useProfile = ({ telegramId }: ProfileProps) => { + return useQuery({ + queryFn: () => getProfile({ telegramId }), + queryKey: telegramId ? ['profile', 'telegramId', telegramId] : ['profile'], + }); +};